shader: lower s_bcnt0_i32_b32/b64 and s_ff0_i32_b32/b64 #95
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!95
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-95"
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:29 UTC · original
lcg007xd-c:shader-s-zero-bits→main· +104 −0 · 2 files · 1 commits · openWhat is broken
The zero-bit counterparts of the supported
s_bcnt1_*/s_ff1_*decode, but a program using one fails to translate withs_bcnt0_i32_b32 is not supported(or the matching name):s_bcnt0_i32_b32s_bcnt0_i32_b64s_ff0_i32_b32s_ff0_i32_b64They 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 13, 14, 17, 18)
s_bcnt0: counts the zero bits of S0, andSCC = (D != 0).s_ff0: gives the position of the first zero bit from the bottom, or −1 if there is none. It writes no SCC.The change (
emit/lower.rs, insop)s_bcnt1/s_ff1lowering (DXILCountbits/FirstbitLo) applied to the complement of S0.s_bcnt0_i32_b64adds the two dwords' counts.s_ff0_i32_b64takes the low dword's position if it has a zero bit, else 32 plus the high dword's (−1 if neither has one), ass_ff1_i32_b64does.s_bcnt0_i32_b64sets SCC itself, because the 64-bit forms return early.s_bcnt0: its SCC comes from the shared path.Tests
emit::lower::tests::scalar_zero_bit_counts_translate(every host): all four decode, and a program that movess12tov0and stores it translates. Without thelower.rschange it fails:s_bcnt0_i32_b32 [be8c0d00, 7e00020c]: GFX10 code at 0x24: s_bcnt0_i32_b32 is not supported.valu_tests::scalar_zero_bit_counts_and_scans_match_rdna2(Windows/GPU): four hand-computed cases per opcode. They include all ones (count 0, scan −1), a zero only in the high dword (scan 63), and all zeros.lli. I compared all four against Rust'scount_zeros/trailing_zeroson 65 64-bit inputs, plus SCC for boths_bcnt0widths. 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 0x0D, 0x0E, 0x11 and 0x12 decoded but failed to translate ("s_bcnt0_i32_b32 is not supported"). AMD's RDNA2 ISA: the number of zero bits (SCC = result != 0) and the position of the first zero bit from the bottom (-1 if there is none). They lower as the supported s_bcnt1/s_ff1 forms of the complement, the 64-bit ones over both dwords. 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.