Recompiler: round f16 conversions and products to nearest-even by default #163
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/166"
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?
Imported from ivall/xcl. Originally posted by ebarr24 on 2026-11-23T18:23:52Z.
The default RDNA binary16 rounding mode is round-to-nearest-even. XCL has used legacy HLSL
f32tof16for that path, which narrows toward zero. On the RTX 3080, converting3075.0gives0x6A01instead of0x6A02, and converting65520.0gives0x7BFFinstead of infinity. Direct3D conversion rules, sections 3.2.2 and 22.13.2Use the existing
f32_to_f16_rmhelper forv_cvt_f16_f32,v_mul_f16, andv_pk_mul_f16, with a constant nearest-even mode when the shader leaves the default in place. The finite product of two binary16 inputs fits exactly in binary32, so one narrowing is sufficient. The regression covers midpoint and adjacent values, negative input, overflow, a subnormal and scalar and packed multiplication with midpoint products.Issue #111 tracks the exact product and sum needed for a single-rounding FMA. Rounding issue #111 · CPU reproduction
Verification
Windows 11 25H2 (26200.9711), Rust 1.100.0
x86_64-pc-windows-gnu, RTX 3080 (driver 616.92), DXC 1.9.2609.5.db5dc26.deccf2bthe expanded conversion, scalar product and packed product regression passes. The full workspace run on10f25f4, with #157, #158 and #160 applied alongside this patch, reported 571 passes, zero failures and 39 ignored. Two native-wave64 tests and the unconfigured retail-sample tests returned early.mainat956a476.AI-assisted patch preparation and verification.
Imported from ivall/xcl. Originally posted by WarmMilkCodes on 2026-11-23T18:55:40Z.
Tested #166
deccf2bmerged onto main956a476on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): passcargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*data:No new failures vs main. The PR's new test passes on RDNA2. The one failure on both,
gpu_wave64_ps_whole_wave_reductions, is the 32-lane PS case on this card (#155).Imported from ivall/xcl. Originally posted by TheHoracio on 2026-11-23T19:28:10Z.
Tested on AMD RDNA3: Radeon RX 7800 XT (16 GB, wave 32–64), driver 32.0.32015.7029, Windows 11 Pro 10.0.26300, Rust 1.100.0
x86_64-pc-windows-msvc, DXC 1.9.2602.17. The PR headdeccf2bwas tested as is, with no other PRs applied.cargo test --workspace --no-fail-fast: 568 passed, 1 failed, 39 ignored, 0SKIPPED.gpu_f16_defaults_to_round_to_nearest_evenpasses on AMD as well. The existing f16 rounding tests also pass:gpu_s_round_mode_controls_f16_rounding_across_modes,gpu_mad_nf_f16_rounds_intermediate_in_binary16,gpu_cvt_norm_f16_exact_rounding_and_edge_cases,gpu_cmp_class_f16_preserves_snan.gpu_wave64_ps_whole_wave_reductions. It fails the same way onmain956a476on this GPU and is fixed by #155 (see my comment there). It is unrelated to this PR.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T20:34:18Z.
Additional default-mode check on the RTX 5070 Ti (driver 610.74, Windows x64 MSVC, Rust 1.99.0): I tested PR head
deccf2ba3c0f09023bc9ccf2f49cb5af8aae798fdirectly, and carried its test plus a 14-lane synthetic conversion probe to main956a476bf738a098f39df4f4c8acef682e43030f.387fe000(midpoint between the largest subnormal and smallest normal)03ff04003f801000,3f803000(successive midpoints)3c00,3c013c00,3c0233000000,33000001,b30000010000,0000,80000000,0001,8001The tie results agree with half-precision round mode 0. The NaN assertion checked the quiet-NaN class only. AMD RDNA 2 ISA, §6.4 and V_CVT_F16_F32
Of seven recompiler tests matching
f16, five passed on main and all seven passed on the head. The failures were the verbatim PR regression (including scalar and packed products) and the added conversion probe. Each dispatched synthetic shaders. No retail shaders, merge build, or explicit denorm-mode sweep. AI-assisted review.Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T20:52:41Z.
Merged (main
2abc562). Checked on an RX 9070 (RDNA4) with the 11 PRs merged together on main38b05b7:cargo build --workspace && cargo test --workspace -- --test-threads=4- 547 unit tests passed, 0 failed (19 ignored); the integration and e2e tests passed too.