Recompiler: v_frexp_mant_f32 drops the sign of negative inputs #580
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#580
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@joeypercia on GitHub · 2026-11-24 02:02 UTC · original
v_frexp_mant_f32returns the mantissa without its sign: for a negative input the result is positive (−10.125 gives +0.6328125 /0x3f220000, want −0.6328125 /0xbf220000), and −0 gives +0. The RDNA2 instruction keeps the sign, as XCL's own f64 path does (frexp_mant_dinemit.rsand the "CPU mirror of the ISA semantics" ingpu_frexp_f64_exp_and_mantboth set it).Cause: the f32 helper in
emit.rs(main508a0c7, line 5467) returns HLSLfrexp()'s mantissa, which is unsigned:v_frexp_mant_f16calls the same helper, so it probably has the same bug (not tested).Fix, one line:
How it was found: a new randomized GPU test,
gpu_f32_math_and_bit_scans_randomingpu/recomp/tests.rs(145 lines, modelled ongpu_f64_math_random). It checks 22 instructions that no test named so far against the CPU:v_floor/ceil/trunc/rndne/fract_f32,v_cvt_i32/flr_i32/rpi_i32_f32,v_frexp_mant/exp_i32_f32bit for bit;v_rcp/sqrt/rsq_f32within 4 ulps;v_exp/log/sin/cos_f32within a tolerance that only catches a wrong formula;v_ffbh_u32,v_ffbl_b32,v_ffbh_i32,v_bfrev_b32,v_bcnt_u32_b32exactly. Onlyfrexp_mantfails; the other 21 match.Measured on
main508a0c7, Windows 11 Pro 26200, Ryzen 7 7800X3D, Rust 1.100.0 MSVC, debug, DXC 1.8.2502.11 (SDK 10.0.26100):mainfrexp_mantfrexp_mantXCL_FUZZ_ITERS=200cargo test --workspace --no-fail-fast -- --test-threads=4, test + fixSKIPPEDWorst errors with the fix: rcp / sqrt / rsq 1 ulp on both; exp / log relative ≤ 1.6e-7; sin / cos absolute ≤ 9.6e-5 (NVIDIA), 1.2e-7 (AMD).
Not tested: a regression run on a title (I have none, which is why this is an issue and not a PR: the fix is a runtime change). Whether a retail title's shader pack uses
v_frexp_mant_f32/_f16with negative inputs.v_frexp_mant_f16. Release build.I can open the test and the fix as a PR if someone with a title can add the
xcl-smokeruns, or hand the test over to whoever picks this up.AI use: Claude Code (Claude Opus 5.5) wrote the test, found the cause, wrote the fix and this issue; every number above is from the runs described.
@requiemsnkrp on GitHub · 2026-11-24 02:04 UTC · original
@joeypercia I have the retail title, so I can make the two regression runs. Unless you'd rather open it yourself, I'll open the PR with your one-line fix in
frexp_mant(crediting you with aCo-authored-bytrailer) and a focused GPU test:v_frexp_mant_f32/_f16on negative inputs and −0, plus the NEG modifier. Your randomizedgpu_f32_math_and_bit_scans_randomshould still go in as its own test PR (it covers 21 more instructions). If you'd prefer to keep it all in one PR, push your branch and I'll post thexcl-smokeblocks there instead.Written with Claude Code (Claude Opus 5.5).
@joeypercia on GitHub · 2026-11-24 02:20 UTC · original · edited 2026-11-24 02:29 UTC
Thanks for opening #587. It matches what I'd want: the fix with the xcl-smoke runs, your focused f32/f16/−0/NEG test, and the Co-authored-by credit.
I'll open gpu_f32_math_and_bit_scans_random as a test-only PR once #587 is merged, since it fails on main without the fix.
Written with Claude Code (Claude Opus 5.5).