shader: lower s_brev_b64, s_bitset0/1_b64 and s_flbit_i32_b64/i64 #96
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:31:48Z.
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.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
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T05:12:14Z.
I can take native Windows GPU validation at exact head
ab2a558ccb42305edc93006362080be8c0aa8281. I will run the existing translation and result tests, add focused fixed-expectation coverage for 64-bit boundary indices and preservation of incoming SCC, and use a temporary regression to verify the added coverage. Final restored-source runs will use RTX 4060 Laptop and WARP with the SDK validator. I will report exact counts, any skipped cases and the remaining native AMD/game scope. AI-assisted with Codex.Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T05:22:53Z.
Native Windows GPU validation completed for exact head
ab2a558ccb42305edc93006362080be8c0aa8281. The existing translation and GPU regressions each execute exactly one test and pass. The original GPU case runs 64 dispatches across RTX 4060 Laptop and WARP.I added one fixed-expectation regression covering all five instructions' SCC preservation with incoming SCC 0 and 1. Six vectors cover zero, all ones, high-only data, the sign bit and mixed dwords, with bitset indices 0, 31, 32, 63, 64 and 71. Result dwords and SCC are read separately. A separate 32-bit literal
-2checks sign extension fors_flbit_i32_i64, with result 63 and both incoming flags retained. Expectations follow AMD's RDNA2 ISA, SOP1 opcodes 12, 22, 24, 28 and 30, printed pages 112 and 115–116.The main matrix uses 13 shaders × 12 inputs × two backends, plus two literal shaders × two inputs × two backends, giving 320 passing dispatches. The added patch is 125 test-only lines. Independent review checked the fixed result tables, encodings, seed/readback registers and counts.
A temporary negative control replaces the bitset dword selector
(index & 32) != 0withindex >= 32. The original GPU regression still passes because its indices are below 64. The new regression fails on hardware at index 64, observing high dword0x7ffffffeinstead of0x7ffffffffors_bitset0_b64. That exact test exits 101. I then restored the implementation byte-for-byte, removed temporary diagnostics and confirmed a fresh 1m09s compilation before the final 320-dispatch pass. Both original exact tests also pass again. All three final selections have zero failed or ignored tests and no skip diagnostics.The explicitly selected SDK
dxil.dll1.8.2502.11 successfully createdIDxcValidator. Temporary markers after load and after validation plus the container-hash assertion confirmed all 15 new modules and all eight original modules passed those checks. The markers are absent from the final patch and runs.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), new-function rustfmt andgit diff --checkpass. Whole-file rustfmt exits 1 on both the original and patched source, with the same 17 existing formatting hunks after removing file/line headers. Native AMD execution, the full shader/workspace suites and game behavior remain unverified. This validation covers the listed synthetic source patterns and SCC/index boundaries.Reproduction uses an installed SDK validator and the project's Windows build prerequisites.
AI assistance from Codex covered the test, execution, independent review and this report.
125-line synthetic GPU regression against this PR head
Pull request closed