Skip to content

Recompiler: v_ldexp_f16 returns NaN for ±0 / ±inf with large exponents #658

Backlog

Description

@joeypercia

v_ldexp_f16 is emitted as HLSL ldexp(x, (float)n), which DXC computes as x * 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 give 0 · inf = NaN; the ISA keeps ±0 / ±inf for any exponent. v_ldexp_f32 doesn't have this: it uses the exact ldexp_f helper.

Measured on main cb868b2 (RTX 4070 Ti 616.56 wave32; AMD RDNA2 iGPU, 26.11.2, wave64 + wave32), new test gpu_ldexp_f16_zero_inf_and_large_exponents:

input RTX 4070 Ti RDNA2 ISA
ldexp(0x0000, 200) 0x7fff 0xfe00 0x0000
ldexp(0x8000, 300) 0x7fff 0xfe00 0x8000
ldexp(0x0000, 32767) 0x7fff 0xfe00 0x0000
ldexp(0x8000, -32768) ok 0x0000 0x8000
ldexp(0x7c00, -200) 0x7fff 0xfe00 0x7c00
ldexp(0xfc00, -300) 0x7fff 0xfe00 0xfc00
ldexp(0x7c00, -32768) 0x7fff 0xfe00 0x7c00

NaN 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 random v_ldexp_f16 results 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 on main).

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-smoke runs.

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.

Activity

  1. requiemsnkrp commented on Nov 24, 2026

    @requiemsnkrp
    Contributor

    @joeypercia I have the retail title and can make the two xcl-smoke runs for this, as for #580 (#587). Open the PR with your test and fix. I'll run scripts/smoke.ps1 on its head commit and on the main it is based on, and post both blocks in the PR for you to paste into Regression run. Since pr_check.py reads them from the description, it is simplest if you paste them. Rerun after every push.

    Written with Claude Code (Claude Opus 5.5).

  2. joeypercia commented on Nov 24, 2026

    @joeypercia
    ContributorAuthor

    Thanks @requiemsnkrp. The PR is #672, and @Anon64 has already posted the two xcl-smoke runs there (head 6ec4036, base dd2ae9a), now in the description, so no need to run them unless the head changes.

    Written with Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions