Repository navigation
Recompiler: simplify bfm / s_bfm_b64 and lower ffbh_i to FirstbitSHi in direct DXIL - #2559
ramon-victor wants to merge 1 commit into
Conversation
|
Wave64 run (listed as untested; the wave64 GPU tests skipped on the RTX 3070) on an AMD RX 9070 XT, plus an RTX 3060: the new test passes, and nothing else changes in the direct-DXIL GPU suite. Head
On both cards, the only result change against Not tested: Intel, a title. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! — Devin |
|
Tested: current PR head merged onto current
Not tested: retail titles (no title data on this lane, counts only). AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting. |
Integrates upstream amd-dev 9f02a3b (BVH null/OOB guard), b67375b (scratch SADDR 0x7F), 4ae5668/xcl-dev#2565 (32-bit VALU add/sub carry without i64), plus open PRs xcl-dev#2559 (bfm/ffbh_i), xcl-dev#2557 (known_nonzero_bits folding), xcl-dev#2552 (f16-to-f32 fold), xcl-dev#2568 (integer min/max range opt), and xcl-dev#2580 (empty DXC blob null slice). Assisted-by: Antigravity (Gemini 4 Neon)
Build bitfield masks with wrapping shift/subtract identities, fold constant 64-bit scalar masks into i32 halves, and lower signed find-first-bit-high directly to FirstbitSHi. This removes branches, selects, and avoidable Int64Ops. Adapted from xcl-dev#2559. Upstream reports 573/573 DXIL validation and GPU parity across NVIDIA and AMD. Locally cross-checked only with the GNU Windows target; Windows GPU execution remains untested here. Part of xcl-dev#2508 Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Build bitfield masks with wrapping shift/subtract identities, fold constant 64-bit scalar masks into i32 halves, and lower signed find-first-bit-high directly to FirstbitSHi. This removes branches, selects, and avoidable Int64Ops. Adapted from xcl-dev#2559. Upstream reports 573/573 DXIL validation and GPU parity across NVIDIA and AMD. Locally cross-checked only with the GNU Windows target; Windows GPU execution remains untested here. Part of xcl-dev#2508 Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Part of #1269.
Problem
In
crates/xcl/src/gpu/dxil/lower.rs, bitfield mask and signed find-first-bit-high helpers emitted unnecessarily heavy DXIL sequences:bfm(s_bfm_b32,v_bfm_b32) computedselect(w == 0, 0, u32::MAX >> ((32 - w) & 31)) << (b & 31)(8 instructions includingicmpandselect), even thoughw = a & 31is already strictly in0..=31, so((1u32 << w) - 1) << (b & 31)is exact for everywincludingw = 0.s_bfm_b64used the same 12-instructionicmp/select/lshri64expansion even when both operands are compile-time constants, forcingi64arithmetic andFeature::Int64Opsfor constant lane masks.ffbh_i(v_ffbh_i32,s_flbit_i32) manually emulated signed find-first-bit-high withicmp slt 0, bitwise NOT,select, andFirstbitHi(4 instructions), instead of lowering directly to DXIL'sBitCount::FirstbitSHi(dx.op.unaryBits.i32op34).Fix
bfm(lower.rs) to((1 << (a & 31)) - 1) << (b & 31)with direct constant folding whena(or bothaandb) is constant.s_bfm_b64(lower.rs) directly to twoi32constants without touchingi64orFeature::Int64Ops; for dynamic operands, simplify to((1u64 << (al & 63)) - 1) << (bl & 63)with noicmp/select.ffbh_i(lower.rs) directly toself.s.bit_count(BitCount::FirstbitSHi, v).lower::bfm_ffbh_tests::bfm_and_ffbh_i_ir_and_gpu_paritychecking DXIL validation, disassembly (zeroInt64Opsfor constants_bfm_b64,FirstbitSHiop34withouticmp sltforv_ffbh_i32/s_flbit_i32, zeroselectfor dynamicbfm), and wave32 RTX 3070 GPU parity across all edge cases (0,-1,1,-2,0x7FFF_FFFF,0x8000_0000, widths0/1/16/31/32/63/64, offsets0..63).Measured impact
573-program retail direct-DXIL validation sweep (
dxil.dll1.8.2502.11):6d12f58):573/573validated (val_fail=0),51,117,488total DXIL bytes (p50=22,865 us,p95=408,132 us).7bf4853):573/573validated (val_fail=0),51,116,080total DXIL bytes (-1,408 B/-0.003%;p50=19,313 us,p95=376,258 us).Tested
cargo test --lib -p xcl bfm_ffbh): 1 passed, 0 failed..\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11):1424 passed, 0 failed, 46 ignored.dxil.dllvalidation sweep:573/573passed,0failures.cargo build --release -p xcl) and 60 s retail smoke run (see below).Not tested
Regression run
Main (
f087b99):This PR (
7bf4853):AI use