shader: lower s_pack_ll/lh/hh_b32_b16 #89

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

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

What is broken

The scalar packs decode, but a program using one fails to translate with s_pack_ll_b32_b16 is not supported (or the matching name):

SOP2 opcode Instruction
0x32 s_pack_ll_b32_b16
0x33 s_pack_lh_b32_b16
0x34 s_pack_hh_b32_b16

Compilers use them to build packed 16-bit constants and operands for the v_pk_* instructions.

How I found them: I translated, through the CPU harness of #62, a one-instruction program for every SOP1 and SOP2 opcode the decoder names, with the result in s12. The scout coverage run used s10, which overlaps the program's UAV descriptor in s[8:11], so it reported nearly every scalar op as "a descriptor changed after loading". With s12, 50 scalar opcodes turn out to be refused, and these three are among them.

Semantics

AMD's RDNA2 ISA (§12.1, opcodes 50–52):

  • s_pack_ll_b32_b16: D = {S1[15:0], S0[15:0]}
  • s_pack_lh_b32_b16: D = {S1[31:16], S0[15:0]}
  • s_pack_hh_b32_b16: D = {S1[31:16], S0[31:16]}

They write no SCC. The IR's writes_scc already leaves them out.

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

Each source's named half is masked or shifted into place, and the two are ORed.

Tests

  • emit::lower::tests::scalar_packs_translate (every host): all three decode, and a program that moves the result to v0 and stores it translates. Without the lower.rs change it fails: s_pack_ll_b32_b16 [990c0100, 7e00020c]: GFX10 code at 0x24: s_pack_ll_b32_b16 is not supported.
  • valu_tests::scalar_packs_take_the_halves_their_names_say (Windows/GPU): two hand-computed cases per opcode.
  • 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 a Rust reference on 60 scrambled pairs per opcode, also with src0 an inline constant (−1) and a 32-bit literal. 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:22 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/89) `lcg007xd-c:shader-s-pack` → `main` · +76 −0 · 2 files · 1 commits · open ## What is broken The scalar packs decode, but a program using one fails to translate with `s_pack_ll_b32_b16 is not supported` (or the matching name): | SOP2 opcode | Instruction | |---|---| | 0x32 | `s_pack_ll_b32_b16` | | 0x33 | `s_pack_lh_b32_b16` | | 0x34 | `s_pack_hh_b32_b16` | Compilers use them to build packed 16-bit constants and operands for the `v_pk_*` instructions. **How I found them:** I translated, through the CPU harness of #62, a one-instruction program for every SOP1 and SOP2 opcode the decoder names, with the result in `s12`. The scout coverage run used `s10`, which overlaps the program's UAV descriptor in `s[8:11]`, so it reported nearly every scalar op as "a descriptor changed after loading". With `s12`, 50 scalar opcodes turn out to be refused, and these three are among them. ## Semantics AMD's RDNA2 ISA (§12.1, opcodes 50–52): - `s_pack_ll_b32_b16`: `D = {S1[15:0], S0[15:0]}` - `s_pack_lh_b32_b16`: `D = {S1[31:16], S0[15:0]}` - `s_pack_hh_b32_b16`: `D = {S1[31:16], S0[31:16]}` They write no SCC. The IR's `writes_scc` already leaves them out. ## The change (`emit/lower.rs`, in `sop`) Each source's named half is masked or shifted into place, and the two are ORed. ## Tests - **`emit::lower::tests::scalar_packs_translate`** (every host): all three decode, and a program that moves the result to `v0` and **stores** it translates. Without the `lower.rs` change it fails: `s_pack_ll_b32_b16 [990c0100, 7e00020c]: GFX10 code at 0x24: s_pack_ll_b32_b16 is not supported`. - **`valu_tests::scalar_packs_take_the_halves_their_names_say`** (Windows/GPU): two hand-computed cases per opcode. - **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 a Rust reference on 60 scrambled pairs per opcode, also with src0 an inline constant (−1) and a 32-bit literal. 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 0x32..=0x34 decoded but failed to translate ("s_pack_ll_b32_b16 is
not supported"). AMD's RDNA2 ISA: D = {S1 half, S0 half}, taking the
low (l) or high (h) half of each source as the name orders them, S0
first. 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:40 +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/89/head:github-bot/gh-89'
git switch 'github-bot/gh-89'

Merge

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