Repository navigation
Recompiler: v_ldexp_f16 keeps ±0 and ±inf for any exponent (#658) - #672
joeypercia wants to merge 2 commits into
Conversation
|
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: 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).
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. |
|
Regression runs for this PR's head main: this PR: Tested
Not tested
Report written with Claude Code (Claude Opus 5.5) from runs on this machine. |
|
Test run of Tested
Review: Using the exact Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
towiice
left a comment
There was a problem hiding this comment.
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), toolchainstable-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_f32gpu_ldexp_f64
All ldexp tests pass on Turing hardware without regressions.
|
Independent test report on Tested
Not tested
AI use
|
|
Hardware check of Tested
Regression run PR ( Not tested
AI use
|
|
The ±0 / ±inf fix looks right. One remaining issue on
The test's AI-assisted (Claude Code), read-only review. |
|
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 Once #696 is in, I'll do the follow-up for the remaining f16 results that still narrow toward zero ( Written with Claude Code (Claude Opus 5.5). |
|
Native RDNA2 reference for #658 I measured
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. |
|
2| |
…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)
|
Independent Intel Arc A770 verification of PR #672 for #658. The checked-in regression passed on clean head Tested
Not tested
AI use
|
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)
6ec4036 to
32bcaef
Compare
|
Diff audit and Windows Remaining before merge: update the |
|
NVIDIA check at
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:
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. |
v_ldexp_f16was emitted as HLSLldexp(x, (float)n), which DXC computes asx * exp2(n). For |n| beyond the f32 exponent rangeexp2(n)is inf or 0, so ±0 with a large positive n and ±inf with a large negative n gave0 · inf= NaN; the ISA keeps ±0 and ±inf. It now uses the exactldexp_fhelper thatv_ldexp_f32already uses. The direct DXIL backend (#1426) had the samex * 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_ldexpneeds: itsv_ldexp_f16(-0)case gives+0onmainon 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_f16goes throughldexp_fcrates/xcl/src/gpu/dxil/lower_wide.rs: the direct backend'sv_ldexp_f16goes through itsldexp_fhelper too, like itsv_ldexp_f32crates/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 scalingTested
cargo test --workspace --no-fail-fast -- --test-threads=4on 32bcaef (rebased on main 3da2abb): RTX 4070 Ti 1112 passed, 0 failed, 46 ignored; RDNA2 1111 passed, 1 failed, 46 ignored. The failure isfuzz_validate_and_gpu_1(seed 540,res[833] = 0x7, CPU0x6), which fails the same way onmainon this iGPUSKIPPED: RTX 4070 Ti: the wave64 cases oflower/lower_dxilGPU 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 thelower_dxilf16 / conversion cases the direct backend refusesXCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_ldexp_f16: passes on both GPUs; withlower_wide.rsback tomainit fails 6 of 11 cases (0x7ffffor ±0 / ±inf with large exponents)emit.rsback tomain, the new test fails on 6 of 11 cases on the RTX 4070 Ti (NaN0x7fff) and 7 of 11 on RDNA2 (NaN0xfe00, andldexp(-0, -32768)gives +0)gfx1031, rawv_ldexp_f16on the hardware): ±0 and ±inf come back unchanged for exponents up to ±32767, as this PR doesRegression run
RTX 4070 Ti (driver 616.56), release builds, 60 s each,
scripts/smoke.ps1 -Title retail-titleon the newer retail title, mainaa9ab8aand this PR's head32bcaef(no uncommitted changes). (@Anon64's earlier runs, on an RTX 3060 for the previous head6ec4036, were equally clean.)main:
PR:
Not tested
shaders.rpf(xcl shaders --json, 26 503 shaders) has nov_ldexp_f16, so this does not change that title.XCL_DIRECT_DXIL=1; CI does not set it, so the test covers it only when run that waymainthe f16 result is narrowed toward zero (f16 add / FMA under a directed rounding mode are rounded twice (through f32) #111), so 1.0 · 2^20 gives0x7bff, not inf; that belongs to the f16 add / FMA under a directed rounding mode are rounded twice (through f32) #111 fixAI use