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

Closed
DavidM1911 wants to merge 1 commit from upstream-pr/1308 into main
DavidM1911 commented 2026-11-24 14:34:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:34:03Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:6584178737 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1308). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T14:34:03Z. --- `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.
futurepro62 commented 2026-11-24 15:06:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:43:35Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7134846609 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1308#issuecomment-7134846609). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T14:43:35Z. --- 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.
DavidM1911 commented 2026-11-24 16:07:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:42:01Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7136464214 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1308#issuecomment-7136464214). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:42:01Z. --- 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!
upstream-sync closed this pull request 2026-11-24 21:05:30 +00:00
ivall commented 2026-11-24 21:09:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-24T20:49:58Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7144116057 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1308#issuecomment-7144116057). Originally posted by [ivall](https://github.com/ivall) on 2026-11-24T20:49:58Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1298
No description provided.