Repository navigation
feat(shader): implement clamp on v_mad_u64_u32 and v_mad_i64_i32 - #563
Conversation
|
Thanks. llvm-mc for gfx1013 accepts I went through the saturation on the halves: for the unsigned form the existing carry is exactly the 64-bit overflow, since the product is at most (2^32 - 1)^2. For the signed form,
One note: #264 edits the same condition in This only adds an encoding that main refused, so it's ready to merge from my side. |
a6a168f to
5ce854d
Compare
|
Rebased on current main: |
|
Thanks, keeping #264's |
Co-Authored-By: Claude <noreply@anthropic.com>
|
Rebased on current main after #474: the clamp exception now sits on the same line as main's |
5ce854d to
a15a21c
Compare
|
Thanks. The range-diff against the previous head shows only the PPSA21564 never uses clamp on these two opcodes, so this doesn't need my PPSA21564 check. Ready to merge from my side. |
What
clampon the VOP3bv_mad_u64_u32andv_mad_i64_i32. llvm-mc (-mcpu=gfx1013) accepts it (word0 bit 15), and the decoder threw "VOP3 source modifiers are not implemented". Found by the modifier sweep of the shader recompiler.negandomodstill throw.Behaviour measured on HW (RDNA2 gfx1035, raw kernels, 2176 rows: every pair of 12 edge values × 8 addends, plus 1024 random rows; 2176/2176 match the model):
v_mad_u64_u32 clamp: the 64-bit result saturates to0xffffffffffffffffwhen the exacta*b + coverflows.v_mad_i64_i32 clamp: the 64-bit result saturates toINT64_MAX/INT64_MIN.The signed case overflows only when the product and the addend have the same sign and the wrapped sum has the other sign. The saturated value then takes the sign of the addend. Everything is computed in 32-bit halves, like the existing path.
Tested
Linux, no title. New execution test
agc_driver_vop3_mad_clamp_tests(Vop3MadClamp.cpp): 32 lanes, expected values from the HW. Rows include exactUINT64_MAX,INT64_MAXandINT64_MINresults (not saturated) and the values just past each one, plus every sign combination. It passes on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8, 0 s cold). Full ctest Release: 183/184 pass; the failing one,agc_driver_pixel_helper_lanes, also fails onmainwith local RADV.The test fails without the fix: the decoder throws. It also fails under each of these mutations: decoder dropping the clamp bit, no signed saturation, no unsigned saturation, saturated sign taken from the result, overflow tested on the addend alone.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)