Repository navigation
Shaders: lower s_bcnt0_i32_b32/_b64, s_ff0_i32_b32/_b64 and s_flbit_i32_b64/_i64 - #148
Rareuncommon wants to merge 1 commit into
Conversation
…32_b64/_i64 Six scalar instructions the emitter refused by name: - s_bcnt0_i32_b32/_b64: the count of clear bits, as the set bits of the complement; SCC = result != 0. - s_ff0_i32_b32/_b64: the lowest clear bit (-1 for none), as s_ff1 of the complement. - s_flbit_i32_b64, s_flbit_i32_i64: the first bit from the top of the pair (for the signed form, the first that differs from the sign), counted from bit 63, -1 for none. The high dword answers unless it has no such bit; then the low dword is searched for a bit that differs from it. On plain data only; a lane mask as the source is still refused, as before. AI-assisted (Claude Code).
|
Tested
No game data used. |
|
I ran the six instructions on Windows 11 build 26200, with your head For each opcode, the synthetic shader checked ten operands with both initial SCC states, returning either the instruction result or SCC. This covered all-zero and all-one inputs, a first zero in the upper dword, and signed versus unsigned FLBIT. BCNT0 set SCC from its result. FF0 and FLBIT preserved incoming SCC. Unmodified To reproduce, cherry-pick the test-only commit onto the test merge, leave cargo test --frozen -p victory-shader --features host --lib vic11_ -- --nocapture --test-threads=1The reference was a CPU model of the ISA. This run used synthetic inputs. Codex prepared the fixture and Claude reviewed the method and its limits. |
|
RDNA2 hardware check of the six instructions: all match. Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 130 cases: low dwords from edge values and random, high dwords
(#165 covers four of these and matches too.) AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
catminou4
left a comment
There was a problem hiding this comment.
Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head a038004:
cargo test -p victory-shader --locked: compiles clean, all ungated tests pass (no regressions vs main's 56).
Scope note: valu_tests/image_tests in victory-shader are #[cfg(all(test, windows))] — they need the Windows host backend (D3D12/dxil.dll), so they did not run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new s_bcnt0/s_ff0/s_flbit lowering coverage still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.
|
Merged onto Checked with CI's steps (both clippy runs with |
|
Automated triage for the maintainers. Needs rebase. This pull request conflicts with Generated by Claude Code |
|
I rebased the six existing scalar operations onto
The commits are on |
Six scalar instructions that the emitter refuses by name now translate. One file,
crates/victory-shader/src/emit/lower.rs: 91 lines of lowering and a 31-line unit test (122 added, none removed).What is in it
s_bcnt0_i32_b32/s_bcnt0_i32_b64: the count of clear bits, as the set bits of the complement. SCC = result != 0, asir::writes_sccalready expects forbcnt0.s_ff0_i32_b32/s_ff0_i32_b64: the lowest clear bit, -1 for none, ass_ff1of the complement. No SCC.s_flbit_i32_b64/s_flbit_i32_i64: the first bit from the top of the pair (for the signed form, the first that differs from the sign), counted from bit 63, -1 for none. The high dword answers unless it has no such bit; then it is all sign or zero, and the low dword is searched for a bit that differs from it.They follow the forms already there (
s_bcnt1_i32_b64,s_ff1_i32_b64,s_flbit_i32_b32) and use the same DXIL bit operations (31, 32, 33, 34). Plain data only: a lane mask as the source is still refused, as before.How I found them
A local probe that encodes every SOP1, SOP2, VOP1, VOP2 and VOP3 opcode of
gfx10/opcodes.rsinto a one-instruction compute program and runs it throughir::build→structure→lower: 219 of 364 lowered before this change, 225 after. The probe is not in this PR. I cannot say how many of the title's programs use these six; I have no game files.Tested
macOS 27 arm64, Rust 1.98.1, debug, no GPU and no game files:
cargo test -p victory-core -p victory-formats -p victory-shader: 8, 20 (3 ignored) and 57 passed, 0 failed. The new test,scalar_zero_counts_and_bit_scans_lower, checks that each of the six lowers, and that the SCC of the two zero counts reaches a branch.cargo fmt -p victory-shader -- --check: clean.cargo clippy -p victory-shader --all-targets: no new warnings.cargo xtask policy: 151 files ok.Checked on hardware by others (see the comments)
a038004merged ontod2a4bae, 240 UAV readbacks on an RTX 3050 Laptop GPU and 240 on WARP, all matching a CPU model of the ISA;mainrefused all six.cargo test -p victory-shaderon Arch Linux, 57 passed.Not tested (by me)
valu_tests,diff_tests) are Windows-only and need a GPU, which I do not have, so nothing here has executed the emitted DXIL. The arithmetic is by reading the existing forms and the ISA rules; a run on a GPU by someone who has one would be welcome.victory-gpu,victory-hle,victory-loader) were not built.victory-pe's four own-image tests fail on macOS onmaintoo (they read the test binary as a PE); not touched here.No game data: the test is seven hand-written instruction words per case.
AI-assisted: yes (Claude Code). I am not the first to ask whether that is welcome here (#22); say so if it is not and I will close this.
🤖 Generated with Claude Code