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--gone-20261201!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]>@lmouz823-lang on GitHub · 2026-11-28 04:09 UTC · original
I can take Windows GPU validation at exact head
59fe40f8b427d8fbf2ef51809f6e5b2e99bb64ca. I will run the existing translation and result tests on RTX 4060 Laptop and WARP with the SDK validator, then add a fixed-expectation SCC regression. It will check both incoming SCC values, count instructions updating SCC and find-first-zero instructions preserving it, with result readback as well. A temporary omission of the new 64-bit count SCC write will provide a negative control, followed by source restoration and fresh final runs. I will report exact counts and any test-only patch here. AI-assisted with Codex.@lmouz823-lang on GitHub · 2026-11-28 04:22 UTC · original
Native Windows validation completed for exact head
59fe40f8b427d8fbf2ef51809f6e5b2e99bb64caon RTX 4060 Laptop and WARP.The unchanged head's translation and GPU tests each execute exactly one test and pass. I added one GPU regression for the flags that the current result-only GPU test does not read. It uses five fixed input pairs, incoming SCC 0 and 1, and separate result/SCC readbacks for all four operations. 80 dispatches per backend, 160 total, pass with
VICTORY_STRICT_TESTS=1and no skips or ignored tests.The fixed table checks that both
s_bcnt0widths overwrite SCC for zero and nonzero results, while boths_ff0widths preserve SCC for results including 0 and -1. It also includes an all-zero 64-bit input, whose count is 64. Incoming flags are set withs_add_u32 s14, s2, 1, using s2=0 oru32::MAX, then read throughs_cselect_b32. The reference is AMD's RDNA2 ISA, SOP1 opcodes 13, 14, 17 and 18, printed pages 112–113.A negative control forces only
s_bcnt0_i32_b64's SCC output to false, keeping its data result correct. The original GPU test still passes. The new test fails on hardware for input(0xfffffff7, 0), incoming SCC 0, count 33, reporting SCC 0 where the fixed table expects 1. After restoring the implementation and removing diagnostics, a fresh compilation and final runs of the new GPU test, original GPU test and translation test each pass. The final patch adds only the 72-line synthetic test.The explicit SDK
dxil.dll1.8.2502.11 createdIDxcValidator. Temporary success markers after validation and the container-hash assertion confirmed all eight new modules and all four original modules passed both checks. Those markers were removed before the final runs. Independent review verified the expectations, input seeding, encodings, counts, final diff and execution evidence.Environment was Windows 11 Pro build 26200, i9-14900HX, NVIDIA 610.88 and Rust 1.98.1 MSVC, release. Package Clippy with
--all-targets -- -D warnings, asset policy (195 files),git diff --checkand rustfmt on the added function pass. Native AMD/RDNA2 execution, game behavior and the full workspace suite remain unverified.Reproduction uses an installed SDK validator and the Windows build prerequisites.
AI assistance from Codex covered the test, execution, independent review and this report.
72-line synthetic test patch against this PR head
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.