shader: lower compute s_add_i32, s_sub_i32 and s_abs_i32 #1949
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1956"
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 henriazz10 on 2026-11-24T22:07:09Z.
Change
Refs #721. This is item 2 (
s_add_i32/s_sub_i32/s_abs_i32) of the five ALU slices claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches onlytools/compute_store_aot.py,tests/compute_store_check.py,CMakeLists.txt, anddocs/experiments.md.alu_word,hlsl_word,ALU_EXPRESSION_LIMIT), outside or inside expressions:s_add_i32 sD, a, b(SOP2) lowers to({0} + {1})(32-bit wrap-around of(int64)S0.i32 + (int64)S1.i32).s_sub_i32 sD, a, b(SOP2) lowers to({0} - {1})(32-bit wrap-around of(int64)S0.i32 - (int64)S1.i32).s_abs_i32 sD, a(SOP1) lowers toasuint(abs(asint({0})))((S0.i32 < 0) ? -S0.i32 : S0.i32, wrapping0x80000000(INT_MIN) to0x80000000).SCC(signed overflow for add/sub, nonzero result for abs) stays unread.s30,s12, or ans_buffer_load_dwordresult befores_waitcnt lgkmcnt(0));s106, or a pendings_buffer_load_dworddestination);0x1ffffffff) or vector source (v0);clamp,mul:2,|s16|,-s16), other spellings (s_add_i32_e64,s_abs_u32), and SCC consumers (s_cselect_b32).Verification
Commit
68d04fd5, rebased onto489d5797. The draws,controls()and the LLVM 15 round trip were re-run on68d04fd5. Windows 11, DXC 10.0.26100.0, Python 3.12 (pe-env), debug layer enabled.salu_i32_controls()controls_ok)groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0binary(Docker)x2w-llvm15binary_exit=0docs_links_check.pybidi_controls_check.pygit diff --check HEAD~1salu_i32_binary()decodes the assembled fixture back to the sames_add_i32,s_sub_i32, ands_abs_i32lines and requires the same translation.Negative control. With
tools/compute_store_aot.pychecked out fromorigin/main(4ab5e018),salu_i32_controls()fails withValueError: Unsupported compute instruction: s_add_i32 s16, 0x7fffffff, 1(exit 1).Evidence
The fixture (
SALU_I32) is source-built in LLVM 15 spelling and runs one group of 64 threads withbuffer_store_dwordx4(stride 16), combiningtid.xwiths_add_i32(0x7fffffff + 1,+ 0x80000000,+ -15),s_sub_i32(0x80000000 - 1,5 - s18,- -10), ands_abs_i32(0x80000000,-15,17,0). All 320 words (256 output words plus 64 trailingSENTINELwords) are compared against an independent Python model of the RDNA2 ISA pseudocode.clamp/mul:2/|...|/-s...modifiers,s_add_i32_e64/s_abs_u32spellings, ands_cselect_b32SCC consumer.INT_MIN abs saturated to INT_MAX: word 2;s_sub_i32 sources swapped: word 1;s_add_i32 saturated instead of wrapped: word 0;sentinel past group: word 256.Compute readback differs):abs dropped on INT_MIN;sub turned into add;add turned into sub.Checklist
docs/experiments.md).AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:30:29Z.
Review: COMMENTED
Review of head
ee512b7bb8Semantics: s_add_i32 and s_sub_i32 lower to wrap-around uint add/sub, which matches the RDNA2 low-32-bit result. s_abs_i32 lowers to asuint(abs(asint(x))), and INT_MIN stays 0x80000000. SCC stays unread, and the docs say so. The new regex only adds the three opcodes. Vector sources, modifiers, other spellings and SCC consumers are still refused, and the controls cover each refusal. CMakeLists.txt only registers
compute_store_aot_salu_i32_<adapter>. The code is original and written from the ISA description. P1: 0. P2: 0.Commands executed locally:
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflictspython3 tests/docs_links_check.py: PASS (18 files, 386 links)python3 tests/bidi_controls_check.py: PASSgit diff --check origin/main...HEAD: PASSpython3 -B tests/compute_store_check.py(controls, run at startup): PASSctest --preset dev, 69 tests includingcompute_store_aot_salu_i32_warp): 69/69 passedctest --preset release, same 69 tests): 69/69 passedMutations in tools/compute_store_aot.py, all killed by the controls (each reverted with
git checkout -- .):s_sub_i32lowered with+instead of-: expected-HLSL assertion failss_abs_i32lowered withoutabs: expected-HLSL assertion failss_sub_i32dropped from the accepted opcode regex:Unsupported compute instructionraisedResult: comment only, no approval.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:57:38Z.
Review: COMMENTED
Review of head
68d04fd5e6Result: 0 P1, 0 P2. Semantics match the RDNA2 ISA: wrap-around add/sub, abs wraps INT_MIN to INT_MIN, SCC unread. CMakeLists.txt only registers the new
compute_store_aot_salu_i32_*tests. Clean-room: the change uses only public ISA semantics and independent code.Commands executed locally:
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.python3 -B tests/compute_store_check.py(controls run at import, including the newsalu_i32_controls): PASS.python3 tests/docs_links_check.py: PASS.python3 tests/bidi_controls_check.py: PASS.git diff --check origin/main...HEAD: PASS.python3 x2w_pipe.py win2025 1956 --wait 900: Debug (--preset dev) and Release/O2(--preset release) PASS, includingcompute_store_aot_salu_i32_warp.Mutations in
tools/compute_store_aot.py, each killed by the test controls (then reverted):s_sub_i32operands swapped: killed.s_abs_i32lowered to a plain copy: killed.s_add_i32turned into a subtract: killed.AI-assisted; commands listed were executed locally.