xshader: lower SAD forms and v_mad_i64_i32 #102
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox!102
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/102/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@JohnVonWells on GitHub · 2026-11-24 22:28 UTC · original
xshader/sad-and-mad-i64→main· +532 −9 · 6 files · 1 commits · merged 2026-11-24 22:31 UTCThird PR from the synthetic opcode sweep, after #95 and #99.
v_sad_u8v_sad_hi_u8v_sad_u16v_sad_u32v_mad_i64_i32All results wrap modulo 2^32 (SAD) or 2^64 (
mad).Semantics. LLVM's gfx1030 backend selects
v_sad_u32foradd(sub(umax(a, b), umin(a, b)), c), andv_mad_i64_i32 v[0:1], null, …forsext(a) * sext(b) + cin i64. The byte and half SADs follow the RDNA2 ISA definitions. LLVM only exposes them as intrinsics and does not fold them.Lowering
hlsl/int32.rs, with the same scope as #95: VGPR sources only, compute shaders only, and clamp, abs, neg and op_sel refused.v_mad_i64_i32shares the existingv_mad_u64_u32path and usestb_mulhi_i32for the high word. The low product word is the same for both. It accepts only thenullcarry destination, which is what LLVM emits when the carry is unused; a real carry for the signed form is not modelled.v_mad_u64_u32with thatnullcarry used to be refused (unsupported multiply-add carry destination). It is now accepted and simply drops the carry.v_msad_u8and the quad SADs stay refused.Verification
tools/check_sad_mad64_gpu.pyruns one LLVM-assembled program with all six forms:v_mad_i64_i32 v[18:19], null, v4, v5, v[18:19]andv_sad_u8 v20, v4, v5, v20.tests/test_sad_mad64_gpu.py.1002:73a5, RADV): 288 inputs, 3,168 results, 9,216 GPU words, zero mismatches. The receipt isevidence/sad-mad64-control.json.cb185e0refuses the program (--baseline).v_mad_i64_i32. All 24 dispatches then failed, only in the two signed high-word columns.Note on #101: that PR adds
flat_inputs/flat_outputstoShaderExtract, and its Rust CI currently fails on the test literal inhlsl/float64.rsthat came in with #99. To avoid adding another literal, the newint32test reuses thatfloat64test helper, so there is still only one place to update.AI-assisted.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY