shader: lower s_bfe_u64, s_bfe_i64 and s_bfm_b64 #97

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

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

What is broken

The 64-bit scalar bitfield instructions decode, but a program using one fails to translate with s_bfe_u64 is not supported (or the matching name). Their 32-bit forms (s_bfe_u32, s_bfe_i32, s_bfm_b32) already lower.

SOP2 opcode Instruction
0x29 s_bfe_u64
0x2A s_bfe_i64
0x25 s_bfm_b64

They are part of the scalar gap the sweep through the CPU harness of #62 turned up (see #89).

Semantics (AMD's RDNA2 ISA, §12.1, opcodes 37, 41, 42)

  • s_bfe_u64: D.u64 = (S0.u64 >> S1[5:0]) & ((1 << S1[22:16]) - 1) and SCC = (D != 0). s_bfe_i64 sign-extends the field from its top bit.
  • s_bfm_b64: D.u64 = ((1 << S0[5:0]) - 1) << S1[5:0]. It writes no SCC.
  • Widths of 64 or more (the field is 7 bits) take every bit left after the shift. That is how this file's bfe helper already treats a width of 32 or more for s_bfe_u32.

The change (emit/lower.rs, in sop's 64-bit section)

  • 64-bit integers: the source pair is joined into an i64, and the extract (or mask) is computed in i64 (INT64 flag), mirroring the 32-bit bfe helper: a full-width mask, then a sign extension skipped for widths 0 and ≥ 64.
  • Result: split back into the two dwords. SCC is set for the extracts.

Tests

  • emit::lower::tests::scalar_64_bit_bitfields_translate (every host): all three decode, and a program that stores the result translates. Without the lower.rs change it fails: s_bfe_u64 [948c0200, 7e00020c]: GFX10 code at 0x24: s_bfe_u64 is not supported.
  • valu_tests::scalar_64_bit_bitfields_match_rdna2 (Windows/GPU): both dwords of each result for four cases: a field across the dword boundary, a sign-set top nibble, width 64, and width 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 both dwords against a Rust u64/i64 reference on 38 cases. They include widths 1, 32, 63+, 127 and junk in S1's other bits, plus SCC for both extracts. 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. I could not check widths above 64 on RDNA2 hardware, so they follow the 32-bit lowering's rule.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:34 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/97) `lcg007xd-c:shader-s-bfe64` → `main` · +154 −0 · 2 files · 1 commits · open ## What is broken The 64-bit scalar bitfield instructions decode, but a program using one fails to translate with `s_bfe_u64 is not supported` (or the matching name). Their 32-bit forms (`s_bfe_u32`, `s_bfe_i32`, `s_bfm_b32`) already lower. | SOP2 opcode | Instruction | |---|---| | 0x29 | `s_bfe_u64` | | 0x2A | `s_bfe_i64` | | 0x25 | `s_bfm_b64` | They are part of the scalar gap the sweep through the CPU harness of #62 turned up (see #89). ## Semantics (AMD's RDNA2 ISA, §12.1, opcodes 37, 41, 42) - **`s_bfe_u64`:** `D.u64 = (S0.u64 >> S1[5:0]) & ((1 << S1[22:16]) - 1)` and `SCC = (D != 0)`. `s_bfe_i64` sign-extends the field from its top bit. - **`s_bfm_b64`:** `D.u64 = ((1 << S0[5:0]) - 1) << S1[5:0]`. It writes no SCC. - **Widths of 64 or more** (the field is 7 bits) take every bit left after the shift. That is how this file's `bfe` helper already treats a width of 32 or more for `s_bfe_u32`. ## The change (`emit/lower.rs`, in `sop`'s 64-bit section) - **64-bit integers:** the source pair is joined into an i64, and the extract (or mask) is computed in i64 (`INT64` flag), mirroring the 32-bit `bfe` helper: a full-width mask, then a sign extension skipped for widths 0 and ≥ 64. - **Result:** split back into the two dwords. SCC is set for the extracts. ## Tests - **`emit::lower::tests::scalar_64_bit_bitfields_translate`** (every host): all three decode, and a program that **stores** the result translates. Without the `lower.rs` change it fails: `s_bfe_u64 [948c0200, 7e00020c]: GFX10 code at 0x24: s_bfe_u64 is not supported`. - **`valu_tests::scalar_64_bit_bitfields_match_rdna2`** (Windows/GPU): both dwords of each result for four cases: a field across the dword boundary, a sign-set top nibble, width 64, and width 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 both dwords against a Rust `u64`/`i64` reference on 38 cases. They include widths 1, 32, 63+, 127 and junk in S1's other bits, plus SCC for both extracts. 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. I could not check widths above 64 on RDNA2 hardware, so they follow the 32-bit lowering's rule. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
SOP2 0x29, 0x2A and 0x25 decoded but failed to translate ("s_bfe_u64
is not supported"): the 64-bit forms of s_bfe_u32/s_bfe_i32/s_bfm_b32.
AMD's RDNA2 ISA: s_bfe extracts a field of width S1[22:16] at offset
S1[5:0] (sign-extended for _i64; a width of 64 or more takes every
remaining bit, as the 32-bit lowering does for 32), SCC = (D != 0);
s_bfm_b64 builds ((1 << S0[5:0]) - 1) << S1[5:0] with no SCC. Computed
in 64-bit integers.

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

Merge

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