Recompiler: v_min/v_max order -0.0 < +0.0 as RDNA2 does in IEEE mode #1348

Closed
github-bot wants to merge 1 commit from gh-pr/1348/head into gh-pr/1348/base
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 15:05 UTC · original
DavidM1911:fix-1282-minmax → main · +75 −8 · 2 files · 1 commits · closed without merging

v_min_f32/v_max_f32/v_min_f16/v_max_f16 and the 3-operand forms emitted plain HLSL min()/max() → DXIL FMin/FMax, whose -0.0/+0.0 result depends on operand order on NVIDIA/WARP. RDNA2 IEEE mode orders -0.0 < +0.0 deterministically: v_min(+0,-0) = v_min(-0,+0) = -0, v_max mirrors to +0.

What is in it

  • fmin_ieee/fmax_ieee HLSL helpers: NaN-suppressing min/max as before, with the both-zero case settled on the sign bits (min: OR keeps -0; max: AND keeps +0). Used for all four f32 forms.
  • The f16 path converts through f32, and f16 -> f32 -> f16 loses the sign of zero entirely (measured: v_add_f16(-0,-0) already yields +0 on this pipeline), so min16z2/3/max16z2/3 settle the zero cases on the raw halves: -0 when a -0 operand is present and nothing is negative, +0 for max when a +0 is present and nothing is positive; NaNs and nonzero results defer to the float path. abs/neg modifiers are already bitwise via hb().
  • New GPU test gpu_min_max_f32_f16_order_negative_zero: both operand orders for all eight instructions, wave32 and wave64.

Note: #1301 adds a test-only version of the f32 coverage; this PR includes the f32 fix plus the f16 handling that test does not cover.

Fixes #1282

Tested

  • cargo test -p xcl --lib recomp: 190 passed, 0 failed, 18 ignored (RTX 3060 Ti, Windows 11, DXC 1.8.2502.11). New test passes on both wave sizes.

Regression run

main 930e8b4:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1603 (PresentX 1603)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14549 MB

head 052af4d:

xcl-smoke v1
commit: 052af4d65c91796f19154ee6e2872b6d52a6e59f
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1592 (PresentX 1593)
presents per 2 s (last 3): 60 39 60
device removals: 0
crashes: 0
peak commit: 14550 MB

Not tested

macOS / Linux (crate does not build there). f16 -0 through other arithmetic ops (e.g. v_add_f16) remains as before — out of scope here.

AI use

Devin (Cognition), frontier model. Implemented the fix and tests; ran the suite and smoke above.

**@⁠DavidM1911** on GitHub · 2026-11-24 15:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348) `DavidM1911:fix-1282-minmax` → `main` · +75 −8 · 2 files · 1 commits · closed without merging `v_min_f32`/`v_max_f32`/`v_min_f16`/`v_max_f16` and the 3-operand forms emitted plain HLSL `min()`/`max()` → DXIL `FMin`/`FMax`, whose `-0.0`/`+0.0` result depends on operand order on NVIDIA/WARP. RDNA2 IEEE mode orders `-0.0 < +0.0` deterministically: `v_min(+0,-0) = v_min(-0,+0) = -0`, `v_max` mirrors to `+0`. ## What is in it - `fmin_ieee`/`fmax_ieee` HLSL helpers: NaN-suppressing `min`/`max` as before, with the both-zero case settled on the sign bits (`min`: OR keeps `-0`; `max`: AND keeps `+0`). Used for all four f32 forms. - The f16 path converts through f32, and `f16 -> f32 -> f16` loses the sign of zero entirely (measured: `v_add_f16(-0,-0)` already yields `+0` on this pipeline), so `min16z2/3`/`max16z2/3` settle the zero cases on the raw halves: `-0` when a `-0` operand is present and nothing is negative, `+0` for max when a `+0` is present and nothing is positive; NaNs and nonzero results defer to the float path. `abs`/`neg` modifiers are already bitwise via `hb()`. - New GPU test `gpu_min_max_f32_f16_order_negative_zero`: both operand orders for all eight instructions, wave32 and wave64. Note: #1301 adds a test-only version of the f32 coverage; this PR includes the f32 fix plus the f16 handling that test does not cover. Fixes #1282 ## Tested - `cargo test -p xcl --lib recomp`: 190 passed, 0 failed, 18 ignored (RTX 3060 Ti, Windows 11, DXC 1.8.2502.11). New test passes on both wave sizes. ## Regression run main `930e8b4`: ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1603 (PresentX 1603) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14549 MB ``` head `052af4d`: ``` xcl-smoke v1 commit: 052af4d65c91796f19154ee6e2872b6d52a6e59f gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1592 (PresentX 1593) presents per 2 s (last 3): 60 39 60 device removals: 0 crashes: 0 peak commit: 14550 MB ``` ## Not tested macOS / Linux (crate does not build there). f16 `-0` through other arithmetic ops (e.g. `v_add_f16`) remains as before — out of scope here. ## AI use Devin (Cognition), frontier model. Implemented the fix and tests; ran the suite and smoke above.
v_min_f32/f16 and v_max_f32/f16 (and the 3-operand forms) emitted plain
HLSL min()/max(), which lowers to DXIL FMin/FMax: on NVIDIA and WARP the
signed-zero result depends on operand order, while RDNA2 IEEE mode
deterministically returns -0 for min and +0 for max when the operands
are +0/-0 in either order.

f32 goes through fmin_ieee/fmax_ieee: NaN-suppressing min/max as before,
with the both-zero case settled on the sign bits (min: OR keeps -0,
max: AND keeps +0).

The f16 path converts through f32, and f16 -> f32 -> f16 loses the sign
of zero entirely (v_add_f16(-0,-0) already yields +0), so the zero cases
are settled on the raw halves instead: min16z*/max16z* return -0 when a
-0 operand is present and nothing is negative (max mirrors it, +0
winning over -0), and defer to the float result otherwise.

New GPU test gpu_min_max_f32_f16_order_negative_zero covers both
operand orders for all eight instructions on wave32 and wave64.

Fixes #1282
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:29 +00:00
github-bot closed this pull request 2026-11-26 04:51:29 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 15:14 UTC · original · edited 2026-11-24 15:22 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 052af4d (on its base 930e8b4).

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: 752 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_min_max_f32_f16_order_negative_zero.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.
  • I also ran this PR's new test against main's emitter (main 930e8b4 with only tests.rs from this PR): gpu_min_max_f32_f16_order_negative_zero passes there too, 2 of 2 on each GPU. So on these two drivers (RTX 5070 Ti, Radeon RDNA2 iGPU) plain min/max already gave the RDNA2 -0 / +0 answers for the operand orders in the test, and the test does not show the bug here; it would on a driver that gets the order wrong (WARP, per the description). The same goes for #1301's test, which passed on main on both GPUs here.

Not tested

  • 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 15:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7135690602) · edited 2026-11-24 15:22 UTC Full-suite run, since this PR has no test report yet. Tested exact head `052af4d` (on its base `930e8b4`). **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`: **752 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_min_max_f32_f16_order_negative_zero`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**, no skips. - I also ran this PR's new test against `main`'s emitter (`main` `930e8b4` with only `tests.rs` from this PR): `gpu_min_max_f32_f16_order_negative_zero` passes there too, 2 of 2 on each GPU. So on these two drivers (RTX 5070 Ti, Radeon RDNA2 iGPU) plain `min`/`max` already gave the RDNA2 `-0` / `+0` answers for the operand orders in the test, and the test does not show the bug here; it would on a driver that gets the order wrong (WARP, per the description). The same goes for #1301's test, which passed on `main` on both GPUs here. **Not tested** - 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

@⁠lemosss on GitHub · 2026-11-24 15:25 UTC · original

Adding to the report above with what it does not cover: an Ada data point, WARP, and the f64 forms.

Tested (head 052af4d, XCL_TRANSLATED_CACHE=0 for every run)

  • NVIDIA GeForce RTX 4060 8 GB (Ada, 32-lane waves only), driver 610.88 (32.0.16.1088); Intel Core i7-10700K; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; DXC 1.9.2609.5; debug
  • gpu_min_max_f32_f16_order_negative_zero passes on the head, and also with emit.rs put back to 930e8b4 (the new test kept). Same result as on the RTX 5070 Ti and the RDNA2 iGPU above: on Ada too, plain min / max already give the RDNA2 answers for the cases in the test.
  • WARP (XCL_ADAPTER=warp): the test prints SKIPPED … no wave64 and runs nothing, with or without the fix. So the WARP failure in the description cannot be shown with this test as it is.
  • v_min_f64 / v_max_f64, which this PR leaves on plain min / max: a throwaway probe on the same build gives min(+0, −0) = min(−0, +0) = 0x8000000000000000 and max(+0, −0) = max(−0, +0) = 0x0000000000000000 on this GPU, i.e. the RDNA2 order already. If the f32 / f16 forms are guarded for drivers that differ, the f64 pair would need the same.

Not tested: AMD / wave64, a release build, a retail title.

Run and written with Claude Code (Claude Opus 5.5).

**@⁠lemosss** on GitHub · 2026-11-24 15:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7136000213) Adding to the report above with what it does not cover: an Ada data point, WARP, and the f64 forms. **Tested** (head `052af4d`, `XCL_TRANSLATED_CACHE=0` for every run) - NVIDIA GeForce RTX 4060 8 GB (Ada, 32-lane waves only), driver 610.88 (32.0.16.1088); Intel Core i7-10700K; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; DXC 1.9.2609.5; debug - `gpu_min_max_f32_f16_order_negative_zero` passes on the head, and also with `emit.rs` put back to `930e8b4` (the new test kept). Same result as on the RTX 5070 Ti and the RDNA2 iGPU above: on Ada too, plain `min` / `max` already give the RDNA2 answers for the cases in the test. - **WARP** (`XCL_ADAPTER=warp`): the test prints `SKIPPED … no wave64` and runs nothing, with or without the fix. So the WARP failure in the description cannot be shown with this test as it is. - **`v_min_f64` / `v_max_f64`**, which this PR leaves on plain `min` / `max`: a throwaway probe on the same build gives `min(+0, −0) = min(−0, +0) = 0x8000000000000000` and `max(+0, −0) = max(−0, +0) = 0x0000000000000000` on this GPU, i.e. the RDNA2 order already. If the f32 / f16 forms are guarded for drivers that differ, the f64 pair would need the same. **Not tested:** AMD / wave64, a release build, a retail title. _Run and written with Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠Darkkandadr on GitHub · 2026-11-24 16:07 UTC · original

An Ampere data point to add to the two reports above. The RTX 3060 has the same architecture as the author's RTX 3060 Ti, but this run used a different driver.

Tested (head 052af4d, on its base 930e8b4)

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2101; Intel Core i3-12100F; Windows 11 Pro build 26300; Rust 1.96.0 MSVC, debug; DXC 1.9.2609.5; D3D12 debug layer installed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 751 passed, 1 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The one failure is e2e::test_title_draws_with_a_root_signature_under_the_debug_layer, and it is unrelated to this PR. It also fails on main in my deep checkout, because the overlay path goes past MAX_PATH. #1015 fixes it (details there).
  • gpu_min_max_f32_f16_order_negative_zero passes on the head. It also passes with only this PR's tests.rs on main 930e8b4. It ran on the GPU there and was not skipped: DXC loaded, and there was no skip line with --nocapture. So, as on the RTX 5070 Ti, RTX 4060 and RDNA2 iGPU above, plain min / max on Ampere with this driver already give the RDNA2 -0 / +0 answers for the cases in the test. The test does not fail without the fix on any GPU reported so far.

Not tested

  • A release build, AMD / wave64, WARP, a retail title.

Run and written with Claude Code (Claude Opus 5.5).

**@⁠Darkkandadr** on GitHub · 2026-11-24 16:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7137169821) An Ampere data point to add to the two reports above. The RTX 3060 has the same architecture as the author's RTX 3060 Ti, but this run used a different driver. **Tested** (head `052af4d`, on its base `930e8b4`) - NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2101; Intel Core i3-12100F; Windows 11 Pro build 26300; Rust 1.96.0 MSVC, debug; DXC 1.9.2609.5; D3D12 debug layer installed. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: **751 passed, 1 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The one failure is `e2e::test_title_draws_with_a_root_signature_under_the_debug_layer`, and it is unrelated to this PR. It also fails on `main` in my deep checkout, because the overlay path goes past `MAX_PATH`. #1015 fixes it (details there). - `gpu_min_max_f32_f16_order_negative_zero` passes on the head. It also passes with only this PR's `tests.rs` on `main` `930e8b4`. It ran on the GPU there and was not skipped: DXC loaded, and there was no skip line with `--nocapture`. So, as on the RTX 5070 Ti, RTX 4060 and RDNA2 iGPU above, plain `min` / `max` on Ampere with this driver already give the RDNA2 `-0` / `+0` answers for the cases in the test. The test does not fail without the fix on any GPU reported so far. **Not tested** - A release build, AMD / wave64, WARP, a retail title. _Run and written with Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:02 UTC · original

An RDNA4 / Linux (Wine + vkd3d-proton) data point for head 052af4d on its base 930e8b4. It adds the wave64 case and an AMD driver where min / max come from RADV.

Tested

  • AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.3.1, wave32 and wave64), Ryzen 9 9900X, CachyOS (Linux 7.3), Wine (GE-Proton11-14) with vkd3d-proton v3.1 plus the #257 patch, DXC 1.9.2609.5, Rust stable, release, x86_64-pc-windows-gnu (llvm-mingw).
  • cargo test -p xcl --lib --release --target x86_64-pc-windows-gnu, test binary run under Wine with --test-threads=4 --skip jumps_to_outer_loop_heads_are_structured: 702 passed, 5 failed, 21 ignored, no SKIPPED lines. Not the whole workspace: only the xcl lib tests.
  • Failures, none near this change: gpu_f64_roots, gpu_f64_math_random, gpu_nonfused_mad_and_mac_prevent_fma_contraction, xma2_source_voice_decodes_and_manages_lifetime, pe::tests::parses_own_test_binary_tls.
  • gpu_min_max_f32_f16_order_negative_zero and gpu_atomic_fmin_fmax_negative_zero pass on both wave sizes.
  • Negative control: 930e8b4 with only crates/xcl/src/gpu/recomp/tests.rs taken from this PR gives the same 702 / 5 / 21, and the new test passes. So here, as in the reports above, plain min / max already order -0 below +0 on the GPU, and this test cannot tell main from the PR on this adapter.
  • The same check for v_med3_f32 (zeros of both signs in all operand orders, plus the clamp med3(-0, 0, 1)) also passes on current main (b7aa9f3, which has the plain chain), so I have no failing case for v_med3 here either. The PR leaves med3f as it is.

Not tested

  • The regression run (a retail title under Wine; nothing posted here).
  • jumps_to_outer_loop_heads_are_structured: the process dies in vkd3d-proton's d3d12core.dll on this setup (#1425), so I skipped it.
  • Windows, NVIDIA, WARP.

AI use

  • Claude Code (Claude Sonnet 5.5) ran the builds and tests above on my machine and wrote this report.
**@⁠pablogonz12** on GitHub · 2026-11-24 17:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7138602407) An RDNA4 / Linux (Wine + vkd3d-proton) data point for head `052af4d` on its base `930e8b4`. It adds the wave64 case and an AMD driver where `min` / `max` come from RADV. **Tested** - AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.3.1, wave32 and wave64), Ryzen 9 9900X, CachyOS (Linux 7.3), Wine (GE-Proton11-14) with vkd3d-proton v3.1 plus the #257 patch, DXC 1.9.2609.5, Rust stable, release, `x86_64-pc-windows-gnu` (llvm-mingw). - `cargo test -p xcl --lib --release --target x86_64-pc-windows-gnu`, test binary run under Wine with `--test-threads=4 --skip jumps_to_outer_loop_heads_are_structured`: **702 passed, 5 failed, 21 ignored**, no `SKIPPED` lines. Not the whole workspace: only the `xcl` lib tests. - Failures, none near this change: `gpu_f64_roots`, `gpu_f64_math_random`, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `xma2_source_voice_decodes_and_manages_lifetime`, `pe::tests::parses_own_test_binary_tls`. - `gpu_min_max_f32_f16_order_negative_zero` and `gpu_atomic_fmin_fmax_negative_zero` pass on both wave sizes. - Negative control: `930e8b4` with only `crates/xcl/src/gpu/recomp/tests.rs` taken from this PR gives the same 702 / 5 / 21, and the new test passes. So here, as in the reports above, plain `min` / `max` already order -0 below +0 on the GPU, and this test cannot tell `main` from the PR on this adapter. - The same check for `v_med3_f32` (zeros of both signs in all operand orders, plus the clamp `med3(-0, 0, 1)`) also passes on current `main` (`b7aa9f3`, which has the plain chain), so I have no failing case for `v_med3` here either. The PR leaves `med3f` as it is. **Not tested** - The regression run (a retail title under Wine; nothing posted here). - `jumps_to_outer_loop_heads_are_structured`: the process dies in vkd3d-proton's `d3d12core.dll` on this setup (#1425), so I skipped it. - Windows, NVIDIA, WARP. **AI use** - Claude Code (Claude Sonnet 5.5) ran the builds and tests above on my machine and wrote this report.
Author
Owner

@⁠throny on GitHub · 2026-11-24 19:55 UTC · original

Two contributors checked independently and found that #1577 solves the same problem (for #1282) in a different way: #1607, group D3. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-24 19:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7142778917) <!-- xcl-1607-hint:D3 --> Two contributors checked independently and found that #1577 solves the same problem (for #1282) in a different way: #1607, group D3. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 00:12 UTC · original

Fair point — comparing with #1577, it covers the same ground (v_min/v_max/v_min3/v_max3 for f16/f32) plus v_pk_min/max_f16 and v_med3_*, so it's the more complete fix for #1282. This PR is redundant; closing it in favour of #1577. Thanks for the hint.

**@⁠DavidM1911** on GitHub · 2026-11-25 00:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1348#issuecomment-7148272269) Fair point — comparing with #1577, it covers the same ground (v_min/v_max/v_min3/v_max3 for f16/f32) plus v_pk_min/max_f16 and v_med3_*, so it's the more complete fix for #1282. This PR is redundant; closing it in favour of #1577. Thanks for the hint.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.