shader: lower compute s_absdiff_i32 #1588

Manually merged
github merged 1 commit from gh-pr/1588/head into gh-pr/1588/base 2026-11-26 23:18:56 +00:00
Owner

@⁠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 UTC

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) gives 0x80000000 (the reference notes "result is negative!");
  • (0x7fffffff, 0x80000000) gives 1, not 0xffffffff.

Lowering.

  • The template is asuint(abs(asint({0} - {1}))). It subtracts as unsigned, so no signed-overflow semantics are involved. DXC 1.8.2502 emits a plain sub i32 and IMax(d, 0 - d), which keeps 0x80000000.
  • The change is one SALU entry plus absdiff_i32 appended to the SALU matcher alternation.
  • SCC is still not modelled, and its consumers are still refused.

Fixture. The fixture and controls are in a new tests/compute_salu_absdiff_check.py. It imports the helpers of tests/compute_store_check.py, which is unchanged. Each lane below the bound stores, with one buffer_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.

Run (groups, bound) c1..c5 Expected words
(1, 17) 2, 5, 0x80000000, 0, 0x7fffffff 3, 0x80000000, 1, 0xa
(2, 50) 0x12345678, 0x12345678, 0x80000000, 0xffffffff, 0x80000000 0, 0x7fffffff, 0, 7
(3, 80) -10, 5, 5, -10, 0 0xf, 0xf, 0x80000000, 0x16

Wrong references and mutations. Four wrong definitions are written as expected words, and each must fail at its first differing word:

  • no abs;
  • unsigned comparison;
  • difference not wrapped to 32 bits;
  • INT_MIN saturated to 0x7fffffff.

Three mutated HLSL translations must report "Compute readback differs": abs dropped, the INT_MIN literal changed, and the inline constant changed.

Translator controls. These are refused with the existing messages:

  • unknown, descriptor, saved-exec and pending sources, and a 33-bit literal;
  • s106 and pending destinations;
  • a vector source, a float inline constant and a 64-bit destination;
  • s_absdiff_u32;
  • the SCC consumers s_cselect_b32 and s_cbranch_scc0;
  • the result used as a store address or as a guard operand;
  • a chain that is too long.

The new CTest is compute_store_aot_salu_absdiff_${adapter}, registered after compute_store_aot_mimg_resinfo. A "Scalar absolute difference" subsection is added to docs/experiments.md.

Verification

Commit 6c0e5380 (main) plus this change, dev preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.

python -B tests/compute_salu_absdiff_check.py controls                                  # pass
python -B tests/compute_salu_absdiff_check.py draw <dxc> <offscreen_check.exe> warp     # pass
python -B tests/compute_salu_absdiff_check.py draw <dxc> <offscreen_check.exe> hardware # pass
ctest --preset dev --no-tests=error -R '^compute_store_aot_salu_absdiff_(warp|hardware)$' -V
Backend Result
WARP 10.0.26100.9818, debug layer enabled 3 runs, 320 words each, mismatches 0, debug errors 0
AMD Radeon RX 6600 (RDNA 2, 1002:73ff), driver 32.0.21045.29003, debug layer enabled 3 runs, 320 words each, mismatches 0, debug errors 0

On both backends the INT_MIN case reads 0x80000000. On the RX 6600, the saturated reference is reported as word=1 expected=7fffffff actual=80000000, so the 32-bit wrap holds on this hardware.

Regression with the change:

  • all *_controls functions in tests/compute_store_check.py, including scalar_alu_controls;
  • draw-guard-read on WARP;
  • tests/docs_links_check.py, tests/bidi_controls_check.py, tests/form_coverage_check.py and git diff --check.

I did not run the LLVM 15 binary mode.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 14:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1588) `Asimmimx:shader/compute-absdiff` → `main` · +233 −1 · 4 files · 1 commits · merged 2026-11-24 17:53 UTC ## 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)` gives `0x80000000` (the reference notes "result is negative!"); - `(0x7fffffff, 0x80000000)` gives 1, not `0xffffffff`. **Lowering.** - The template is `asuint(abs(asint({0} - {1})))`. It subtracts as unsigned, so no signed-overflow semantics are involved. DXC 1.8.2502 emits a plain `sub i32` and `IMax(d, 0 - d)`, which keeps `0x80000000`. - The change is one `SALU` entry plus `absdiff_i32` appended to the SALU matcher alternation. - SCC is still not modelled, and its consumers are still refused. **Fixture.** The fixture and controls are in a new `tests/compute_salu_absdiff_check.py`. It imports the helpers of `tests/compute_store_check.py`, which is unchanged. Each lane below the bound stores, with one `buffer_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. | Run (groups, bound) | c1..c5 | Expected words | |---|---|---| | (1, 17) | `2, 5, 0x80000000, 0, 0x7fffffff` | `3, 0x80000000, 1, 0xa` | | (2, 50) | `0x12345678, 0x12345678, 0x80000000, 0xffffffff, 0x80000000` | `0, 0x7fffffff, 0, 7` | | (3, 80) | `-10, 5, 5, -10, 0` | `0xf, 0xf, 0x80000000, 0x16` | **Wrong references and mutations.** Four wrong definitions are written as expected words, and each must fail at its first differing word: - no abs; - unsigned comparison; - difference not wrapped to 32 bits; - INT_MIN saturated to `0x7fffffff`. Three mutated HLSL translations must report "Compute readback differs": `abs` dropped, the INT_MIN literal changed, and the inline constant changed. **Translator controls.** These are refused with the existing messages: - unknown, descriptor, saved-exec and pending sources, and a 33-bit literal; - `s106` and pending destinations; - a vector source, a float inline constant and a 64-bit destination; - `s_absdiff_u32`; - the SCC consumers `s_cselect_b32` and `s_cbranch_scc0`; - the result used as a store address or as a guard operand; - a chain that is too long. The new CTest is `compute_store_aot_salu_absdiff_${adapter}`, registered after `compute_store_aot_mimg_resinfo`. A "Scalar absolute difference" subsection is added to `docs/experiments.md`. ## Verification Commit `6c0e5380` (`main`) plus this change, `dev` preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11. ```powershell python -B tests/compute_salu_absdiff_check.py controls # pass python -B tests/compute_salu_absdiff_check.py draw <dxc> <offscreen_check.exe> warp # pass python -B tests/compute_salu_absdiff_check.py draw <dxc> <offscreen_check.exe> hardware # pass ctest --preset dev --no-tests=error -R '^compute_store_aot_salu_absdiff_(warp|hardware)$' -V ``` | Backend | Result | |---|---| | WARP 10.0.26100.9818, debug layer enabled | 3 runs, 320 words each, mismatches 0, debug errors 0 | | AMD Radeon RX 6600 (RDNA 2, `1002:73ff`), driver 32.0.21045.29003, debug layer enabled | 3 runs, 320 words each, mismatches 0, debug errors 0 | On both backends the INT_MIN case reads `0x80000000`. On the RX 6600, the saturated reference is reported as `word=1 expected=7fffffff actual=80000000`, so the 32-bit wrap holds on this hardware. Regression with the change: - all `*_controls` functions in `tests/compute_store_check.py`, including `scalar_alu_controls`; - `draw-guard-read` on WARP; - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/form_coverage_check.py` and `git diff --check`. I did not run the LLVM 15 `binary` mode. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:18:54 +00:00
github manually merged commit 3f3047c1ff into gh-pr/1588/base 2026-11-26 23:18:56 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 15:46 UTC · original · reviewed

Reviewed at 3f3047c1ff85782d16397eb18afdcba3fbd32432.

Summary

  • Lowering (tools/compute_store_aot.py): Lowers s_absdiff_i32 sD, a, b to asuint(abs(asint({0} - {1}))) in SALU. Unsigned {0} - {1} performs well-defined 32-bit wrapping subtraction, abs(asint(...)) negates negative values in two's complement (preserving 0x80000000 on INT_MIN - 0), and asuint(...) returns the 32-bit word, matching the RDNA 1/2 ISA specification. SCC remains unmodelled and SCC consumers remain rejected.
  • Tests (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

  • Linux:
    • python3 -B tests/compute_salu_absdiff_check.py controls: passed
    • python3 -B tests/docs_links_check.py: passed (16 Markdown files, 344 links)
    • python3 -B tests/bidi_controls_check.py: passed (1253 files)
  • Windows Server 2025 (MSVC 14.44.35207, D3D12 WARP):
    • Debug (--preset dev): 41/41 passed (compute_store_aot_salu_absdiff_warp 3.64s)
    • Release /O2 (--preset release): 41/41 passed (compute_store_aot_salu_absdiff_warp 3.55s)

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 15:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1588#pullrequestreview-6042554524) · **reviewed** Reviewed at `3f3047c1ff85782d16397eb18afdcba3fbd32432`. ### Summary - **Lowering (`tools/compute_store_aot.py`)**: Lowers `s_absdiff_i32 sD, a, b` to `asuint(abs(asint({0} - {1})))` in `SALU`. Unsigned `{0} - {1}` performs well-defined 32-bit wrapping subtraction, `abs(asint(...))` negates negative values in two's complement (preserving `0x80000000` on `INT_MIN - 0`), and `asuint(...)` returns the 32-bit word, matching the RDNA 1/2 ISA specification. SCC remains unmodelled and SCC consumers remain rejected. - **Tests (`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 - **Linux**: - `python3 -B tests/compute_salu_absdiff_check.py controls`: passed - `python3 -B tests/docs_links_check.py`: passed (16 Markdown files, 344 links) - `python3 -B tests/bidi_controls_check.py`: passed (1253 files) - **Windows Server 2025 (MSVC 14.44.35207, D3D12 WARP)**: - Debug (`--preset dev`): 41/41 passed (`compute_store_aot_salu_absdiff_warp` 3.64s) - Release `/O2` (`--preset release`): 41/41 passed (`compute_store_aot_salu_absdiff_warp` 3.55s) AI-assisted; commands listed were executed locally.
Author
Owner

@⁠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.

  • The PR is still mergeable after the merge of #1596: git merge-tree of this head against current main (e4ac2c78) reports no conflicts.

Verified

Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware ctest for 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^ HEAD clean.
  • llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding assembles s_absdiff_i32 s1, s2, s3 (0x96010302) and s_absdiff_i32 s1, s2, 4 (0x96018402).
  • Mutation 1: swapped the operands in the template to asuint(abs(asint({1} - {0}))); controls fails with an AssertionError.
  • Mutation 2: dropped abs (asuint(asint({0} - {1}))); controls fails with an AssertionError.
  • Both mutations were reverted with git checkout -- .; git status --short clean.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 17:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1588#pullrequestreview-6044349763) · **reviewed** Re-verification at `head_sha`: `3f3047c1ff85782d16397eb18afdcba3fbd32432` (same head as the earlier review). ### Findings No P1/P2. No defect found. - The PR is still mergeable after the merge of #1596: `git merge-tree` of this head against current `main` (`e4ac2c78`) reports no conflicts. ### Verified Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware `ctest` for 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^ HEAD` clean. - `llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding` assembles `s_absdiff_i32 s1, s2, s3` (`0x96010302`) and `s_absdiff_i32 s1, s2, 4` (`0x96018402`). - **Mutation 1:** swapped the operands in the template to `asuint(abs(asint({1} - {0})))`; `controls` fails with an `AssertionError`. - **Mutation 2:** dropped `abs` (`asuint(asint({0} - {1}))`); `controls` fails with an `AssertionError`. - Both mutations were reverted with `git checkout -- .`; `git status --short` clean. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.