shader: lower compute s_add_i32, s_sub_i32 and s_abs_i32 #1949

Merged
henriazz10 merged 1 commit from upstream-pr/1956 into main 2026-11-24 23:58:24 +00:00
henriazz10 commented 2026-11-24 22:07:09 +00:00 (Migrated from github.com)

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 only tools/compute_store_aot.py, tests/compute_store_check.py, CMakeLists.txt, and docs/experiments.md.

  • On known 32-bit scalar words (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 to asuint(abs(asint({0}))) ((S0.i32 < 0) ? -S0.i32 : S0.i32, wrapping 0x80000000 (INT_MIN) to 0x80000000).
    • SCC (signed overflow for add/sub, nonzero result for abs) stays unread.
  • Refused, each with its own control:
    • unknown or pending scalar source (s30, s12, or an s_buffer_load_dword result before s_waitcnt lgkmcnt(0));
    • invalid or pending scalar destination (s106, or a pending s_buffer_load_dword destination);
    • literal wider than 32 bits (0x1ffffffff) or vector source (v0);
    • modifiers (clamp, mul:2, |s16|, -s16), other spellings (s_add_i32_e64, s_abs_u32), and SCC consumers (s_cselect_b32).

Verification

Commit 68d04fd5, rebased onto 489d5797. The draws, controls() and the LLVM 15 round trip were re-run on 68d04fd5. Windows 11, DXC 10.0.26100.0, Python 3.12 (pe-env), debug layer enabled.

python -B -c "import sys; sys.path.insert(0, 'tests'); import compute_store_check as c; c.salu_i32_controls(); print('controls_ok')"
python -B tests/compute_store_check.py draw-salu_i32 <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-salu_i32 <dxc> <offscreen_check> hardware
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check HEAD~1
docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-salu-i32:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?'
Check / Backend Adapter / driver Result
salu_i32_controls() — exit 0 (controls_ok)
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
LLVM 15 binary (Docker) x2w-llvm15 binary_exit=0
docs_links_check.py — exit 0 (18 Markdown files, 376 links)
bidi_controls_check.py — exit 0 (1330 tracked files)
git diff --check HEAD~1 — exit 0

salu_i32_binary() decodes the assembled fixture back to the same s_add_i32, s_sub_i32, and s_abs_i32 lines and requires the same translation.

Negative control. With tools/compute_store_aot.py checked out from origin/main (4ab5e018), salu_i32_controls() fails with ValueError: 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 with buffer_store_dwordx4 (stride 16), combining tid.x with s_add_i32 (0x7fffffff + 1, + 0x80000000, + -15), s_sub_i32 (0x80000000 - 1, 5 - s18, - -10), and s_abs_i32 (0x80000000, -15, 17, 0). All 320 words (256 output words plus 64 trailing SENTINEL words) are compared against an independent Python model of the RDNA2 ISA pseudocode.

  • Translation controls. Verify the exact HLSL line and 18 rejection cases covering unknown/pending sources, invalid/pending destinations, >32-bit literal, vector source, clamp/mul:2/|...|/-s... modifiers, s_add_i32_e64/s_abs_u32 spellings, and s_cselect_b32 SCC consumer.
  • Reference controls. Each fails at its stated first differing word:
    • 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.
  • Recompiled-HLSL controls. Each fails on the device (Compute readback differs):
    • abs dropped on INT_MIN;
    • sub turned into add;
    • add turned into sub.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592364050 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1956). Originally posted by [henriazz10](https://github.com/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 only `tools/compute_store_aot.py`, `tests/compute_store_check.py`, `CMakeLists.txt`, and `docs/experiments.md`. - On known 32-bit scalar words (`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 to `asuint(abs(asint({0})))` (`(S0.i32 < 0) ? -S0.i32 : S0.i32`, wrapping `0x80000000` (`INT_MIN`) to `0x80000000`). - `SCC` (signed overflow for add/sub, nonzero result for abs) stays unread. - Refused, each with its own control: - unknown or pending scalar source (`s30`, `s12`, or an `s_buffer_load_dword` result before `s_waitcnt lgkmcnt(0)`); - invalid or pending scalar destination (`s106`, or a pending `s_buffer_load_dword` destination); - literal wider than 32 bits (`0x1ffffffff`) or vector source (`v0`); - modifiers (`clamp`, `mul:2`, `|s16|`, `-s16`), other spellings (`s_add_i32_e64`, `s_abs_u32`), and SCC consumers (`s_cselect_b32`). ## Verification Commit `68d04fd5`, rebased onto `489d5797`. The draws, `controls()` and the LLVM 15 round trip were re-run on `68d04fd5`. Windows 11, DXC 10.0.26100.0, Python 3.12 (`pe-env`), debug layer enabled. ```powershell python -B -c "import sys; sys.path.insert(0, 'tests'); import compute_store_check as c; c.salu_i32_controls(); print('controls_ok')" python -B tests/compute_store_check.py draw-salu_i32 <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-salu_i32 <dxc> <offscreen_check> hardware python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check HEAD~1 ``` ```sh docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-salu-i32:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?' ``` | Check / Backend | Adapter / driver | Result | |---|---|---| | `salu_i32_controls()` | — | exit 0 (`controls_ok`) | | WARP | Microsoft Basic Render Driver 10.0.26100.9818 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | | LLVM 15 `binary` (Docker) | `x2w-llvm15` | `binary_exit=0` | | `docs_links_check.py` | — | exit 0 (18 Markdown files, 376 links) | | `bidi_controls_check.py` | — | exit 0 (1330 tracked files) | | `git diff --check HEAD~1` | — | exit 0 | `salu_i32_binary()` decodes the assembled fixture back to the same `s_add_i32`, `s_sub_i32`, and `s_abs_i32` lines and requires the same translation. **Negative control.** With `tools/compute_store_aot.py` checked out from `origin/main` (`4ab5e018`), `salu_i32_controls()` fails with `ValueError: 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 with `buffer_store_dwordx4` (stride 16), combining `tid.x` with `s_add_i32` (`0x7fffffff + 1`, `+ 0x80000000`, `+ -15`), `s_sub_i32` (`0x80000000 - 1`, `5 - s18`, `- -10`), and `s_abs_i32` (`0x80000000`, `-15`, `17`, `0`). All 320 words (256 output words plus 64 trailing `SENTINEL` words) are compared against an independent Python model of the RDNA2 ISA pseudocode. - **Translation controls.** Verify the exact HLSL line and 18 rejection cases covering unknown/pending sources, invalid/pending destinations, >32-bit literal, vector source, `clamp`/`mul:2`/`|...|`/`-s...` modifiers, `s_add_i32_e64`/`s_abs_u32` spellings, and `s_cselect_b32` SCC consumer. - **Reference controls.** Each fails at its stated first differing word: - `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. - **Recompiled-HLSL controls.** Each fails on the device (`Compute readback differs`): - `abs dropped on INT_MIN`; - `sub turned into add`; - `add turned into sub`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-24 23:03:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:30:29Z.

Review: COMMENTED


Review of head ee512b7bb8

Semantics: 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 conflicts
  • python3 tests/docs_links_check.py: PASS (18 files, 386 links)
  • python3 tests/bidi_controls_check.py: PASS
  • git diff --check origin/main...HEAD: PASS
  • python3 -B tests/compute_store_check.py (controls, run at startup): PASS
  • Win2025 Debug (ctest --preset dev, 69 tests including compute_store_aot_salu_i32_warp): 69/69 passed
  • Win2025 Release (ctest --preset release, same 69 tests): 69/69 passed
  • CI: Linux checks, fixture assembly and Windows build all pass

Mutations in tools/compute_store_aot.py, all killed by the controls (each reverted with git checkout -- .):

  • s_sub_i32 lowered with + instead of -: expected-HLSL assertion fails
  • s_abs_i32 lowered without abs: expected-HLSL assertion fails
  • s_sub_i32 dropped from the accepted opcode regex: Unsupported compute instruction raised

Result: comment only, no approval.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048425262 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1956#pullrequestreview-6048425262). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:30:29Z. **Review:** COMMENTED --- Review of head ee512b7bb82c10ccc8c3c95873e91dd0a5f45c0b Semantics: 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 conflicts - `python3 tests/docs_links_check.py`: PASS (18 files, 386 links) - `python3 tests/bidi_controls_check.py`: PASS - `git diff --check origin/main...HEAD`: PASS - `python3 -B tests/compute_store_check.py` (controls, run at startup): PASS - Win2025 Debug (`ctest --preset dev`, 69 tests including `compute_store_aot_salu_i32_warp`): 69/69 passed - Win2025 Release (`ctest --preset release`, same 69 tests): 69/69 passed - CI: Linux checks, fixture assembly and Windows build all pass Mutations in tools/compute_store_aot.py, all killed by the controls (each reverted with `git checkout -- .`): - `s_sub_i32` lowered with `+` instead of `-`: expected-HLSL assertion fails - `s_abs_i32` lowered without `abs`: expected-HLSL assertion fails - `s_sub_i32` dropped from the accepted opcode regex: `Unsupported compute instruction` raised Result: comment only, no approval. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 00:04:44 +00:00
tedin7 commented 2026-11-25 00:04:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:57:38Z.

Review: COMMENTED


Review of head 68d04fd5e6

Result: 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 new salu_i32_controls): PASS.
  • python3 tests/docs_links_check.py: PASS.
  • python3 tests/bidi_controls_check.py: PASS.
  • git diff --check origin/main...HEAD: PASS.
  • Win2025 python3 x2w_pipe.py win2025 1956 --wait 900: Debug (--preset dev) and Release /O2 (--preset release) PASS, including compute_store_aot_salu_i32_warp.

Mutations in tools/compute_store_aot.py, each killed by the test controls (then reverted):

  • s_sub_i32 operands swapped: killed.
  • s_abs_i32 lowered to a plain copy: killed.
  • s_add_i32 turned into a subtract: killed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049391613 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1956#pullrequestreview-6049391613). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:57:38Z. **Review:** COMMENTED --- Review of head 68d04fd5e64e808080aaf014e3d565b2f021b31e Result: 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 new `salu_i32_controls`): PASS. - `python3 tests/docs_links_check.py`: PASS. - `python3 tests/bidi_controls_check.py`: PASS. - `git diff --check origin/main...HEAD`: PASS. - Win2025 `python3 x2w_pipe.py win2025 1956 --wait 900`: Debug (`--preset dev`) and Release `/O2` (`--preset release`) PASS, including `compute_store_aot_salu_i32_warp`. Mutations in `tools/compute_store_aot.py`, each killed by the test controls (then reverted): - `s_sub_i32` operands swapped: killed. - `s_abs_i32` lowered to a plain copy: killed. - `s_add_i32` turned into a subtract: killed. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1949
No description provided.