shader: lower s_absdiff_i32 #94

Open
github-bot wants to merge 1 commit from github-bot/gh-94 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:27 UTC · original
lcg007xd-c:shader-s-absdiff → main · +70 −0 · 2 files · 1 commits · open

What is broken

s_absdiff_i32 (SOP2 0x2C) decodes, but a program using it fails to translate with s_absdiff_i32 is not supported. I found it in the scalar sweep through the CPU harness of #62, the same sweep as #89, #91 and #92.

Semantics

AMD's RDNA2 ISA (§12.1, opcode 44): D.i = S0.i - S1.i; if (D.i < 0) D.i = -D.i, and SCC = (D != 0). The difference is a 32-bit one and wraps. So, for example, |0x80000000 - 0| stays 0x80000000, as the hardware's two's-complement negation leaves it.

The change (emit/lower.rs, in sop)

  • Value: subtract, then negate when the result is negative.
  • SCC: SCC = (D != 0) is what sop's shared SCC path already sets, and the IR already lists absdiff among the SCC writers.

Tests

  • emit::lower::tests::scalar_absolute_difference_translates (every host): the encoding decodes. Two programs translate: one that stores the value, and one that stores SCC through s_cselect_b32. Without the lower.rs change it fails: s_absdiff_i32 [960c0100, 7e00020c]: GFX10 code at 0x24: s_absdiff_i32 is not supported.
  • valu_tests::scalar_absolute_difference_matches_rdna2 (Windows/GPU): the value and SCC for five pairs, covering both orders, a negative operand, equal values (SCC 0), and INT_MIN − 0.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I compared the value and SCC against Rust's wrapping_sub(..).wrapping_abs() on all 81 pairs of 9 edge values. All match.

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.
  • Portable clippy and CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the GPU case, since I have no Windows machine.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:27 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/94) `lcg007xd-c:shader-s-absdiff` → `main` · +70 −0 · 2 files · 1 commits · open ## What is broken `s_absdiff_i32` (SOP2 **0x2C**) decodes, but a program using it fails to translate with `s_absdiff_i32 is not supported`. I found it in the scalar sweep through the CPU harness of #62, the same sweep as #89, #91 and #92. ## Semantics AMD's RDNA2 ISA (§12.1, opcode 44): `D.i = S0.i - S1.i; if (D.i < 0) D.i = -D.i`, and `SCC = (D != 0)`. The difference is a 32-bit one and wraps. So, for example, `|0x80000000 - 0|` stays `0x80000000`, as the hardware's two's-complement negation leaves it. ## The change (`emit/lower.rs`, in `sop`) - **Value:** subtract, then negate when the result is negative. - **SCC:** `SCC = (D != 0)` is what `sop`'s shared SCC path already sets, and the IR already lists `absdiff` among the SCC writers. ## Tests - **`emit::lower::tests::scalar_absolute_difference_translates`** (every host): the encoding decodes. Two programs translate: one that **stores** the value, and one that stores SCC through `s_cselect_b32`. Without the `lower.rs` change it fails: `s_absdiff_i32 [960c0100, 7e00020c]: GFX10 code at 0x24: s_absdiff_i32 is not supported`. - **`valu_tests::scalar_absolute_difference_matches_rdna2`** (Windows/GPU): the value and SCC for five pairs, covering both orders, a negative operand, equal values (SCC 0), and `INT_MIN − 0`. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I compared the value and SCC against Rust's `wrapping_sub(..).wrapping_abs()` on all 81 pairs of 9 edge values. All match. **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib --locked`: 188 passed, 0 failed, 2 ignored. - Portable clippy and `CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the GPU case, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
SOP2 0x2C decoded but failed to translate ("s_absdiff_i32 is not
supported"). AMD's RDNA2 ISA: D.i = S0.i - S1.i, negated if negative
(the 32-bit difference wraps, so |INT_MIN| stays 0x80000000), and
SCC = (D != 0), which the shared SCC path already gives.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:49 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/94/head:github-bot/gh-94'
git switch 'github-bot/gh-94'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-94'
git switch 'github-bot/gh-94'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-94'
git switch 'github-bot/gh-94'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-94'
git switch 'main'
git merge --squash 'github-bot/gh-94'
git switch 'main'
git merge --ff-only 'github-bot/gh-94'
git switch 'main'
git merge 'github-bot/gh-94'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.