shader: lower compute s_absdiff_i32 #1581

Merged
Asimmimx merged 1 commit from upstream-pr/1588 into main 2026-11-24 17:53:45 +00:00
Asimmimx commented 2026-11-24 14:37:26 +00:00 (Migrated from github.com)

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) 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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584250243 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1588). Originally posted by [Asimmimx](https://github.com/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)` 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).
tedin7 commented 2026-11-24 16:03:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:46:49Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042554524 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1588#pullrequestreview-6042554524). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:46:49Z. **Review:** COMMENTED --- 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.
upstream-sync closed this pull request 2026-11-24 18:02:16 +00:00
tedin7 commented 2026-11-24 18:02:16 +00:00 (Migrated from github.com)

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.

  • 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044349763 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1588#pullrequestreview-6044349763). Originally posted by [tedin7](https://github.com/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. - 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.
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!1581
No description provided.