Recompiler: simplify direct DXIL frexp_mant, frexp_exp, and alignbit helpers #2641
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2641
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2641"
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?
@Decodere on GitHub · 2026-11-26 04:35 UTC · original
Decodere:fix-dxil-prelude-alignbit-frexp→main· +173 −42 · 1 files · 1 commits · openWhat is in it
Part of #2508
Part of #2403
Part of #1833
Direct-DXIL
frexp_mant,frexp_exp, andalignbit(crates/xcl/src/gpu/dxil/prelude.rs) previously emitted redundant intrinsics, int/float round-trips, and compare/select workarounds on everyV_FREXP_MANT_F32,V_FREXP_EXP_I32_F32,V_FREXP_MANT_F16,V_FREXP_EXP_I16_F16,V_ALIGNBIT_B32, andV_ALIGNBYTE_B32instruction:frexp_exprouted through privatefrexp_dxc, converting integeretofloat(sitofp) and back toi32(fptosi), while bothfrexp_mantandfrexp_expemitted two@dx.op.isSpecialFloatcalls (IsInf+IsNaN) even thoughe_raw = bits(x) & 0x7F80_0000is already extracted.alignbitemittedand 31,lshr,sub 32, s,and 31,shl,or,icmp eq s, 0, andselectfor both dynamic and constant shift counts.Scoped solely to
crates/xcl/src/gpu/dxil/prelude.rs(+173/-42lines; net-7production lines +144test lines):frexp_dxcand loweredfrexp_mantandfrexp_expdirectly fromi = bits(x)ande_raw = i & 0x7F80_0000:zero = (e_raw == 0)andspecial = (e_raw == 0x7F80_0000)instead of@dx.op.isSpecialFloat,sitofp/fptosi, orfcmp oeq float x, 0.0. Checkinge_raw == 0in integer bits eliminates driver-dependent FTZ vs denorm-preserve divergence onfcmp(fixing@DarkPanda69's RTX 3060 Ampere report wherefcmp oeq 0x0000_0001, 0.0did not flush subnormals and produced0x3F00_0001instead of0), while keeping exact behavior for F32 (±0.0, FTZ subnormals, normals,±Inf,±sNaN/±qNaNpreserving sign and payload) and F16 (whose subnormals widen to normal F32 values inf16_to_f32).alignbit(s0, s1, s):s: maskssh = (k as u32) & 31, returnings1directly whensh == 0(0ops) or(s1 >> sh) | (s0 << (32 - sh))(3ops).s:sh = s & 31,((s0 << 1) << (sh ^ 31)) | (s1 >> sh)(6ops, zerosub 32, zeroicmp, zeroselect, every shift count strictly in0..=31).prelude.rs:gpu_direct_frexp_avoids_special_float_and_int_float_roundtrip(F32V_FREXP_MANT_F32+V_FREXP_EXP_I32_F32: asserts zero@dx.op.isSpecialFloat,sitofp,fptosi, andfcmp oeq; checks all 12 IEEE-754 edge cases on GPU).gpu_direct_frexp_f16_avoids_special_float_and_matches_isa(addressing@luckyteagirl's F16 coverage review: translatesV_FREXP_MANT_F16+V_FREXP_EXP_I16_F16, asserts zero@dx.op.isSpecialFloat,sitofp,fptosi, andfcmp oeq, and verifies 11 F16 cases including±0.0, F16 subnormals, negative normals,±Inf, and±qNaNon GPU).gpu_direct_alignbit_is_select_free_and_matches_isa(useswrapping_mulin lane setup to fix the debug-buildu32overflow panic reported by@luckyteagirland@DarkPanda69).Tested
rustc 1.100.0, DXC1.9.2609.5 (01b62ad4).b49be183: F32 frexp disassembly contained@dx.op.isSpecialFloat,sitofp, andfptosi; alignbit disassembly containedsub i32 32,,3icmp eq, and9select i1. On previous PR head84ae02e8, debug builds panicked onprelude.rs:998overflow and Ampere did not FTZfcmp oeq.XCL_ADAPTER=warp,XCL_WARP=1, release):cargo test --release -p xcl --lib -- gpu::dxil::prelude:: --nocapture->10 passed; 0 failed; 0 ignored(0.03 s; DXC 1.9 validate & disassembly assertions ran and passed on F32 frexp, F16 frexp, and alignbit; wave32 GPU sections skipped cleanly on WARP).cargo test --release -p xcl --lib -- gpu::dxil::prelude:: --nocapture->10 passed; 0 failed; 0 ignored(0skipped,0.42 s).cargo test --release -p xcl --lib -- gpu_frexp --nocapture->8 passed; 0 failed; 0 ignored(0skipped,0.44 s).cargo test -p xcl --lib -- gpu::dxil::prelude:: --nocapture->10 passed; 0 failed; 0 ignored(0skipped,0.39 s— directly verifying the debugwrapping_mulfix and F16 direct-DXIL GPU execution).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37binaries,1438passed,0failed,47ignored (0new warnings),29pre-existing host-gatedSKIPPEDlines (none inprelude::):21wave64-only GPU tests (no wave64on RTX 4060 32-lane waves)3per-lane wave32 shader tests (refused)3D3D12 debug layer tests (no d3d12SDKLayers.dll/ debug layer unavailable)1heap-window OOM fallback test (no heap windows)1PSO driver-cache measurement test (cannot disable the driver cache)Regression run
Paired 60 s retail smoke (
scripts/smoke.ps1, RTX 4060): both base (889ef3e8, ancestor ofb49be183andc9751948) and HEAD sustained60 60 60presents per 2 s with0device removals and0crashes (1549vs1550total frames,14018 MBvs13981 MBpeak commit).Base (
origin/mainancestor):HEAD (
fix-dxil-prelude-alignbit-frexp):Not tested
fcmp oeqwith integere_raw == 0removes the driver FTZ dependency that caused the Ampere mismatch).AI use
Google Antigravity (Gemini 4 Neon) authored the direct-DXIL
frexp_mant,frexp_exp, andalignbitsimplifications, integere_raw == 0Ampere FTZ fix, direct F16 frexp test, debugwrapping_mulfix, and verification runs; verified via DXC 1.9 validation/disassembly, RTX 4060 release & debug tests, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.@luckyteagirl on GitHub · 2026-11-26 04:48 UTC · original
RX 6800M focused debug run on exact PR head
84ae02e80496d01d01bdf28b1544f4e9890f312e(Windows 11 Home build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver30.0.13002.13003, Rust 1.99.0 MSVC, DXC 1.9.2609.5):With
XCL_ADAPTER=6800M,XCL_REQUIRE_GPU=wave32,XCL_DIRECT_DXIL=1, pinnedXCL_DXC_DIR, and--exact --test-threads=1 --show-output:cargo test --locked -p xcl --lib gpu::dxil::prelude::fclass_const_tests::gpu_direct_frexp_avoids_special_float_and_int_float_roundtrip -- --exact --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED (1337 filtered out).cargo test --locked -p xcl --lib gpu::dxil::prelude::fclass_const_tests::gpu_direct_alignbit_is_select_free_and_matches_isa -- --exact --test-threads=1 --show-output: 0 passed, 1 failed, 0 ignored, 0 SKIPPED (1337 filtered out). It panicked atprelude.rs:998:64withattempt to multiply with overflowwhile setting up lane inputs. Thelane as u32 * 0x1020_3040expression overflows starting at lane 16 in debug; the test never reached its GPUrunner::runcalls.wrapping_mulwould let the intended wrapping input pattern run in debug.Both isolated guarded runs completed without a memory-guard stop. The fixture output does not print adapter identity, so this report identifies the requested selector and required-GPU mode, not an independent GPU name from the test. The passing frexp fixture does reach GPU execution; alignbit GPU behavior remains untested here. No full suite or retail-title comparison was run on this head.
AI use: OpenAI Codex (GPT-6; exact serving variant unavailable) with a Luna subagent prepared and ran these tests. I checked the exact head and logs before posting.
@Decodere on GitHub · 2026-11-26 05:29 UTC · original
Thanks
@DarkPanda69and@luckyteagirlfor the thorough testing and review! Pushedc9751948fixing all three findings:0x3F00_0001vs0):frexp_mantandfrexp_expwere usingfcmp oeq float x, 0.0, which did not flush subnormals to zero on RTX 3060 (Ampere). Switched both to pure integere_raw == 0((bits(x) & 0x7F80_0000) == 0), removingfcmp oeqcompletely (now asserted in the disassembly tests) so±0.0and F32 FTZ subnormals deterministically return(±0.0, 0)across all GPUs/drivers while F16 subnormals (which widen to normal F32 viaf16_to_f32) keep their exact normalized mantissas and exponents.gpu_direct_alignbit_is_select_free_and_matches_isa: Fixed both lane setup multipliers to use.wrapping_mul(...)and verifiedcargo test -p xcl --lib -- gpu::dxil::prelude::in debug builds on RTX 4060 (10/10passed,0skipped).gpu_direct_frexp_f16_avoids_special_float_and_matches_isacoveringV_FREXP_MANT_F16andV_FREXP_EXP_I16_F16(DXC validate/disassembly + wave32 GPU checks on±0.0, F16 subnormals, negative normals,±Inf, and±qNaN).If you have a chance to re-check on RTX 3060 / RX 6800M / RX 9070 XT, would really appreciate confirmation!
@DarkPanda69 on GitHub · 2026-11-26 05:07 UTC · original · edited 2026-11-26 05:54 UTC
Update for head
c975194: both findings are fixed on our cards. Onmainb49be18, same cards:cargo test -p xcl --lib -- gpu::dxil::prelude:: --nocapture: 10 passed, 0 failed, no SKIPPED, in debug and in release, on both the RX 9070 XT and the RTX 3060. That includesgpu_direct_frexp_avoids_special_float_and_int_float_roundtripon the RTX 3060 (Ampere), the newgpu_direct_frexp_f16_avoids_special_float_and_matches_isa, andgpu_direct_alignbit_is_select_free_and_matches_isain debug.XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, paired againstmain: the only result changes are those 3 tests, all ok, with no new skips. RX 9070 XT 708 → 711 passed, 2 failed (#2115, the same onmain). RTX 3060 710 → 713 passed, 0 failed.The original report follows.
Two failures of the new tests on our cards, one in the test code and one on Ampere:
1.
gpu_direct_alignbit_is_select_free_and_matches_isapanics in debug builds, on any GPU.prelude.rs:998,0x1234_5678u32.wrapping_add(lane as u32 * 0x1020_3040): the multiplication overflowsu32from lane 16 on, and debug builds check overflow. On both cards, in debug:In release it passes on both.
(lane as u32).wrapping_mul(0x1020_3040)would keep the same values. The description's runs are release; the whole-suite runs CONTRIBUTING.md asks for are debug.2.
gpu_direct_frexp_avoids_special_float_and_int_float_roundtripfails on an RTX 3060 (Ampere), in debug and in release:That is
0x3F000001for the smallest positive denormal where the test expects0. The same test passes on the RX 9070 XT, and per the description on the RTX 4060.main's existing frexp tests all pass on this RTX 3060, so it looks like the newfrexp_mantlowering behaves differently on Ampere. I did not look into why.Head
84ae02eapplied onmainb49be18, Windows 11 Pro 26200, card chosen withXCL_ADAPTER; RX 9070 XT (RDNA4, 32.0.32029.2010), RTX 3060 (32.0.16.1088):cargo test --release -p xcl --lib -- gpu::dxil::prelude::: RX 9070 XT 9 passed, 0 failed; RTX 3060 8 passed, 1 failed (frexp).XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR: no other result changes on either card. RX 9070 XT 708 → 709 passed, 2 → 3 failed (alignbit, plus the #2115 fuzz seeds, the same onmain). RTX 3060 710 → 710 passed, 0 → 2 failed (alignbit, frexp). The two new-test failures are the same withXCL_DIRECT_DXILunset.Not tested: Turing / Ada beyond your RTX 4060, Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine, found the overflow line and wrote this report.
@luckyteagirl on GitHub · 2026-11-26 04:41 UTC · original · reviewed
The new
gpu_direct_frexp_avoids_special_float_and_int_float_roundtripfixture encodes onlyV_FREXP_MANT_F32andV_FREXP_EXP_I32_F32, butlower_wide.rsalso routesV_FREXP_MANT_F16andV_FREXP_EXP_I16_F16through the changedLw::frexp_mant/frexp_exphelpers. The existinggpu_frexp_mant_f32_f16_keep_the_signfixture uses the legacy HLSL runner, so it does not check the direct F16 lowering. Could this PR add a focused direct F16 translation/validation and wave32 GPU result check (for signed zero, a negative normal, and special values), or state that path as untested? This is a coverage suggestion from source review; I have not run a new F16 direct test.@zhouzhidong3-hash on GitHub · 2026-11-26 06:24 UTC · original
RTX 5070 (Blackwell) focused confirmation on exact head
c9751948934e884624212c4edbf5d774af149bc7, from the official GitHub commit archive, with no source edits.Tested
Windows 10 Pro 19045, i7-12700KF, NVIDIA GeForce RTX 5070 / driver 591.86, Rust 1.100.0 MSVC debug test build. Explicit
XCL_ADAPTER=5070,XCL_DIRECT_DXIL=all; local D3D12 Agility SDK and DXC/DXIL 1.8.2502.11.The first group includes successful DXC validation/disassembly and wave32 GPU assertions for all three new fixtures:
gpu_direct_frexp_avoids_special_float_and_int_float_roundtrip,gpu_direct_frexp_f16_avoids_special_float_and_matches_isa, andgpu_direct_alignbit_is_select_free_and_matches_isa. The prelude group also contains CPU/translation-only tests; 10 passes should not be read as 10 GPU dispatch tests. The frexp group includes the existing sign and directed-rounding/denormal-mode checks. These results confirm the fixtures' expected outputs on this Blackwell configuration, not an independent native-RDNA ISA reference.The changed
prelude.rsGit blob matches the GitHub files API (33369da2d25577ec0b685e3933bdb30be081a3e4). All 210 Rust source files retained their original SHA256 hashes. Archive SHA256:4d54b6406e75188bb83b5f5ec84e3e522c5192a40109bd841e88d5921b7a3a8a.Not tested
Parent control, full workspace, release-host build, native wave64, other adapters/drivers, retail/gameplay or performance. No FPS claim or approval of unrelated behavior.
AI use
OpenAI Codex (GPT-6; exact serving variant unavailable) fetched and checked the archive/API blob, ran the existing focused fixtures, inspected output/skip markers and source integrity, and prepared this test report. No implementation changes.
@DarkPanda69 on GitHub · 2026-11-26 08:16 UTC · original
@Decodere re-checked
c975194on the RTX 3060 (Ampere) and the RX 9070 XT, as you asked: all three are fixed.gpu::dxil::prelude::gives 10 passed, 0 failed, no SKIPPED on both cards, in debug and in release. That includes the frexp subnormal case on the RTX 3060, the alignbit test in debug, and the new f16 test. The paired direct-DXILgpu::run shows no other changes. Details are in the update at the top of my comment above.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this comment.
github-bot referenced this pull request2026-11-26 12:40:17 +00:00
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.