Recompiler: v_cmp_class applies abs/neg on the sign bit, not as float ops #1308

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

@⁠DavidM1911 on GitHub · 2026-11-24 14:34 UTC · original
DavidM1911:fix-1281-cmp-class → main · +69 −16 · 2 files · 1 commits · closed without merging

v_cmp_class_f32 applied VOP3 abs/neg through fsrc(), which emits asfloat() + float abs()/neg(). On RDNA2 those modifiers are bitwise sign-bit operations: a float abs() flushes f32 subnormals to +0.0 under D3D12's default FTZ mode (class bits 7/4 misread as 6/5) and can quiet an sNaN into a qNaN (bit 0 vs bit 1). The unconditional asfloat() round-trip risked the same even without modifiers.

The f16 path already did this bitwise; f64 applied abs/neg on the sign bit but still round-tripped through double for fclass64.

What is in it

  • vopc() handles class for f32 before fsrc: abs -> & 0x7FFFFFFF, neg -> ^ 0x80000000 on the raw uint, then fclass_u32(uint) on bits directly (same shape as fclass16).
  • v_cmp*_class_f64 passes (lo, hi) to fclass64_u32(uint l, uint h) instead of asdouble/asuint round-trip; abs/neg already acted on the high word's sign bit.
  • New GPU test gpu_cmp_class_f32_preserves_denormals_and_snan: abs(-subnormal) classifies as +subnormal, neg(sNaN) stays sNaN, plus plain sNaN/qNaN/subnormal checks, on both wave32 and wave64.
  • f64_class_compare_vopc_and_vop3 updated for the new helper name/signature.

Fixes #1281

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.
  • cargo test -p xcl --lib: 707 passed, 1 failed (coherent_buffer_sanitizes_console_flags_and_state — the known flake from #913; passes standalone), 21 ignored.
  • cargo test --workspace: lib suite as above; one run of the lib binary aborted with 0xc0000005 under parallel load before completing — rerun completed cleanly, same flake class as the d3d12x filter noted on main.

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 1fee31e:

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

Not tested

macOS / Linux (crate does not build there).

AI use

Devin (Cognition), frontier model. Implemented the fix and tests from the issue's analysis; ran the suites and smokes above.

**@⁠DavidM1911** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1308) `DavidM1911:fix-1281-cmp-class` → `main` · +69 −16 · 2 files · 1 commits · closed without merging `v_cmp_class_f32` applied VOP3 `abs`/`neg` through `fsrc()`, which emits `asfloat()` + float `abs()`/`neg()`. On RDNA2 those modifiers are bitwise sign-bit operations: a float `abs()` flushes f32 subnormals to `+0.0` under D3D12's default FTZ mode (class bits 7/4 misread as 6/5) and can quiet an sNaN into a qNaN (bit 0 vs bit 1). The unconditional `asfloat()` round-trip risked the same even without modifiers. The f16 path already did this bitwise; f64 applied abs/neg on the sign bit but still round-tripped through `double` for `fclass64`. ## What is in it - `vopc()` handles `class` for `f32` before `fsrc`: `abs` -> `& 0x7FFFFFFF`, `neg` -> `^ 0x80000000` on the raw `uint`, then `fclass_u32(uint)` on bits directly (same shape as `fclass16`). - `v_cmp*_class_f64` passes `(lo, hi)` to `fclass64_u32(uint l, uint h)` instead of `asdouble`/`asuint` round-trip; abs/neg already acted on the high word's sign bit. - New GPU test `gpu_cmp_class_f32_preserves_denormals_and_snan`: `abs(-subnormal)` classifies as `+subnormal`, `neg(sNaN)` stays sNaN, plus plain sNaN/qNaN/subnormal checks, on both wave32 and wave64. - `f64_class_compare_vopc_and_vop3` updated for the new helper name/signature. Fixes #1281 ## 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. - `cargo test -p xcl --lib`: 707 passed, 1 failed (`coherent_buffer_sanitizes_console_flags_and_state` — the known flake from #913; passes standalone), 21 ignored. - `cargo test --workspace`: lib suite as above; one run of the lib binary aborted with 0xc0000005 under parallel load before completing — rerun completed cleanly, same flake class as the d3d12x filter noted on main. ## 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 `1fee31e`: ``` xcl-smoke v1 commit: 1fee31ee024b682f37d5469e61a090f661eac989 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1440 (PresentX 1440) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14553 MB ``` ## Not tested macOS / Linux (crate does not build there). ## AI use Devin (Cognition), frontier model. Implemented the fix and tests from the issue's analysis; ran the suites and smokes above.
v_cmp_class_f32 went through fsrc(), which emits asfloat() + abs()/neg()
float operations: under D3D12's default FTZ mode that flushes f32
subnormals to +-0.0 (misclassifying class bits 7/4) and can quiet an
sNaN into a qNaN (bit 0 vs bit 1). The asfloat() round-trip also risked
denormal flush and NaN canonicalization even without modifiers.

Handle "class" before fsrc for f32: abs/neg are bitwise sign-bit ops
(& 0x7FFFFFFF / ^ 0x80000000) on the raw uint, and fclass_u32() works
on bits directly, matching fclass16. fclass64 becomes fclass64_u32(l,h)
for the same reason in the 64-bit path.

New GPU test gpu_cmp_class_f32_preserves_denormals_and_snan covers
abs(neg subnormal) -> +subnormal and neg(sNaN) staying sNaN; the f64
emission test is updated for the new helper.

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

@⁠futurepro62 on GitHub · 2026-11-24 14:43 UTC · original · edited 2026-11-24 14:47 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 1fee31e (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_cmp_class_f32_preserves_denormals_and_snan.
  • 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.
  • #1308, #1309 and #1318 all fix #1281 the same way (VOP3 abs / neg on v_cmp_class_f32 applied to the sign bit); all three were opened within six minutes, #1308 first.

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 14:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/1308#issuecomment-7134846609) · edited 2026-11-24 14:47 UTC Full-suite run, since this PR has no test report yet. Tested exact head `1fee31e` (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_cmp_class_f32_preserves_denormals_and_snan`. - 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. - #1308, #1309 and #1318 all fix #1281 the same way (VOP3 abs / neg on `v_cmp_class_f32` applied to the sign bit); all three were opened within six minutes, #1308 first. **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

@⁠DavidM1911 on GitHub · 2026-11-24 15:42 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, 21 ignored. (One run aborted with 0xc0000005 under parallel scheduling; clean on rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 15:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1308#issuecomment-7136464214) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 21 ignored. (One run aborted with 0xc0000005 under parallel scheduling; clean on rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠ivall on GitHub · 2026-11-24 20:49 UTC · original

Closing this as a duplicate of #1306 (group D2 in #1607), which makes the same f32 change and was opened first. The f64 part here hands the two words to the helper instead of asdouble of them. main already applies abs / neg to the sign bit there, so no result changes.

This says nothing about the quality of the code here. If this PR covers a case the other one does not, or #1306 is closed without being merged, say so and I'll reopen it.

Thank you for the work.

AI use: Claude Code (Claude Opus 5.5) read the diffs and the checks in #1607 and wrote this comment, on the maintainer's behalf.

**@⁠ivall** on GitHub · 2026-11-24 20:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/1308#issuecomment-7144116057) Closing this as a duplicate of #1306 (group D2 in #1607), which makes the same f32 change and was opened first. The f64 part here hands the two words to the helper instead of `asdouble` of them. `main` already applies abs / neg to the sign bit there, so no result changes. This says nothing about the quality of the code here. If this PR covers a case the other one does not, or #1306 is closed without being merged, say so and I'll reopen it. Thank you for the work. AI use: Claude Code (Claude Opus 5.5) read the diffs and the checks in #1607 and wrote this comment, on the maintainer's behalf.

Pull request closed

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