shader: lower s_brev_b64, s_bitset0/1_b64 and s_flbit_i32_b64/i64 #96

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

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

What is broken

The 64-bit forms of scalar bit operations decode, but a program using one fails to translate with s_brev_b64 is not supported (or the matching name). Their 32-bit forms already lower.

SOP1 opcode Instruction
0x0C s_brev_b64
0x1C s_bitset0_b64
0x1E s_bitset1_b64
0x16 s_flbit_i32_b64
0x18 s_flbit_i32_i64

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.2, opcodes 12, 22, 24, 28, 30)

  • s_brev_b64: D.u64 is S0's 64 bits in reverse order.
  • s_bitset0_b64 / s_bitset1_b64: clear or set bit S0[5:0] of the 64-bit destination. The IR already reads the old destination for s_bitset*.
  • s_flbit_i32_b64: the first set bit counted from the top, or −1 if there is none.
  • s_flbit_i32_i64: the number of leading bits equal to the sign bit, or −1 if all of them are. A 32-bit literal source sign-extends, which half already does for _i64.
  • SCC: none of them writes it.

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

  • s_brev_b64: each dword is reversed (DXIL Bfrev), and the two are swapped.
  • s_bitset*_b64: bit 5 of the index picks the dword, and bits 4:0 the bit within it.
  • s_flbit_*: DXIL FirstbitHi of each dword, the high dword first. The signed form first XORs both dwords with the sign.

Tests

  • emit::lower::tests::scalar_64_bit_bit_operations_translate (every host): all five decode, and a program that stores the result translates. Without the lower.rs change it fails: s_brev_b64 [be8c0c00, 7e00020c]: GFX10 code at 0x24: s_brev_b64 is not supported.
  • valu_tests::scalar_64_bit_bit_operations_match_rdna2 (Windows/GPU): four inputs. Each dword is checked for s_brev_b64 and the bitsets, the latter with bit indices 3, 37, 63 and 0. The s_flbit cases include 0, −1-like values and a sign bit alone.
  • 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 reverse_bits/leading_zeros and 64-bit masks on 48 inputs (40 scrambled), including an index of 71 that only bits 5:0 count. I also checked a literal −2 for s_flbit_i32_i64 (sign-extended: 63). 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:31 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/96) `lcg007xd-c:shader-s-bits64` → `main` · +148 −0 · 2 files · 1 commits · open ## What is broken The 64-bit forms of scalar bit operations decode, but a program using one fails to translate with `s_brev_b64 is not supported` (or the matching name). Their 32-bit forms already lower. | SOP1 opcode | Instruction | |---|---| | 0x0C | `s_brev_b64` | | 0x1C | `s_bitset0_b64` | | 0x1E | `s_bitset1_b64` | | 0x16 | `s_flbit_i32_b64` | | 0x18 | `s_flbit_i32_i64` | 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.2, opcodes 12, 22, 24, 28, 30) - **`s_brev_b64`:** `D.u64` is S0's 64 bits in reverse order. - **`s_bitset0_b64` / `s_bitset1_b64`:** clear or set bit `S0[5:0]` of the 64-bit destination. The IR already reads the old destination for `s_bitset*`. - **`s_flbit_i32_b64`:** the first set bit counted from the top, or −1 if there is none. - **`s_flbit_i32_i64`:** the number of leading bits equal to the sign bit, or −1 if all of them are. A 32-bit literal source sign-extends, which `half` already does for `_i64`. - **SCC:** none of them writes it. ## The change (`emit/lower.rs`, in `sop`'s 64-bit section) - **`s_brev_b64`:** each dword is reversed (DXIL `Bfrev`), and the two are swapped. - **`s_bitset*_b64`:** bit 5 of the index picks the dword, and bits 4:0 the bit within it. - **`s_flbit_*`:** DXIL `FirstbitHi` of each dword, the high dword first. The signed form first XORs both dwords with the sign. ## Tests - **`emit::lower::tests::scalar_64_bit_bit_operations_translate`** (every host): all five decode, and a program that **stores** the result translates. Without the `lower.rs` change it fails: `s_brev_b64 [be8c0c00, 7e00020c]: GFX10 code at 0x24: s_brev_b64 is not supported`. - **`valu_tests::scalar_64_bit_bit_operations_match_rdna2`** (Windows/GPU): four inputs. Each dword is checked for `s_brev_b64` and the bitsets, the latter with bit indices 3, 37, 63 and 0. The `s_flbit` cases include 0, −1-like values and a sign bit alone. - **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 `reverse_bits`/`leading_zeros` and 64-bit masks on 48 inputs (40 scrambled), including an index of 71 that only bits 5:0 count. I also checked a literal `−2` for `s_flbit_i32_i64` (sign-extended: 63). 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 0x0C, 0x1C, 0x1E, 0x16 and 0x18 decoded but failed to translate
("s_brev_b64 is not supported"): the 64-bit forms of scalar bit
operations whose 32-bit forms lower. As AMD's RDNA2 ISA defines them:
s_brev_b64 reverses all 64 bits (each dword reversed, then swapped);
s_bitset0/1_b64 clear or set bit S0[5:0] of the destination they read;
s_flbit_i32_b64 finds the first set bit from the top (-1 for none), and
s_flbit_i32_i64 the first bit that differs from the sign. None writes
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:52 +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/96/head:github-bot/gh-96'
git switch 'github-bot/gh-96'

Merge

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