shader: lower s_sext_i32_i8 and s_sext_i32_i16 #91

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

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

What is broken

s_sext_i32_i8 (SOP1 0x19) and s_sext_i32_i16 (SOP1 0x1A) decode, but a program using either fails to translate with s_sext_i32_i8 is not supported (or the i16 name). They sign-extend a byte or a short held in an SGPR, which compilers emit for int8/int16 loads and for packed constants.

How I found them: I translated every SOP1/SOP2 opcode the decoder names through the CPU harness of #62, with the result in s12. The earlier coverage run wrote s10, which overlaps the UAV descriptor, so it could not see scalar gaps. The same sweep found the s_pack_* gap (#89).

Semantics

AMD's RDNA2 ISA (§12.2, opcodes 25 and 26): D.i = signext(S0.i[7:0]) and D.i = signext(S0.i[15:0]). They write no SCC, and the IR's writes_scc already leaves them out.

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

Each is a shift left by 24 (or 16) followed by an arithmetic shift right by the same amount.

Tests

  • emit::lower::tests::scalar_sign_extensions_translate (every host): both decode, and a program that moves the result to v0 and stores it translates. Without the lower.rs change it fails: s_sext_i32_i8 [be8c1901, 7e00020c]: GFX10 code at 0x24: s_sext_i32_i8 is not supported.
  • valu_tests::scalar_sign_extensions_match_rdna2 (Windows/GPU): three hand-computed cases each, covering negative and positive bytes and halves with junk above them.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I compared against Rust's as i8/as i16 casts on 80 scrambled inputs, plus a 32-bit literal source. 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:24 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/91) `lcg007xd-c:shader-s-sext` → `main` · +64 −0 · 2 files · 1 commits · open ## What is broken `s_sext_i32_i8` (SOP1 **0x19**) and `s_sext_i32_i16` (SOP1 **0x1A**) decode, but a program using either fails to translate with `s_sext_i32_i8 is not supported` (or the `i16` name). They sign-extend a byte or a short held in an SGPR, which compilers emit for `int8`/`int16` loads and for packed constants. **How I found them:** I translated every SOP1/SOP2 opcode the decoder names through the CPU harness of #62, with the result in `s12`. The earlier coverage run wrote `s10`, which overlaps the UAV descriptor, so it could not see scalar gaps. The same sweep found the `s_pack_*` gap (#89). ## Semantics AMD's RDNA2 ISA (§12.2, opcodes 25 and 26): `D.i = signext(S0.i[7:0])` and `D.i = signext(S0.i[15:0])`. They write no SCC, and the IR's `writes_scc` already leaves them out. ## The change (`emit/lower.rs`, in `sop`) Each is a shift left by 24 (or 16) followed by an arithmetic shift right by the same amount. ## Tests - **`emit::lower::tests::scalar_sign_extensions_translate`** (every host): both decode, and a program that moves the result to `v0` and **stores** it translates. Without the `lower.rs` change it fails: `s_sext_i32_i8 [be8c1901, 7e00020c]: GFX10 code at 0x24: s_sext_i32_i8 is not supported`. - **`valu_tests::scalar_sign_extensions_match_rdna2`** (Windows/GPU): three hand-computed cases each, covering negative and positive bytes and halves with junk above them. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I compared against Rust's `as i8`/`as i16` casts on 80 scrambled inputs, plus a 32-bit literal source. 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)
SOP1 0x19 and 0x1A decoded but failed to translate ("s_sext_i32_i8 is
not supported"). AMD's RDNA2 ISA: D.i = signext(S0[7:0]) and
signext(S0[15:0]); they write no SCC.

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:42 +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/91/head:github-bot/gh-91'
git switch 'github-bot/gh-91'

Merge

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