Skip to content

Recompiler: enforce -0.0 < +0.0 order in f16/f32 min and max (#1282) - #1577

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:recompiler/float-minmax-signed-zero
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:recompiler/float-minmax-signed-zero

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown

Adds fmin_ieee and fmax_ieee HLSL helpers so RDNA2 v_min_, v_max_, v_min3_, v_max3_, v_pk_min_f16, v_pk_max_f16, and v_med3_* over f16/f32 strictly enforce -0.0 < +0.0 across D3D12 drivers while preserving NaN suppression. Fixes #1282.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: define fmin_ieee(float, float) and fmax_ieee(float, float) in the HLSL prelude (and use them in med3f, v_min_f32, v_max_f32, v_min3_f32, v_max3_f32, v_min_f16, v_max_f16, v_min3_f16, v_max3_f16, v_pk_min_f16, and v_pk_max_f16).
  • crates/xcl/src/gpu/recomp/tests.rs: add float_minmax_uses_ieee_signed_zero_helpers and gpu_float_minmax_orders_negative_zero_below_positive_zero testing (+0.0, -0.0), (-0.0, +0.0), and qNaN suppression across Wave32 and Wave64.

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), AMD Ryzen 7 9800X3D, Windows 11 10.0.26300.9974, rustc 1.98.1 (48a229cea 2026-09-01), debug (cargo test).
  • cargo test -p xcl --lib gpu::recomp::tests::float_minmax_uses_ieee -- --test-threads=2: 1 passed, 0 failed, 0 ignored.
  • cargo test -p xcl --lib gpu::recomp::tests::gpu_float_minmax_orders -- --test-threads=2: 1 passed, 0 failed, 0 ignored.
  • cargo test --workspace -- --test-threads=2: 778 passed, 0 failed, 41 ignored (xcl --lib: 729 passed, 0 failed, 21 ignored; integration/e2e suites: 49 passed, 0 failed, 20 ignored).
  • SKIPPED runtime tests: SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.

Regression run

main:

xcl-smoke v1
commit: 082944135cd2b96288470a595861fa608eee08dc
gpu: AMD Radeon RX 9070 XT
title: b0ea61d5
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13681 MB

PR:

xcl-smoke v1
commit: 67d551ecd8a0ad97381c6e9a3c15b84d75dbd6cc
gpu: AMD Radeon RX 9070 XT
title: b0ea61d5
seconds: 60
exit: 0x0
frames shown: 1673 (PresentX 1673)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14730 MB

Not tested

  • NVIDIA, Intel Arc, and WARP adapters.

AI use

  • Antigravity (Gemini 4 Hydrogen, high): added fmin_ieee/fmax_ieee and updated f16/f32 min/max/med3 emissions in emit.rs, wrote translation and Wave32/Wave64 GPU tests, ran the workspace test suite, and prepared commit and PR description.

@hajduzsolt
hajduzsolt force-pushed the recompiler/float-minmax-signed-zero branch from ab1e636 to d6d8f11 Compare November 24, 2026 18:54
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 19:13
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1348 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.

@regiumlepidi

Copy link
Copy Markdown
Contributor

RTX 5070 Ti: d6d8f11 merged into main 8e87fc7 passes on both paths; on this GPU the GPU test also passes without the fix

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves), driver 617.42; Ryzen 7 9800X3D; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; Windows SDK 10.0.26100.0, DXC 1.8.2502.11; debug; no XCL_SAMPLE_*
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture, one run per cell; PR head d6d8f116d7398e6c702665f65b21c9505f4ca35c merged locally into 8e87fc7b62a87ea589ccb9ea6182f514016cf7db, no conflicts (passed / failed / ignored):
tree default XCL_DIRECT_DXIL=1
main 8e87fc7 986 / 4 / 45 985 / 5 / 45
merge 988 / 4 / 45 987 / 5 / 45
  • Both new tests pass on both paths. The other failures are fuzz_validate_and_gpu_0 to _3 (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905, this driver) and, with XCL_DIRECT_DXIL=1, offline_compute_pipeline_is_reused_by_a_second_process, all as on main
  • Negative control, only the PR's tests.rs change applied to main 8e87fc7: float_minmax_uses_ieee_signed_zero_helpers (HLSL text) fails, but gpu_float_minmax_orders_negative_zero_below_positive_zero passes on both paths. So this driver already orders -0 below +0 in min / max and returns the number for a qNaN operand; the GPU test does not show the bug here. A GPU whose min / max treat ±0 as equal is needed to see it fail
  • 26 SKIPPED lines in each run (18 no wave64, 1 const mask + wave64, 3 per-lane form refused, Developer Mode, d3d12SDKLayers.dll, heap windows, debug layer); none names the new tests

Not tested

  • the wave64 half of the GPU test (gpu_waves() runs wave32 only here), any GPU where the test fails without the fix, release build, any retail title

AI use

  • Claude Code with Claude Opus 5.5: read the diff, ran the tests and wrote this report.

@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1577 — Intel Arc A770 signed-zero compatibility
#1577

Tested

  • Exact clean PR head d6d8f11. GitHub confirmed the PR was open at that SHA before and after the run. I read the existing conversation, including the RTX 3060 Ti and RTX 5070 Ti reports.

  • Intel Arc A770 (32.0.101.9175), AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 26200.9974, Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), unoptimized Cargo test profile. The runner reported dxcompiler and dxil 1.9.2609.5 (DXC 01b62ad4).

  • Process-only setup: CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, CARGO_TARGET_DIR=L:/XclTooling/pr1778-2e2ee55-20261125-020159/target, TEMP=TMP=L:/XclTooling/pr1577. GPU runs used XCL_ADAPTER=A770 and XCL_DXC_DIR=$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64.

  • Prebuild outside the lock: cargo test -p xcl --lib --locked --no-run (54.18 s wall, exit 0). The commands below used the executable printed by Cargo:

    $bin = 'L:/XclTooling/pr1778-2e2ee55-20261125-020159/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe'
    $lock = 'L:/XclTooling/Invoke-ArcTest.ps1'
    $gpu = 'gpu::recomp::tests::gpu_float_minmax_orders_negative_zero_below_positive_zero'

    $env:XCL_DIRECT_DXIL = '0'
    & $bin gpu::recomp::tests::float_minmax_uses_ieee_signed_zero_helpers --exact --nocapture --test-threads=1

    & $lock -Test { & $bin $gpu --exact --nocapture --test-threads=1 }

    $env:XCL_DIRECT_DXIL = '1'
    & $lock -Test { & $bin $gpu --exact --nocapture --test-threads=1 }

    & $lock -Test { & 'L:/XclTooling/CapabilityProbe/capabilities.exe' }

  • HLSL translation test: 1 passed, 0 failed, 0 ignored, 0 SKIPPED, 832 filtered out (0.00 s harness). It checked complete translation and the signed-zero helpers in the emitted HLSL for f32/f16 scalar min/max, min3/max3 and packed f16 min/max. The translation-only test used the default logical wave64 options.

  • HLSL/DXC GPU test: 1 passed, 0 failed, 0 ignored, 0 SKIPPED, 832 filtered out (0.25 s harness, 0.41 s wall including lock). The fixture compiled HLSL with DXC as cs_6_6 and dispatched it on the Arc.

  • Direct DXIL GPU test: 1 passed, 0 failed, 0 ignored, 0 SKIPPED, 832 filtered out (0.20 s harness, 0.27 s wall including lock). The fixture's kernel_wave routes to direct_kernel when enabled, so this was a separate dispatch through the direct translator. The PR's HLSL helpers are only exercised by the HLSL path.

  • On both GPU paths, all 14 register assertions passed on each of 32 lanes (448 bit-exact comparisons per path). The assertions cover f32 and scalar f16 min/max for both mixed-sign zero operand orders, f32 min3/max3, packed f16 min/max across both halves, and f32 qNaN suppression with a finite first operand (3.0 for min and -2.0 for max). Scalar f16 checks include preservation of the upper 0xCAFE bits.

  • The D3D12 probe identified the Arc A770 (PCI 8086:56A0), WaveOps=1 and WaveLaneCountMin/Max=8/32. The fixture ran wave32 only. gpu_waves() omits wave64 on this adapter without emitting a SKIPPED line and does not select split wave64.

  • The GPU commands ran in a child PowerShell with process-scoped RemoteSigned after the default session blocked script loading. One retry acquired the lock but its output pipeline stopped on the DXC stderr diagnostic before capturing a result. Counts above come from the subsequent complete runs. Machine policy was untouched.

  • Logs: prebuild-20261125-033409.log, cpu-20261125-033531.log, gpu-hlsl-dxc-20261125-033726.log, gpu-direct-dxil-20261125-033726.log, wave-capability-20261125-033726.log.

Not tested

  • Native or split wave64 execution, GPU execution of f16 min3/max3 or med3, other adapters or drivers, a pre-fix negative control, release or full workspace suite, retail or smoke runs.

AI use

  • T3 Code / Codex (gpt-6.2-sol) inspected the fixture, ran the tests, and wrote this report from the captured results.

…#1282)

HLSL min()/max() leaves the sign of (+/-0.0, -/+0.0) driver-dependent, whereas RDNA2 IEEE mode strictly orders -0.0 < +0.0.

Add fmin_ieee/fmax_ieee helpers preserving NaN suppression while resolving two-zero inputs via sign-bit OR/AND, and use them for v_min/v_max/v_min3/v_max3/v_pk_min/v_pk_max/v_med3 over f16 and f32.

Fixes xcl-dev#1282

Assisted-by: Antigravity (Gemini 4 Hydrogen, high)
@hajduzsolt
hajduzsolt force-pushed the recompiler/float-minmax-signed-zero branch from d6d8f11 to 67d551e Compare November 25, 2026 15:24
@hajduzsolt
hajduzsolt marked this pull request as draft November 25, 2026 15:24
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 25, 2026 15:31
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_min_f32 / v_max_f32 / v_min_f16 / v_max_f16 (and 3-op forms) emit plain HLSL min/max, violating RDNA2 -0.0 < +0.0 ordering on NVIDIA/WARP

6 participants