shader: lower s_brev_b64, s_bitset0/1_b64 and s_flbit_i32_b64/i64 #96
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!96
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-96"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lcg007xd-c on GitHub · 2026-11-25 22:31 UTC · original
lcg007xd-c:shader-s-bits64→main· +148 −0 · 2 files · 1 commits · openWhat 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.s_brev_b64s_bitset0_b64s_bitset1_b64s_flbit_i32_b64s_flbit_i32_i64They 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.u64is S0's 64 bits in reverse order.s_bitset0_b64/s_bitset1_b64: clear or set bitS0[5:0]of the 64-bit destination. The IR already reads the old destination fors_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, whichhalfalready does for_i64.The change (
emit/lower.rs, insop's 64-bit section)s_brev_b64: each dword is reversed (DXILBfrev), 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_*: DXILFirstbitHiof 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 thelower.rschange 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 fors_brev_b64and the bitsets, the latter with bit indices 3, 37, 63 and 0. Thes_flbitcases include 0, −1-like values and a sign bit alone.lli. I compared against Rust'sreverse_bits/leading_zerosand 64-bit masks on 48 inputs (40 scrambled), including an index of 71 that only bits 5:0 count. I also checked a literal−2fors_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.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
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]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.