Skip to content

Recompiler: v_ldexp_f16 keeps ±0 and ±inf for any exponent (#658) - #672

Open
joeypercia wants to merge 2 commits into
xcl-dev:mainfrom
joeypercia:recompiler-ldexp-f16
Open

joeypercia wants to merge 2 commits into
xcl-dev:mainfrom
joeypercia:recompiler-ldexp-f16

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 24, 2026 •

Copy link
Copy Markdown

v_ldexp_f16 was 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 gave 0 · inf = NaN; the ISA keeps ±0 and ±inf. It now uses the exact ldexp_f helper that v_ldexp_f32 already uses. The direct DXIL backend (#1426) had the same x * exp2(n) lowering and gets the same fix in a second commit. Fixes #658.

On AMD this is also what #1227's gpu_f16_rounding_and_frexp_ldexp needs: its v_ldexp_f16(-0) case gives +0 on main on RDNA2 and RDNA4 (Toons29's run there), and passes with this PR merged (RDNA2 iGPU; NVIDIA passes either way).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: v_ldexp_f16 goes through ldexp_f
  • crates/xcl/src/gpu/dxil/lower_wide.rs: the direct backend's v_ldexp_f16 goes through its ldexp_f helper too, like its v_ldexp_f32
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_ldexp_f16_zero_inf_and_large_exponents, 11 cases: ±0 and ±inf with exponents up to ±32767, NaN, underflow to 0, a subnormal scaled to a normal, an exact scaling

Tested

  • NVIDIA GeForce RTX 4070 Ti (Ada, 32-lane waves), driver 616.56; AMD Radeon iGPU (Ryzen 7 7800X3D, RDNA2, 32–64 lanes, no mesh shaders), driver 26.11.2; Windows 11 Pro 26200; Rust 1.100.0 MSVC; DXC 1.8.2502.11 (SDK 10.0.26100); debug
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 32bcaef (rebased on main 3da2abb): RTX 4070 Ti 1112 passed, 0 failed, 46 ignored; RDNA2 1111 passed, 1 failed, 46 ignored. The failure is fuzz_validate_and_gpu_1 (seed 540, res[833] = 0x7, CPU 0x6), which fails the same way on main on this iGPU
  • SKIPPED: RTX 4070 Ti: the wave64 cases of lower / lower_dxil GPU tests, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows); RDNA2: the mesh-shader tests (no mesh shaders); both: pso_measurement_compiles_an_exact_synthetic_record (needs Developer Mode) and the lower_dxil f16 / conversion cases the direct backend refuses
  • direct DXIL: XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_ldexp_f16: passes on both GPUs; with lower_wide.rs back to main it fails 6 of 11 cases (0x7fff for ±0 / ±inf with large exponents)
  • negative control: with only emit.rs back to main, the new test fails on 6 of 11 cases on the RTX 4070 Ti (NaN 0x7fff) and 7 of 11 on RDNA2 (NaN 0xfe00, and ldexp(-0, -32768) gives +0)
  • native RDNA2 reference by @luckyteagirl (RX 6800M, gfx1031, raw v_ldexp_f16 on the hardware): ±0 and ±inf come back unchanged for exponents up to ±32767, as this PR does

Regression run

RTX 4070 Ti (driver 616.56), release builds, 60 s each, scripts/smoke.ps1 -Title retail-title on the newer retail title, main aa9ab8a and this PR's head 32bcaef (no uncommitted changes). (@Anon64's earlier runs, on an RTX 3060 for the previous head 6ec4036, were equally clean.)

main:

xcl-smoke v1
commit: aa9ab8a3e7b738ec48899e37805f6a7d2d22da53
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1613)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16044 MB

PR:

xcl-smoke v1
commit: 32bcaef6fca398125b5abcacaeb3aadcc8418e08
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1589 (PresentX 1589)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15848 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the bug, wrote the fix, the test and this description, and ran the tests above on my machine.

@zhouzhidong3-hash

zhouzhidong3-hash commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent Release-mode result for the unmodified PR head 6ec4036. On an RTX 5070 with Windows 10, Rust 1.100.0 MSVC, DXC 1.8.2502.11 and the D3D12 Agility SDK, the focused GPU test passed all 11 synthetic cases.

Command: cargo test --locked --release -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents -- --nocapture. Adapter selection: XCL_ADAPTER=5070. The optimized build ran one test, 0 failed, 0 ignored, 671 filtered out; no runtime skip appeared. Scope: this PR-head test only. No parent control, full Release suite, wave64 or retail smoke on this machine for this report.

AI assistance: OpenAI Codex prepared and ran the test and summarized the log.

Follow-up baseline for the planned narrowing fix. I ran the 11 input/exponent pairs from the native RX 6800M report through the same Release wave32 fixture at 6ec4036 on the RTX 5070, changing the case table and logging each low halfword. Eight results matched bit-for-bit. All three mismatches are listed below (hexadecimal binary16 bits).

Input Signed exponent RTX 5070 via XCL Native RDNA2
3c00 20 7bff 7c00
bc00 20 fbff fc00
0003 -1 0001 0002

The original PR test passed; this expanded comparison fails on the already scoped-out finite overflow and subnormal rounding cases. Only the default-mode fixture was exercised. This baseline can be reused when the unary narrowing change lands.

Full Release workspace follow-up on 6ec4036 using a fresh target directory: cargo build --locked --release --workspace followed by cargo test --locked --release --workspace --no-fail-fast -- --test-threads=4 --nocapture. Both exited 0. Aggregate harness counts: 691 passed, 0 failed, 41 ignored. Four explicit runtime skips counted among passes: two wave64 checks and two D3D12 debug-layer checks. Optional retail sample variables were unset. The separately instrumented native-comparison probe was absent from this run.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression runs for this PR's head 6ec4036 and for its base main dd2ae9a, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 and pasted unedited. Feel free to copy both blocks into Regression run.

main:

xcl-smoke v1
commit: dd2ae9a70af5eb5aad60f02d86e386b72abe1e95
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1647 (PresentX 1647)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14680 MB

this PR:

xcl-smoke v1
commit: 6ec4036d1208eee1b496d7c47c4df57c8d3614b3
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14675 MB

Tested

  • NVIDIA GeForce RTX 3060 (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0
  • cargo build --release -p xcl for both smoke runs, clean tree at each commit
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on 6ec4036: 690 passed, 1 failed, 41 ignored. gpu_ldexp_f16_zero_inf_and_large_exponents passes. The one failure is hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, which fails the same way on main dd2ae9a on this machine (Tests: align XMemVirtualQuery buffers and verify CPU flags #650 / Tests: align the XMemVirtualQuery output buffer #656).
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • whether the title reaches v_ldexp_f16 with these inputs; this is a regression check only
  • wave64 / AMD

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 6ec4036d1208eee1b496d7c47c4df57c8d3614b3 on AMD RDNA4. I merged it onto current main 91f9a5e locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 693 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 653 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_ldexp_f16_zero_inf_and_large_exponents passes.

Review: Using the exact ldexp_f helper that v_ldexp_f32 already uses keeps ±0 and ±inf for any exponent, instead of x * exp2(n) giving 0·inf = NaN. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@towiice towiice left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested:

  • Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), DXC v1.9.2609 (01b62ad4), toolchain stable-x86_64-pc-windows-gnullvm (llvm-mingw 23.1.6).
  • Test command: cargo test -p xcl --lib ldexp -- --nocapture
  • Result: 3 passed, 0 failed (0.58 s):
    • gpu_ldexp_f16_zero_inf_and_large_exponents (verifies ±0 and ±inf preserved across extreme exponents)
    • gpu_ldexp_f32
    • gpu_ldexp_f64
      All ldexp tests pass on Turing hardware without regressions.

@lordon1a

Copy link
Copy Markdown

Independent test report on 6ec4036:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build, DXC 1.9.2609.5 (01b62ad4)
  • Command: cargo test -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents -- --nocapture
  • Result: 1 passed, 0 failed, 0 ignored in 0.63s (gpu_ldexp_f16_zero_inf_and_large_exponents ok)

Not tested

  • AMD / wave64, Intel GPU, retail title

AI use

  • Antigravity (Google DeepMind agent) — fetched 6ec4036 in a detached worktree, audited the diff, ran the test, and posted this report.

@eizispark

Copy link
Copy Markdown

Hardware check of 6ec4036d1208eee1b496d7c47c4df57c8d3614b3 (verified clean merge with main f4ce27c): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 691 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none — native wave64 and mesh shader tests included)
  • cargo test -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents: 1 passed, 0 failed

Regression run
main (f4ce27c):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14847 MB

PR (6ec4036):

xcl-smoke v1
commit: 6ec4036d1208eee1b496d7c47c4df57c8d3614b3
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1666 (PresentX 1666)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14849 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The ±0 / ±inf fix looks right. One remaining issue on 6ec4036, from reading the code (not run): the result still goes through fr → to_f16_expr, which in the default mode is f32tof16 (emit.rs:450), and #696 measured that as rounding toward zero. ldexp_f is exact in binary32 for a binary16 input, so only that last narrowing rounds, and it rounds the wrong way when the result overflows or lands in the binary16 denormal range:

  • ldexp_f16(0x7BFF, 1): 131008 should be +inf (0x7C00); toward zero gives 65504 (0x7BFF).
  • ldexp_f16(0x3C03, -15): 2^-15 · (1 + 3·2^-10) = 513.5 denormal steps should round to even, 514 (0x0202); toward zero gives 513 (0x0201).

The test's (0x0001, 10) and (0x3C00, -30) cases are exact or flush to 0, so they don't exercise this. Adding "v_ldexp_f16" to the to_f16_rounded_expr branch, as #696 does for add / sub (one rounding of an exact binary32 value, so no double-rounding question), would cover both, and the two cases above could go into the test.

AI-assisted (Claude Code), read-only review.

@joeypercia

Copy link
Copy Markdown
Author

Thanks @upipibi, both cases are right (513.5 denormal steps → 514 under nearest-even; 131008 → inf). I left that out on purpose: it's the default-mode narrowing from #111 / #685, not the 0·inf NaN, and the Not tested section notes the overflow case for that reason. #696 changes the same matches! line in valu16, so adding v_ldexp_f16 here would conflict with it.

Once #696 is in, I'll do the follow-up for the remaining f16 results that still narrow toward zero (v_ldexp_f16, v_sqrt_f16, v_rcp_f16, v_rsq_f16, v_exp_f16, v_log_f16, with v_fract_f16's clamp kept below 1.0, see #655), and your two cases will go into its test.

Written with Claude Code (Claude Opus 5.5).

@luckyteagirl

Copy link
Copy Markdown

Native RDNA2 reference for #658

I measured v_ldexp_f16 directly on a Radeon RX 6800M (gfx1031), Windows 11 build 26200, display driver 30.0.13002.13003, and AMD OpenCL 3302.6 (PAL,LC). The inline ISA probe checked the raw input bits and got the same output from four work-items per case. The wave's default HW_REG_MODE read back as 0x000003F0.

f16 input bits Signed exponent Native output bits
0x0000 (+0) 32767 0x0000
0x8000 (−0) −32768 0x8000
0x7C00 (+Inf) / 0xFC00 (−Inf) −32768 Unchanged
0x3C00 (+1) / 0xBC00 (−1) 20 0x7C00 / 0xFC00
0xBC00 (−1) −32768 0x8000
0x0400 (minimum normal) −1 0x0200
0x0001 / 0x0003 (subnormal ties) −1 0x0000 / 0x0002
0x8001 (negative subnormal tie) −1 0x8000

The signed zeros and infinities agree with the cases addressed by this PR. The native finite-overflow and subnormal-tie results give reference values for the rounding cases discussed under #111.

Not tested

The PR's HLSL on this adapter, alternate hardware rounding modes, and retail titles.

AI use

OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report.

@SlopTart

Copy link
Copy Markdown

2|
3|Release-build full-suite datapoint — the axis your row lists as not tested.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross x86_64-pc-windows-gnu, release profile, XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.
6|
7|Merged state: head 6ec4036d1 onto main beaa245, clean merge.
8|
9|Full suite, cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 10 failed, 41 ignored (17 suites). Of the 10: 7 are this rig's stable Wine-lane failures (my #42 row) and 3 were the known #718 flaky trio (placed_title_textures_share_vram_and_preserve_pixels + the two poisoned-lock deaths) — that trio hits ~2 of 5 threads=4 runs on this rig regardless of PRs, nothing to do with yours. Your tests pass: gpu_ldexp_f16_zero_inf_and_large_exponents, gpu_ldexp_f32, gpu_ldexp_f64.
10|
11|Not tested: retail titles (none here), Windows, the overflow-to-inf case you deliberately left out (#111).
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
…l-dev#111)

In the default mode every f16 result that is narrowed from binary32 went
through HLSL f32tof16, which rounds toward zero: on an RTX 4070 Ti and an
RDNA2 iGPU every inexact v_add/sub/sqrt/rcp/rsq/exp/log/ldexp_f16 result
came out one binary16 step low, and an overflow stopped at 65504 instead
of inf. Native RDNA2 rounds to nearest even (luckyteagirl's measurements on
xcl-dev#672). to_f16_expr now narrows with f32_to_f16_rm(e, 0u) in the default
mode, the helper the multiplies already use (xcl-dev#166); under a dynamic mode
nothing changes.

v_fract_f16 clamps its binary32 result below 1.0, and 1 - 2^-24 narrows to
1.0 by nearest even, so its binary16 result is kept at 0x3BFF (xcl-dev#655).

Supersedes xcl-dev#696, whose add / sub cases this covers.

Assisted-by: Claude Code (Claude Opus 5.5)
@JJAutoCompare

JJAutoCompare commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent Intel Arc A770 verification of PR #672 for #658. The checked-in regression passed on clean head 6ec4036d1208eee1b496d7c47c4df57c8d3614b3. The PR was open at that head before and after the run.

Tested

  • Intel Arc A770, driver 32.0.101.9175, AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 25H2 build 26200.9974, Rust/Cargo 1.100.0 MSVC x64, unoptimized test profile. D3D12 reported wave sizes 8–32. The fixture ran as wave32.

  • Prebuilt outside the GPU lock with cargo test --locked -p xcl --lib -j 2 --no-run and CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0. Cargo exited 0.

  • Set XCL_ADAPTER=A770, XCL_REQUIRE_GPU=wave64 to make missing GPU or DXC a failure, and XCL_DXC_DIR=%LOCALAPPDATA%\XclTooling\dxc-1.9.2609\bin\x64. The test loaded DXC/DXIL 1.9.2609.5 (DXC 01b62ad4) and used the fixture's HLSL cs_6_6 compiler path. Ran this exact command inside L:/XclTooling/Invoke-ArcTest.ps1:

    & 'L:\XclTooling\pr2011-990b9d4-t3-76a0502d\target\debug\build\xcl\00e28da3621caf64\out\xcl-00e28da3621caf64.exe' gpu::recomp::tests::gpu_ldexp_f16_zero_inf_and_large_exponents --exact --nocapture --test-threads=1
  • 1 passed, 0 failed, 0 ignored, 0 skipped, 671 filtered out, 0.80 s, exit 0. All 11 checked-in assertions passed after GPU readback: four signed-zero cases, three signed-infinity cases (with exponents up to the signed 16-bit endpoints across those seven cases), one NaN classification check, and three finite cases. The finite cases check underflow to +0, scaling the minimum subnormal to the minimum normal, and scaling 1 to 8.

Not tested

  • Native or split wave64, direct DXIL, other adapters, finite overflow, subnormal tie rounding, alternate rounding modes, workspace tests, retail smoke, or a pre-fix baseline.

AI use

  • T3 Code through the Codex harness (gpt-6.2-sol) verified the live revision, ran the checked-in test, and wrote this report.

Follow-up on 32bcaef

The PR was open at 32bcaef before and after testing, and the reused checkout was clean and detached at that exact SHA. This run covered HLSL/DXC and direct DXIL.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation 25H2 build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), unoptimized test profile with debug info disabled. Both fixture stderr logs reported DXC/DXIL 1.9.2609.5 (DXC 01b62ad4).

  • Prebuilt outside the Arc mutex with cargo test --locked -p xcl --lib --no-run (exit 0, 1m 38s). Environment used CARGO_TARGET_DIR=L:/XclTooling/pr2014-1c971de6/target, CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, and CARGO_PROFILE_TEST_DEBUG=0.

  • Ran the exact command below in separate native processes under L:/XclTooling/Invoke-ArcTest.ps1, launched with powershell.exe -NoProfile -ExecutionPolicy RemoteSigned. Set XCL_ADAPTER=A770, XCL_DXC_DIR=$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64, and XCL_REQUIRE_GPU=wave64 to fail on an unavailable GPU or DXC. Each process had a separate TEMP/TMP directory. Mode 1 selects the fixture's direct DXIL path without HLSL fallback.

    & 'L:/XclTooling/pr2014-1c971de6/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe' gpu::recomp::tests::gpu_ldexp_f16_zero_inf_and_large_exponents --exact --nocapture --test-threads=1
XCL_DIRECT_DXIL Backend Passed Failed Ignored Runtime skips Filtered out Fixture time Fixture / wrapper exit
0 HLSL + DXC 1 0 0 0 1088 0.26 s 0 / 0
1 Direct DXIL 1 0 0 0 1088 0.24 s 0 / 0

Both native wave32 runs satisfied all 11 GPU readback assertions. Inputs and results below are binary16 bit patterns, with signed decimal exponents. The NaN check accepts any NaN encoding.

Case Input, exponent → expected result
Signed zero 0x0000, +200 → 0x0000; 0x8000, +300 → 0x8000; 0x0000, +32767 → 0x0000; 0x8000, −32768 → 0x8000
Signed infinity 0x7C00, −200 → 0x7C00; 0xFC00, −300 → 0xFC00; 0x7C00, −32768 → 0x7C00
NaN 0x7E00, +5 → NaN
Finite 0x3C00, −30 → 0x0000 (underflow to +0); 0x0001, +10 → 0x0400 (minimum subnormal to minimum normal); 0x3C00, +3 → 0x4800 (1 to 8)

Not tested

Native or split wave64, other adapters, finite overflow, subnormal ties, alternate rounding modes, release or workspace suites, fuzzing, retail smoke, or a pre-fix baseline.

AI use

T3 Code / Codex (gpt-6.2-sol) verified the revision, ran both fixture invocations, and wrote this report.

v_ldexp_f16 was 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 gave 0 * inf =
NaN (0x7fff on an RTX 4070 Ti, 0xfe00 on an RDNA2 iGPU); the ISA keeps ±0
and ±inf. v_ldexp_f16 now uses the exact ldexp_f helper that v_ldexp_f32
already uses.

Fixes xcl-dev#658

Assisted-by: Claude Code (Claude Opus 5.5)
The direct backend computed x * exp2(n) in f32, so 0 with an exponent that
overflows exp2 gave 0 * inf = NaN, and inf with a very negative one gave
inf * 0 = NaN (both 0x7fff after the f16 conversion). It now uses the exact
ldexp_f helper that v_ldexp_f32 uses, like the HLSL path in the previous
commit. gpu_ldexp_f16_zero_inf_and_large_exponents with XCL_DIRECT_DXIL=1:
6 of 11 cases wrong before, all pass after, on an RTX 4070 Ti and an RDNA2
iGPU.

Assisted-by: Claude Code (Claude Opus 5.5)
@raylitebull

Copy link
Copy Markdown
Member

Diff audit and Windows Build and test passed on 32bcaef (ldexp_f in both emit.rs and dxil/lower_wide.rs, preserving ±0 / ±inf across extreme exponents).

Remaining before merge: update the PR description so Regression run uses a matching xcl-smoke v1 pair for current head 32bcaef (the Regression run block currently references previous head 6ec4036 and title: retail-title), plus an independent NVIDIA check on 32bcaef (AMD RDNA2 + RTX 4070 Ti are from the PR author).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

NVIDIA check at 32bcaef, as asked: RTX 3070 (Ampere, 32-lane waves, driver 616.56), Windows 11, debug.

The two rounding cases from my earlier comment, measured by adding them to the test locally (not pushed), give the same results on both backends:

  • ldexp_f16(0x3C03, -15) = 0x0201, round-to-nearest-even gives 0x0202.
  • ldexp_f16(0x7BFF, 1) = 0x7BFF, round-to-nearest-even gives 0x7C00.

The test leaves overflow to #111. The denormal case comes from the same rounding of the narrowing, so it fits there too. Neither blocks this PR.

AI-assisted (Claude Code). Synthetic tests only.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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