shader: lower compute s_absdiff_i32 #1581
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1588"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T14:37:26Z.
Change
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).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:46:49Z.
Review: COMMENTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:39:53Z.
Review: COMMENTED
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.