Recompiler: f16 results round to nearest even in the default mode (#111) #842

Open
github-bot wants to merge 1 commit from github-bot/gh-842 into main AGit
Owner

@⁠joeypercia on GitHub · 2026-11-24 06:39 UTC · original
joeypercia:recompiler-f16-default-rne → main · +175 −6 · 2 files · 1 commits · open

In the default mode every f16 result narrowed from binary32 went through HLSL f32tof16, which rounds toward zero, so 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 raw-ISA measurements on #672: ldexp(1, 20) = inf, subnormal ties to even). to_f16_expr now narrows with f32_to_f16_rm(e, 0u) in the default mode, the helper the multiplies already use (#166); under a dynamic rounding mode nothing changes. Part of #111.

v_fract_f16 needs one extra step: fract_f 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 (#655 found this).

This supersedes #696 (add / sub only), as its author suggested on #111; its cases are covered by the census test below.

In a retail title. The same to_f16_expr narrows v_interp_p2_f16, v_fma_mixlo_f16 and v_fma_mixhi_f16, so in a program that does not change the rounding mode they round toward zero on main too, and this PR makes them round to nearest even. They are most of what it changes in a retail game: in the newer retail title's shaders.rpf (xcl shaders --json, 26 503 shaders) there are 59 367 v_interp_p2_f16 (4 776 shaders), 33 900 v_fma_mixlo_f16 (6 155) and 2 135 v_fma_mixhi_f16 (842), against a few hundred v_add/sub/mul/fma_f16 and no v_ldexp_f16 or v_fract_f16. (v_cvt_f16_f32, 38 871, already rounds to nearest even on main.) gpu_s_round_mode_controls_f16_rounding_across_modes checks v_fma_mixlo_f16 only in a program that changes the mode, where it already took the rounding path.

Measured for the mix ops (a local test, not in this PR, so the regression runs below stay on its head): v_fma_mixlo_f16 / v_fma_mixhi_f16 of x·1 + 0 with x = 1 + 2^-11 + 2^-20, no mode change in the program, give 0x3C00 (toward zero) on main 037aecd and 0x3C01 (nearest even) with this PR merged on it, on both GPUs below. v_interp_p2_f16 is from reading the emitter, not measured.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: to_f16_expr rounds to nearest even in the default mode; v_fract_f16 keeps its result below 1.0 (only without OMOD)
  • crates/xcl/src/gpu/recomp/tests.rs:
    • gpu_f16_results_round_to_nearest_even_by_default: random inputs against an exact reference for add, sqrt, rcp, rsq, exp, log, ldexp and mul; fails on any toward-zero result of the exact ones (add, ldexp, mul) and prints the counts for the approximate ones
    • gpu_f16_unary_results_round_to_nearest_even: fixed inputs whose exact result sits 0.69–0.88 of a step above the lower neighbour (so a 1-ulp binary32 approximation can't change it), plus @⁠upipibi's two ldexp cases from #672 (overflow to inf, a subnormal tie to even)
    • gpu_fract_f16_stays_below_one_with_nearest_even: -2^-14 and -2^-24 give 0x3BFF, NaN stays NaN

Tested

  • NVIDIA GeForce RTX 4070 Ti (Ada, wave32), driver 616.56; AMD Radeon iGPU (Ryzen 7 7800X3D, RDNA2, native wave64, 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 on feaeb7b: RTX 4070 Ti 716 passed, 0 failed, 41 ignored; RDNA2 713 passed, 3 failed, 41 ignored; the 3 are placed_title_textures_share_vram_and_preserve_pixels and its two lock-poison followers (#718 / #288), under load, and pass alone on this head (2 runs of 2)
  • cargo test -p xcl --lib -- f16 fract: 16 passed on both, the existing s_round_mode and f16 rounding tests included
  • negative controls: with main's emit.rs, the census and unary tests fail on both GPUs (the unary test stops at its first case, sqrt(0x3420)); with nearest even but without the fract clamp, the fract test fails on both (fract(0x8400) = 0x3C00, want 0x3BFF), which is #655's regression
  • SKIPPED: RTX 4070 Ti gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64); RDNA2 gpu_geometry_mode_es_gs_strip, gpu_mesh_mode_two_passes (no mesh shaders)

Regression run

From @⁠Anon64 (RTX 3060, release builds, 60 s each), pasted unedited from their comment:

main:

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

PR:

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

Not tested

  • A retail title on my machine (none here; the regression runs above are @⁠Anon64's), and whether the title's frames show a visible difference
  • v_fma_f16 / v_fmac_f16 / v_pk_fma_f16: rounding the f32 result to nearest even is closer than toward zero, but still not always single rounding (#111's FMA point; #128 handles the exact sum for directed modes)
  • v_fract_f16 with OMOD: narrowed to nearest even without the below-1.0 step (a scaled fraction can legitimately reach 1.0 or more); not checked on hardware
  • Release build

AI use

  • Claude Code with Claude Opus 5.5: wrote the fix, the tests and this description, and ran the tests above on my machine.
**@⁠joeypercia** on GitHub · 2026-11-24 06:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/842) `joeypercia:recompiler-f16-default-rne` → `main` · +175 −6 · 2 files · 1 commits · open In the default mode every f16 result narrowed from binary32 went through HLSL `f32tof16`, which rounds toward zero, so 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 raw-ISA measurements on #672: `ldexp(1, 20)` = inf, subnormal ties to even). `to_f16_expr` now narrows with `f32_to_f16_rm(e, 0u)` in the default mode, the helper the multiplies already use (#166); under a dynamic rounding mode nothing changes. Part of #111. `v_fract_f16` needs one extra step: `fract_f` 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` (#655 found this). This supersedes #696 (add / sub only), as its author suggested on #111; its cases are covered by the census test below. **In a retail title.** The same `to_f16_expr` narrows `v_interp_p2_f16`, `v_fma_mixlo_f16` and `v_fma_mixhi_f16`, so in a program that does not change the rounding mode they round toward zero on `main` too, and this PR makes them round to nearest even. They are most of what it changes in a retail game: in the newer retail title's `shaders.rpf` (`xcl shaders --json`, 26 503 shaders) there are 59 367 `v_interp_p2_f16` (4 776 shaders), 33 900 `v_fma_mixlo_f16` (6 155) and 2 135 `v_fma_mixhi_f16` (842), against a few hundred `v_add/sub/mul/fma_f16` and no `v_ldexp_f16` or `v_fract_f16`. (`v_cvt_f16_f32`, 38 871, already rounds to nearest even on `main`.) `gpu_s_round_mode_controls_f16_rounding_across_modes` checks `v_fma_mixlo_f16` only in a program that changes the mode, where it already took the rounding path. Measured for the mix ops (a local test, not in this PR, so the regression runs below stay on its head): `v_fma_mixlo_f16` / `v_fma_mixhi_f16` of x·1 + 0 with x = 1 + 2^-11 + 2^-20, no mode change in the program, give `0x3C00` (toward zero) on `main` `037aecd` and `0x3C01` (nearest even) with this PR merged on it, on both GPUs below. `v_interp_p2_f16` is from reading the emitter, not measured. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: `to_f16_expr` rounds to nearest even in the default mode; `v_fract_f16` keeps its result below 1.0 (only without OMOD) - `crates/xcl/src/gpu/recomp/tests.rs`: - `gpu_f16_results_round_to_nearest_even_by_default`: random inputs against an exact reference for add, sqrt, rcp, rsq, exp, log, ldexp and mul; fails on any toward-zero result of the exact ones (add, ldexp, mul) and prints the counts for the approximate ones - `gpu_f16_unary_results_round_to_nearest_even`: fixed inputs whose exact result sits 0.69–0.88 of a step above the lower neighbour (so a 1-ulp binary32 approximation can't change it), plus @⁠upipibi's two ldexp cases from #672 (overflow to inf, a subnormal tie to even) - `gpu_fract_f16_stays_below_one_with_nearest_even`: `-2^-14` and `-2^-24` give `0x3BFF`, NaN stays NaN **Tested** - NVIDIA GeForce RTX 4070 Ti (Ada, wave32), driver 616.56; AMD Radeon iGPU (Ryzen 7 7800X3D, RDNA2, native wave64, 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` on feaeb7b: RTX 4070 Ti 716 passed, 0 failed, 41 ignored; RDNA2 713 passed, 3 failed, 41 ignored; the 3 are `placed_title_textures_share_vram_and_preserve_pixels` and its two lock-poison followers (#718 / #288), under load, and pass alone on this head (2 runs of 2) - `cargo test -p xcl --lib -- f16 fract`: 16 passed on both, the existing `s_round_mode` and f16 rounding tests included - negative controls: with `main`'s `emit.rs`, the census and unary tests fail on both GPUs (the unary test stops at its first case, `sqrt(0x3420)`); with nearest even but without the fract clamp, the fract test fails on both (`fract(0x8400)` = `0x3C00`, want `0x3BFF`), which is #655's regression - `SKIPPED`: RTX 4070 Ti `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64); RDNA2 `gpu_geometry_mode_es_gs_strip`, `gpu_mesh_mode_two_passes` (no mesh shaders) **Regression run** From @⁠Anon64 (RTX 3060, release builds, 60 s each), pasted unedited from their comment: main: ``` xcl-smoke v1 commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1636 (PresentX 1637) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18113 MB ``` PR: ``` xcl-smoke v1 commit: feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1633 (PresentX 1633) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17753 MB ``` **Not tested** - A retail title on my machine (none here; the regression runs above are @⁠Anon64's), and whether the title's frames show a visible difference - `v_fma_f16` / `v_fmac_f16` / `v_pk_fma_f16`: rounding the f32 result to nearest even is closer than toward zero, but still not always single rounding (#111's FMA point; #128 handles the exact sum for directed modes) - `v_fract_f16` with OMOD: narrowed to nearest even without the below-1.0 step (a scaled fraction can legitimately reach 1.0 or more); not checked on hardware - Release build **AI use** - Claude Code with Claude Opus 5.5: wrote the fix, the tests and this description, and ran the tests above on my machine.
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
#672). to_f16_expr now narrows with f32_to_f16_rm(e, 0u) in the default
mode, the helper the multiplies already use (#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 (#655).

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

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:34:18 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 06:51 UTC · original

Regression runs for this PR's head feaeb7b and for its base main beaa245, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

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

this PR:

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

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0
  • cargo test -p xcl --lib f16 (debug) on feaeb7b: 15 passed, 0 failed, including gpu_f16_results_round_to_nearest_even_by_default, gpu_f16_unary_results_round_to_nearest_even and gpu_fract_f16_stays_below_one_with_nearest_even

Not tested

  • the whole suite on this machine
  • whether the title reaches these f16 results; this is a regression check only

Since this covers #696's add / sub, I'll close #696 once this one is merged.

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

**@⁠Anon64** on GitHub · 2026-11-24 06:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7124359817) Regression runs for this PR's head `feaeb7b` and for its base `main` `beaa245`, on a retail title (same title, 60 s each), made with `scripts/smoke.ps1` (release, clean tree at each commit) and pasted unedited, for **Regression run**. main: ``` xcl-smoke v1 commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1636 (PresentX 1637) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18113 MB ``` this PR: ``` xcl-smoke v1 commit: feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1633 (PresentX 1633) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17753 MB ``` **Tested** - NVIDIA GeForce RTX 3060 12 GB (Ampere, driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0 - `cargo test -p xcl --lib f16` (debug) on `feaeb7b`: 15 passed, 0 failed, including `gpu_f16_results_round_to_nearest_even_by_default`, `gpu_f16_unary_results_round_to_nearest_even` and `gpu_fract_f16_stays_below_one_with_nearest_even` **Not tested** - the whole suite on this machine - whether the title reaches these f16 results; this is a regression check only Since this covers #696's add / sub, I'll close #696 once this one is merged. Report written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 07:04 UTC · original

Full-suite run to go with the smoke runs above, so the new GPU tests have a result on hardware. Tested exact head feaeb7b (on its base beaa245).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 716 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: gpu_f16_results_round_to_nearest_even_by_default, gpu_f16_unary_results_round_to_nearest_even, gpu_fract_f16_stays_below_one_with_nearest_even.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 07:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7124580750) Full-suite run to go with the smoke runs above, so the new GPU tests have a result on hardware. Tested exact head `feaeb7b` (on its base `beaa245`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **716 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `gpu_f16_results_round_to_nearest_even_by_default`, `gpu_f16_unary_results_round_to_nearest_even`, `gpu_fract_f16_stays_below_one_with_nearest_even`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠zhouzhidong3-hash on GitHub · 2026-11-24 07:04 UTC · original · edited 2026-11-24 07:08 UTC

Paired RTX 5070 Release check of the 11 raw binary16/exponent pairs from the native gfx1031 reference, using the same wave32 probe, driver 591.86 and DXC 1.8.2502.11 across runs.

Emitter Native matches Differences
#672 at 6ec4036 8/11 Both finite overflows and the 0x0003 / 2 halfway case
#842 at feaeb7b 8/11 ldexp(+0,32767), ldexp(+inf,-32768), ldexp(-inf,-32768) gave 0x7fff
#842 plus only the v_ldexp_f16 emitter arm from #672 11/11 None in this fixture

The #842 head corrects all three rounding differences from the #672 baseline. Its checked-in gpu_f16_results_round_to_nearest_even_by_default test also passed. The #842 emitter still calls HLSL ldexp for the f16 instruction; the third row locally substituted #672's ldexp_f call, leaving #842's narrowing in place. This is a focused combination check, not evidence that #842 introduced the extreme-exponent behavior. Default-mode synthetic cases only; no full-branch merge, wave64 or game run tested here. OpenAI Codex ran the comparison and drafted the report.

Integration check: the complete two-file #672 patch applied cleanly to feaeb7b. The Release f16 name-filtered suite on this local combination passed 16/16, with 681 filtered out and no runtime skip reported. The filter also matches UTF-16 tests. The relevant passes include the original ldexp, rounding census, unary rounding and fract fixtures from these two PRs. Full workspace and retail runs remain untested here.

**@⁠zhouzhidong3-hash** on GitHub · 2026-11-24 07:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7124594681) · edited 2026-11-24 07:08 UTC Paired RTX 5070 Release check of the 11 raw binary16/exponent pairs from [the native gfx1031 reference](https://github.com/ivall/xcl/pull/672#issuecomment-7123466880), using the same wave32 probe, driver 591.86 and DXC 1.8.2502.11 across runs. | Emitter | Native matches | Differences | |---|---:|---| | #672 at 6ec4036 | 8/11 | Both finite overflows and the 0x0003 / 2 halfway case | | #842 at feaeb7b | 8/11 | ldexp(+0,32767), ldexp(+inf,-32768), ldexp(-inf,-32768) gave 0x7fff | | #842 plus only the v_ldexp_f16 emitter arm from #672 | 11/11 | None in this fixture | The #842 head corrects all three rounding differences from the #672 baseline. Its checked-in gpu_f16_results_round_to_nearest_even_by_default test also passed. The #842 emitter still calls HLSL ldexp for the f16 instruction; the third row locally substituted #672's ldexp_f call, leaving #842's narrowing in place. This is a focused combination check, not evidence that #842 introduced the extreme-exponent behavior. Default-mode synthetic cases only; no full-branch merge, wave64 or game run tested here. OpenAI Codex ran the comparison and drafted the report. Integration check: the complete two-file #672 patch applied cleanly to feaeb7b. The Release f16 name-filtered suite on this local combination passed 16/16, with 681 filtered out and no runtime skip reported. The filter also matches UTF-16 tests. The relevant passes include the original ldexp, rounding census, unary rounding and fract fixtures from these two PRs. Full workspace and retail runs remain untested here.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 07:17 UTC · original

Linux / AMD RDNA3 datapoint.

Merged state: head feaeb7b onto main beaa245, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 706 passed, 10 failed, 41 ignored. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Your three f16 round-to-nearest-even tests all pass on RDNA3 native wave64: gpu_f16_results_round_to_nearest_even_by_default, gpu_f16_unary_results_round_to_nearest_even, gpu_fract_f16_stays_below_one_with_nearest_even ok. Follow-on datapoint to my #696 row for the same f16 axis.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-24 07:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7124831543) Linux / AMD RDNA3 datapoint. **Merged state:** head `feaeb7b` onto main `beaa245`, clean merge. **Full suite, `cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4`:** **706 passed, 10 failed, 41 ignored**. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Your three f16 round-to-nearest-even tests all pass on RDNA3 native wave64: `gpu_f16_results_round_to_nearest_even_by_default`, `gpu_f16_unary_results_round_to_nearest_even`, `gpu_fract_f16_stays_below_one_with_nearest_even` ok. Follow-on datapoint to my #696 row for the same f16 axis. **Not tested:** retail titles (none here), Windows, RDNA4. Counts only, no game data. **Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross `x86_64-pc-windows-gnu`, `XCL_NETWORK=0`, release profile, `--test-threads=4`. Linux rows: #42 / #718. AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Author
Owner

@⁠eizispark on GitHub · 2026-11-24 08:08 UTC · original

Hardware check of feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a (verified clean merge with main 1c87b1d): 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: 716 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none)
  • Verified f16 nearest-even rounding & wave64 GPU tests (gpu_f16_results_round_to_nearest_even_by_default, gpu_f16_unary_results_round_to_nearest_even, gpu_fract_f16_stays_below_one_with_nearest_even, gpu_f16_defaults_to_round_to_nearest_even, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware): all ok; --nocapture census on RX 9070 XT recorded [N, 0, 0] ([nearest even, toward zero, neither]) across all 8 ops (add, sqrt, rcp, rsq, exp, log, ldexp, mul) in both wave64 and wave32

Regression run
main (beaa245):

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

PR (feaeb7b):

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

(Note: an initial cold-shader-cache smoke run exited early with 0xc0000409, presents per 2 s (last 3): 0 21 59, device removals: 0, crashes: 0, peak commit: 9490 MB during first-run DXC compilation; the immediate rerun above ran the full 60 s cleanly.)

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.
**@⁠eizispark** on GitHub · 2026-11-24 08:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7125764218) Hardware check of `feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a` (verified clean merge with `main` `1c87b1d`): **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`: `716 passed, 0 failed, 41 ignored` (GPU tests skipped on this adapter: `none`) - Verified f16 nearest-even rounding & wave64 GPU tests (`gpu_f16_results_round_to_nearest_even_by_default`, `gpu_f16_unary_results_round_to_nearest_even`, `gpu_fract_f16_stays_below_one_with_nearest_even`, `gpu_f16_defaults_to_round_to_nearest_even`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`): all `ok`; `--nocapture` census on RX 9070 XT recorded `[N, 0, 0]` (`[nearest even, toward zero, neither]`) across all 8 ops (`add`, `sqrt`, `rcp`, `rsq`, `exp`, `log`, `ldexp`, `mul`) in both `wave64` and `wave32` **Regression run** `main` (`beaa245`): ``` xcl-smoke v1 commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1660 (PresentX 1660) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14862 MB ``` PR (`feaeb7b`): ``` xcl-smoke v1 commit: feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1665 (PresentX 1665) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14858 MB ``` *(Note: an initial cold-shader-cache smoke run exited early with `0xc0000409`, `presents per 2 s (last 3): 0 21 59`, `device removals: 0`, `crashes: 0`, `peak commit: 9490 MB` during first-run DXC compilation; the immediate rerun above ran the full 60 s cleanly.)* **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.
Author
Owner

@⁠KENAJBBY on GitHub · 2026-11-24 09:31 UTC · original

Native RDNA2 (gfx1036): f16 add / sub round once, in every rounding mode

This is a hardware reference for the add / sub part of this PR (which covers #696 / #685). I ran the instructions on raw bits on an RDNA2 GPU under an explicitly set MODE (s_setreg_b32, read back with s_getreg_b32 before the instruction). Every result was compared with an exact integer reference: an f16 sum is exact in units of 2^-24, rounded once in the mode under test.

  • v_add_f16, v_sub_f16, v_subrev_f16 and v_pk_add_f16 (both halves) show 0 differences from a single correct rounding on 60,000 operand pairs, in each of 37 modes. The pairs lean towards ones that need rounding, plus ties, overflow, zero signs and subnormals. The modes are every f16 round mode × every f16 denorm mode × IEEE 0/1, plus f32 round, f32 denorm and DX10_CLAMP variations, which change nothing.
  • In the default mode (f16 RNE, f16 denormals on), this PR's binary32-sum-then-nearest-even model differs from the hardware on 0 of the 60,000 pairs, for all four instructions.
  • #696's five vectors, raw on the hardware at MODE 0x1C0, give exactly #696's expected bits:
a, b add sub subrev pk_add lo / hi
0x3C00, 0x1200 0x3C01 0x3BFE 0xBBFE 0x3C01 / 0x3C01
0x3C00, 0x0800 0x3C00 0x3C00 0xBC00 0x3C00 / 0x3C00
0xBC00, 0x9200 0xBC01 0xBBFE 0x3BFE 0xBC01 / 0xBC01
0x3C00, 0x1000 0x3C00 0x3BFF 0xBBFF 0x3C00 / 0x3C00
0x7BFF, 0x5000 0x7C00 0x7BFE 0xFBFE 0x7C00 / 0x7C00

Outside this PR's scope, for #111 and #73:

  • s_round_mode: the hardware writes MODE[3:0] = the immediate. s_round_mode 0..15 read back as MODE[3:0] = 0..15 with MODE[9:4] untouched, and s_denorm_mode n writes MODE[7:4] = n. So 0xC is f16/f64 round toward zero with f32 RNE, as #91 assumes; #73 listed this as unconfirmed. In 0xC the hardware rounds the f16 sum once toward zero. The dynamic-mode path (binary32 sum, then f32_to_f16_rm(…, 3)), as I model it, differs on 601 of the 60,000 pairs for v_add_f16, always where the binary32 sum is inexact. #111's three cases give the values #111 calls correct: 0x3C00 + 0x0001 toward +inf = 0x3C01, 0x4000 + 0x8001 RTZ = 0x3FFF, v_fma_f16(0x4000, 0x3C00, 0x8001) RTZ = 0x3FFF.
  • f16 denormal mode: with MODE[6] = 0 the hardware reads denormal f16 inputs as zero, and with MODE[7] = 0 it flushes denormal results. XCL always keeps f16 denormals, which is right if console shaders start with MODE[7:6] = 3. XCL does not read the entry mode (#73), and the pack has no s_denorm_mode.

Tested

  • AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), driver 32.0.21030.2001, AMD OpenCL 3652.0 (PAL,LC), native wave64; Windows 11 Pro 26200.
  • Inline asm in OpenCL C, one block per lane. It saves MODE, sets it with s_setreg_b32 hwreg(HW_REG_MODE, 0, 10), reads it back with s_getreg_b32 (checked against the requested value in every run), runs the instruction and restores MODE. Inputs: 4 instructions × 37 modes × 60,000 pairs.

Not tested

  • This PR's HLSL on my GPUs: I compared against a model of it (binary32 sum, then nearest even).
  • The PR's unary f16 results (sqrt, rcp, rsq, exp, log, ldexp), v_fma_f16, NaN / inf inputs; console hardware and its entry MODE.

AI use

  • Claude Code (Claude Opus 5.5) wrote the probe and the reference, ran them on this machine and drafted this comment.
**@⁠KENAJBBY** on GitHub · 2026-11-24 09:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7127524349) **Native RDNA2 (`gfx1036`): f16 add / sub round once, in every rounding mode** This is a hardware reference for the add / sub part of this PR (which covers #696 / #685). I ran the instructions on raw bits on an RDNA2 GPU under an explicitly set MODE (`s_setreg_b32`, read back with `s_getreg_b32` before the instruction). Every result was compared with an exact integer reference: an f16 sum is exact in units of 2^-24, rounded once in the mode under test. - `v_add_f16`, `v_sub_f16`, `v_subrev_f16` and `v_pk_add_f16` (both halves) show **0 differences from a single correct rounding** on 60,000 operand pairs, in each of 37 modes. The pairs lean towards ones that need rounding, plus ties, overflow, zero signs and subnormals. The modes are every f16 round mode × every f16 denorm mode × IEEE 0/1, plus f32 round, f32 denorm and DX10_CLAMP variations, which change nothing. - In the default mode (f16 RNE, f16 denormals on), this PR's binary32-sum-then-nearest-even model differs from the hardware on **0 of the 60,000** pairs, for all four instructions. - #696's five vectors, raw on the hardware at MODE `0x1C0`, give exactly #696's expected bits: | a, b | add | sub | subrev | pk_add lo / hi | |---|---|---|---|---| | `0x3C00`, `0x1200` | `0x3C01` | `0x3BFE` | `0xBBFE` | `0x3C01` / `0x3C01` | | `0x3C00`, `0x0800` | `0x3C00` | `0x3C00` | `0xBC00` | `0x3C00` / `0x3C00` | | `0xBC00`, `0x9200` | `0xBC01` | `0xBBFE` | `0x3BFE` | `0xBC01` / `0xBC01` | | `0x3C00`, `0x1000` | `0x3C00` | `0x3BFF` | `0xBBFF` | `0x3C00` / `0x3C00` | | `0x7BFF`, `0x5000` | `0x7C00` | `0x7BFE` | `0xFBFE` | `0x7C00` / `0x7C00` | Outside this PR's scope, for #111 and #73: - **`s_round_mode`**: the hardware writes MODE[3:0] = the immediate. `s_round_mode 0..15` read back as MODE[3:0] = 0..15 with MODE[9:4] untouched, and `s_denorm_mode n` writes MODE[7:4] = n. So `0xC` is f16/f64 round toward zero with f32 RNE, as #91 assumes; #73 listed this as unconfirmed. In `0xC` the hardware rounds the f16 sum once toward zero. The dynamic-mode path (binary32 sum, then `f32_to_f16_rm(…, 3)`), as I model it, differs on 601 of the 60,000 pairs for `v_add_f16`, always where the binary32 sum is inexact. #111's three cases give the values #111 calls correct: `0x3C00 + 0x0001` toward +inf = `0x3C01`, `0x4000 + 0x8001` RTZ = `0x3FFF`, `v_fma_f16(0x4000, 0x3C00, 0x8001)` RTZ = `0x3FFF`. - **f16 denormal mode**: with MODE[6] = 0 the hardware reads denormal f16 inputs as zero, and with MODE[7] = 0 it flushes denormal results. XCL always keeps f16 denormals, which is right if console shaders start with MODE[7:6] = 3. XCL does not read the entry mode (#73), and the pack has no `s_denorm_mode`. **Tested** - AMD Radeon iGPU of a Ryzen 7 9800X3D (`gfx1036`, RDNA2), driver 32.0.21030.2001, AMD OpenCL `3652.0 (PAL,LC)`, native wave64; Windows 11 Pro 26200. - Inline asm in OpenCL C, one block per lane. It saves MODE, sets it with `s_setreg_b32 hwreg(HW_REG_MODE, 0, 10)`, reads it back with `s_getreg_b32` (checked against the requested value in every run), runs the instruction and restores MODE. Inputs: 4 instructions × 37 modes × 60,000 pairs. **Not tested** - This PR's HLSL on my GPUs: I compared against a model of it (binary32 sum, then nearest even). - The PR's unary f16 results (sqrt, rcp, rsq, exp, log, ldexp), `v_fma_f16`, NaN / inf inputs; console hardware and its entry MODE. **AI use** - Claude Code (Claude Opus 5.5) wrote the probe and the reference, ran them on this machine and drafted this comment.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 06:57 UTC · original

Tested

Clean detached PR head feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a on STOR-WINLAB. Windows 11 Enterprise Evaluation 25H2 x64 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust/Cargo 1.100.0 MSVC, DXC/DXIL 1.9.2609.5.

cargo test --locked -p xcl --lib --no-run built outside the Arc mutex in 1m 13s, exit 0. With XCL_ADAPTER=A770, XCL_DIRECT_DXIL=0 and DXC/DXIL 1.9.2609.5 configured, the following exact filters were run under Invoke-ArcTest.ps1 -Test.

$exe = 'L:/XclTooling/pr1801-e00963f-t3-3c561aa2/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe'
& $exe gpu::recomp::tests::gpu_f16_results_round_to_nearest_even_by_default --exact --nocapture --test-threads=1
& $exe gpu::recomp::tests::gpu_f16_unary_results_round_to_nearest_even --exact --nocapture --test-threads=1
& $exe gpu::recomp::tests::gpu_fract_f16_stays_below_one_with_nearest_even --exact --nocapture --test-threads=1

3 passed, 0 failed, 0 ignored, 0 skipped, 695 filtered out per invocation. Native and wrapper exits were 0. On standalone wave32, 4,727 inexact results matched nearest-even across eight operations, with assertions enforcing 2,041 add/ldexp/multiply cases. The unary and fract fixtures passed 224 and 32 lane comparisons respectively, including overflow, a subnormal tie, clamping below one and NaN preservation.

Not tested

Split or native wave64, direct DXIL, other adapters, negative controls, full workspace suite, and retail smoke.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the verification and wrote this report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 06:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7155336091) **Tested** Clean detached PR head `feaeb7b0b437abfddcb6612f9d4bd1c853ebfb6a` on STOR-WINLAB. Windows 11 Enterprise Evaluation 25H2 x64 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust/Cargo 1.100.0 MSVC, DXC/DXIL 1.9.2609.5. `cargo test --locked -p xcl --lib --no-run` built outside the Arc mutex in 1m 13s, exit 0. With `XCL_ADAPTER=A770`, `XCL_DIRECT_DXIL=0` and DXC/DXIL 1.9.2609.5 configured, the following exact filters were run under `Invoke-ArcTest.ps1 -Test`. ```powershell $exe = 'L:/XclTooling/pr1801-e00963f-t3-3c561aa2/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe' & $exe gpu::recomp::tests::gpu_f16_results_round_to_nearest_even_by_default --exact --nocapture --test-threads=1 & $exe gpu::recomp::tests::gpu_f16_unary_results_round_to_nearest_even --exact --nocapture --test-threads=1 & $exe gpu::recomp::tests::gpu_fract_f16_stays_below_one_with_nearest_even --exact --nocapture --test-threads=1 ``` **3 passed, 0 failed, 0 ignored, 0 skipped**, 695 filtered out per invocation. Native and wrapper exits were 0. On standalone wave32, 4,727 inexact results matched nearest-even across eight operations, with assertions enforcing 2,041 add/ldexp/multiply cases. The unary and fract fixtures passed 224 and 32 lane comparisons respectively, including overflow, a subnormal tie, clamping below one and NaN preservation. **Not tested** Split or native wave64, direct DXIL, other adapters, negative controls, full workspace suite, and retail smoke. **AI use** T3 Code / Codex (`gpt-6.2-sol`) ran the verification and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:27 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 10:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/842#issuecomment-7159729041) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/842/head:github-bot/gh-842'
git switch 'github-bot/gh-842'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-842'
git switch 'github-bot/gh-842'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-842'
git switch 'github-bot/gh-842'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-842'
git switch 'main'
git merge --squash 'github-bot/gh-842'
git switch 'main'
git merge --ff-only 'github-bot/gh-842'
git switch 'main'
git merge 'github-bot/gh-842'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.