Recompiler: v_ldexp_f16 returns NaN for ±0 / ±inf with large exponents #658
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#658
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:57 UTC · original
v_ldexp_f16is emitted as HLSLldexp(x, (float)n), which DXC computes asx * exp2(n). For |n| beyond the f32 exponent range,exp2(n)is inf or 0, so ±0 with a large positive n and ±inf with a large negative n give0 · inf= NaN; the ISA keeps ±0 / ±inf for any exponent.v_ldexp_f32doesn't have this: it uses the exactldexp_fhelper.Measured on
maincb868b2(RTX 4070 Ti 616.56 wave32; AMD RDNA2 iGPU, 26.11.2, wave64 + wave32), new testgpu_ldexp_f16_zero_inf_and_large_exponents:ldexp(0x0000, 200)0x7fff0xfe000x0000ldexp(0x8000, 300)0x7fff0xfe000x8000ldexp(0x0000, 32767)0x7fff0xfe000x0000ldexp(0x8000, -32768)0x00000x8000ldexp(0x7c00, -200)0x7fff0xfe000x7c00ldexp(0xfc00, -300)0x7fff0xfe000xfc00ldexp(0x7c00, -32768)0x7fff0xfe000x7c00NaN in, overflow to ±inf and underflow to 0 already come out right.
Fix, one line in
emit.rs:"v_ldexp_f16" => fr(format!("ldexp_f({}, {})", fh(0), si(1))). With it the test passes on both GPUs (wave64 and wave32), and the randomv_ldexp_f16results in #111's census still round to nearest even (with that fix applied). Full suite: RTX 4070 Ti 687 passed, 0 failed; RDNA2 686 passed, 1 failed (frame::tests::origin_events_issue_tokens_and_flips_have_statistics, a timing test that failed under load and passes 3/3 alone and onmain).Not tested: a regression run (I have no title); whether a retail title hits these inputs.
I can open a PR with the test and fix if someone with a title can add the
xcl-smokeruns.AI use: Claude Code (Claude Opus 5.5) found the bug, wrote the test, the fix and this issue; the numbers are from the runs described.
github-bot referenced this issue2026-11-26 04:28:59 +00:00
@requiemsnkrp on GitHub · 2026-11-24 03:05 UTC · original
@joeypercia I have the retail title and can make the two
xcl-smokeruns for this, as for #580 (#587). Open the PR with your test and fix. I'll runscripts/smoke.ps1on its head commit and on themainit is based on, and post both blocks in the PR for you to paste into Regression run. Sincepr_check.pyreads them from the description, it is simplest if you paste them. Rerun after every push.Written with Claude Code (Claude Opus 5.5).
@joeypercia on GitHub · 2026-11-24 03:26 UTC · original
Thanks @requiemsnkrp. The PR is #672, and @Anon64 has already posted the two
xcl-smokeruns there (head6ec4036, basedd2ae9a), now in the description, so no need to run them unless the head changes.Written with Claude Code (Claude Opus 5.5).