shader: lower compute s_absdiff_i32 #1588
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1588
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1588/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?
@Asimmimx on GitHub · 2026-11-24 14:37 UTC · original
Asimmimx:shader/compute-absdiff→main· +233 −1 · 4 files · 1 commits · merged 2026-11-24 17:53 UTCChange
Refs #1546. This adds
s_absdiff_i32(SOP2 opcode 44) to the compute translator's scalar ALU on known words (tools/compute_store_aot.py).Semantics. The RDNA 1 (2020-09-25) and RDNA 2 (2020-11-30) ISA references both define it as
D.i = S0.i - S1.i; if (D.i < 0) D.i = -D.i; SCC = (D.i != 0). The subtraction and the negation both wrap at 32 bits:(0x80000000, 0)gives0x80000000(the reference notes "result is negative!");(0x7fffffff, 0x80000000)gives 1, not0xffffffff.Lowering.
asuint(abs(asint({0} - {1}))). It subtracts as unsigned, so no signed-overflow semantics are involved. DXC 1.8.2502 emits a plainsub i32andIMax(d, 0 - d), which keeps0x80000000.SALUentry plusabsdiff_i32appended to the SALU matcher alternation.Fixture. The fixture and controls are in a new
tests/compute_salu_absdiff_check.py. It imports the helpers oftests/compute_store_check.py, which is unchanged. Each lane below the bound stores, with onebuffer_store_dwordx4:|c1 - c2||c3 - c4||c5 - 0x80000000||-7 - r0|The constants come from the case file. The expected words were worked by hand, and a Python model of the ISA pseudocode reproduces all six ISA examples.
2, 5, 0x80000000, 0, 0x7fffffff3, 0x80000000, 1, 0xa0x12345678, 0x12345678, 0x80000000, 0xffffffff, 0x800000000, 0x7fffffff, 0, 7-10, 5, 5, -10, 00xf, 0xf, 0x80000000, 0x16Wrong references and mutations. Four wrong definitions are written as expected words, and each must fail at its first differing word:
0x7fffffff.Three mutated HLSL translations must report "Compute readback differs":
absdropped, the INT_MIN literal changed, and the inline constant changed.Translator controls. These are refused with the existing messages:
s106and pending destinations;s_absdiff_u32;s_cselect_b32ands_cbranch_scc0;The new CTest is
compute_store_aot_salu_absdiff_${adapter}, registered aftercompute_store_aot_mimg_resinfo. A "Scalar absolute difference" subsection is added todocs/experiments.md.Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledOn both backends the INT_MIN case reads
0x80000000. On the RX 6600, the saturated reference is reported asword=1 expected=7fffffff actual=80000000, so the 32-bit wrap holds on this hardware.Regression with the change:
*_controlsfunctions intests/compute_store_check.py, includingscalar_alu_controls;draw-guard-readon WARP;tests/docs_links_check.py,tests/bidi_controls_check.py,tests/form_coverage_check.pyandgit diff --check.I did not run the LLVM 15
binarymode.Checklist
AI-assisted (Claude Code).
Add s_absdiff_i32 sD, a, b (SOP2 opcode 44) to the compute store profile's scalar ALU subset on known words. The RDNA 1 and RDNA 2 ISA references define it as D.i = S0.i - S1.i; if (D.i < 0) D.i = -D.i; SCC = (D.i != 0), in 32-bit words, so (0x80000000, 0) gives 0x80000000 and (0x7fffffff, 0x80000000) gives 1. It lowers to asuint(abs(asint(a - b))) with an unsigned subtraction; DXC 1.8.2502 emits a plain sub and IMax(d, 0 - d), which keeps 0x80000000. SCC stays unmodelled, and its consumers are still refused. tests/compute_salu_absdiff_check.py adds a source-built gfx1013 fixture (LLVM 15 spelling). Each guarded lane stores four results: two register pairs, a register against the INT_MIN literal, and an inline constant against the first result. Three dispatches cover negative differences, equal operands, INT_MIN and the 32-bit wrap, against hand-worked words that a Python model of the ISA pseudocode (checked against the six ISA functional examples) also produces. Four wrong definitions and three mutated translations must fail on the device. The controls mode checks the exact HLSL and refuses unknown, pending, descriptor, exec-mask, vector, float-constant and oversized sources, bad destinations, s_absdiff_u32, SCC consumers, address and guard uses of the result, and an oversized expression. Registered as compute_store_aot_salu_absdiff_{warp,hardware}. Verified with controls and the WARP draw (Microsoft Basic Render Driver 10.0.26100.9818), plus the compute_store_check translator controls and draw-guard-read on WARP.@tedin7 on GitHub · 2026-11-24 15:46 UTC · original · reviewed
Reviewed at
3f3047c1ff85782d16397eb18afdcba3fbd32432.Summary
tools/compute_store_aot.py): Lowerss_absdiff_i32 sD, a, btoasuint(abs(asint({0} - {1})))inSALU. Unsigned{0} - {1}performs well-defined 32-bit wrapping subtraction,abs(asint(...))negates negative values in two's complement (preserving0x80000000onINT_MIN - 0), andasuint(...)returns the 32-bit word, matching the RDNA 1/2 ISA specification. SCC remains unmodelled and SCC consumers remain rejected.tests/compute_salu_absdiff_check.py): Covers the RDNA ISA reference examples, 3 dispatch constant sets (A,B,C), 4 wrong-definition negative checks, 3 HLSL mutation checks, and 16 control rejections (unwritten/pending/descriptor/saved-exec SGPRs, >32-bit literal,dst > s105, vector/float sources, 64-bit dst,s_absdiff_u32, SCC consumers, address/guard uses, expression limit).No blocking issues found.
Verification
python3 -B tests/compute_salu_absdiff_check.py controls: passedpython3 -B tests/docs_links_check.py: passed (16 Markdown files, 344 links)python3 -B tests/bidi_controls_check.py: passed (1253 files)--preset dev): 41/41 passed (compute_store_aot_salu_absdiff_warp3.64s)/O2(--preset release): 41/41 passed (compute_store_aot_salu_absdiff_warp3.55s)AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 17:39 UTC · original · reviewed
Re-verification at
head_sha:3f3047c1ff85782d16397eb18afdcba3fbd32432(same head as the earlier review).Findings
No P1/P2. No defect found.
git merge-treeof this head against currentmain(e4ac2c78) reports no conflicts.Verified
Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware
ctestfor this head.python3 -B tests/compute_salu_absdiff_check.py controls-> exit 0.python3 -B tests/docs_links_check.py-> 16 files, 344 links OK.git diff --check HEAD^ HEADclean.llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encodingassembless_absdiff_i32 s1, s2, s3(0x96010302) ands_absdiff_i32 s1, s2, 4(0x96018402).asuint(abs(asint({1} - {0})));controlsfails with anAssertionError.abs(asuint(asint({0} - {1})));controlsfails with anAssertionError.git checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.