Recompiler: apply abs and neg bitwise for v_cmp_class_f32 #1318

Closed
github-bot wants to merge 2 commits from gh-pr/1318/head into gh-pr/1318/base
Owner

@⁠mahfuzinam0045-spec on GitHub · 2026-11-24 14:39 UTC · original
mahfuzinam0045-spec:fix/recomp-v-cmp-class-f32-bitwise-modifiers → main · +81 −12 · 2 files · 2 commits · closed without merging

Apply VOP3 abs and neg modifiers bitwise for v_cmp_class_f32, and take raw uint bit patterns directly in fclass and fclass64.

Fixes #1281

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs:
    • v_cmp_class_f32: apply m.abs[0] as ({a} & 0x7FFFFFFFu) and m.neg[0] as ({a} ^ 0x80000000u) directly on the raw uint bits instead of calling Self::fsrc (abs(asfloat(u)) / (-asfloat(u))). This prevents denormal flushing and signaling NaN quieting.
    • fclass(uint u): update HLSL preamble function to accept uint u directly, eliminating the redundant asuint(asfloat(u)) round-trip.
    • fclass64(uint l, uint h) & v_cmp_class_f64: pass low and high dwords directly into fclass64(lo_hi[0].0, hi) without asdouble / asuint conversion.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat: verify emitted HLSL applies bitwise mask/flip on the sign bit and avoids asfloat.
    • gpu_cmp_class_f32_preserves_snan_and_denormals: synthetic test asserting that sNaN, qNaN, -subnormal with ABS, and sNaN with NEG match their respective class bits without being quieted or flushed.

Tested

  • Local MSVC/MinGW C toolchains (link.exe/gcc.exe) are absent on this development environment. Full validation and regression suite run via GitHub Actions CI (PR checks).
  • Logic verified against new unit tests v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat and gpu_cmp_class_f32_preserves_snan_and_denormals.

Regression run

Regression testing requires Windows SDK and DXC toolchains. Relying on project CI.

Not tested

  • End-to-end retail game titles on physical RDNA2 console hardware.

AI use

Antigravity (Gemini 3.8 Flash) was used to analyze the modifier lowering discrepancy in crates/xcl/src/gpu/recomp/emit.rs, implement bitwise modifiers on raw uint bits, update fclass and fclass64, and author the recompiler unit tests.

**@⁠mahfuzinam0045-spec** on GitHub · 2026-11-24 14:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318) `mahfuzinam0045-spec:fix/recomp-v-cmp-class-f32-bitwise-modifiers` → `main` · +81 −12 · 2 files · 2 commits · closed without merging Apply VOP3 `abs` and `neg` modifiers bitwise for `v_cmp_class_f32`, and take raw `uint` bit patterns directly in `fclass` and `fclass64`. Fixes #1281 ### What is in it - `crates/xcl/src/gpu/recomp/emit.rs`: - `v_cmp_class_f32`: apply `m.abs[0]` as `({a} & 0x7FFFFFFFu)` and `m.neg[0]` as `({a} ^ 0x80000000u)` directly on the raw `uint` bits instead of calling `Self::fsrc` (`abs(asfloat(u))` / `(-asfloat(u))`). This prevents denormal flushing and signaling NaN quieting. - `fclass(uint u)`: update HLSL preamble function to accept `uint u` directly, eliminating the redundant `asuint(asfloat(u))` round-trip. - `fclass64(uint l, uint h)` & `v_cmp_class_f64`: pass low and high dwords directly into `fclass64(lo_hi[0].0, hi)` without `asdouble` / `asuint` conversion. - `crates/xcl/src/gpu/recomp/tests.rs`: - `v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat`: verify emitted HLSL applies bitwise mask/flip on the sign bit and avoids `asfloat`. - `gpu_cmp_class_f32_preserves_snan_and_denormals`: synthetic test asserting that sNaN, qNaN, -subnormal with ABS, and sNaN with NEG match their respective class bits without being quieted or flushed. ### Tested - Local MSVC/MinGW C toolchains (`link.exe`/`gcc.exe`) are absent on this development environment. Full validation and regression suite run via GitHub Actions CI (`PR checks`). - Logic verified against new unit tests `v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat` and `gpu_cmp_class_f32_preserves_snan_and_denormals`. ### Regression run Regression testing requires Windows SDK and DXC toolchains. Relying on project CI. ### Not tested - End-to-end retail game titles on physical RDNA2 console hardware. ### AI use Antigravity (Gemini 3.8 Flash) was used to analyze the modifier lowering discrepancy in `crates/xcl/src/gpu/recomp/emit.rs`, implement bitwise modifiers on raw `uint` bits, update `fclass` and `fclass64`, and author the recompiler unit tests.
In v_cmp_class_f32, VOP3 abs and neg modifiers were previously applied through Self::fsrc, which emitted float operations abs(asfloat(u)) and (-asfloat(u)). In D3D12/DXIL, this could flush subnormals/denormals to zero and quiet signaling NaNs, distorting the class test bits. Additionally, fclass took a float parameter, forcing an asfloat / asuint conversion.

Apply abs (& 0x7FFFFFFFu) and neg (^ 0x80000000u) bitwise on the raw uint bits, matching f16 and RDNA2 hardware semantics. Update fclass to take uint u directly, and update fclass64 to take uint l, uint h directly to avoid asdouble/asuint round-trips.

Fixes #1281.

Assisted-by: Antigravity (Gemini 3.8 Flash)
Update fclass_compare_vopc_and_vop3 test assertion to match fclass64 taking raw uint parameters directly without asdouble, and scope the asfloat check in v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat so it avoids matching asfloat occurrences in the shared preamble.

Assisted-by: Antigravity (Gemini 3.8 Flash)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:33 +00:00
github-bot closed this pull request 2026-11-26 04:50:33 +00:00
Author
Owner

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

Full-suite run, since this PR has no test report yet. Tested exact head 25c44a6 (on its base 930e8b4): two tests fail, both on the expected HLSL text rather than the emitter.

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: the xcl lib run ends with 2 failed (707 passed, 21 ignored), so cargo stops before the remaining test binaries. Reproduced 3 of 3 times with cargo test -p xcl --lib -- f64_class_compare_vopc_and_vop3 v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat.
  • f64_class_compare_vopc_and_vop3 (existing test, tests.rs:474) still expects (v12) >> fclass64(asdouble(v10, v11)). With fclass64 now taking (uint l, uint h), the emitted text is (v12) >> fclass64(v10, v11), fclass64(v10, (v11 & 0x7FFFFFFFu)) and fclass64(v10, (v11 ^ 0x80000000u)), so the three contains checks need the asdouble(...) dropped.
  • v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat (new, tests.rs:7180): the emitted compare is right (fclass(((v0 & 0x7FFFFFFFu) ^ 0x80000000u))), but !t.hlsl.contains("asfloat(") checks the whole shader, and the shared helper preamble always has asfloat( (e.g. fract_f). The check needs to look at the compare line only, or for fclass(asfloat(.
  • Same head on the AMD Radeon iGPU of the 9800X3D (XCL_ADAPTER=radeon): the same two failures.
  • #1308, #1309 and #1318 all fix #1281 by applying VOP3 abs / neg on v_cmp_class_f32 to the sign bit; #1308 and #1309 were opened about five minutes before this one, and both pass the full suite here.

Not tested

  • The test binaries after the xcl lib (cargo stops at its failures), 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:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7134942736) Full-suite run, since this PR has no test report yet. Tested exact head `25c44a6` (on its base `930e8b4`): **two tests fail**, both on the expected HLSL text rather than the emitter. **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`: the xcl lib run ends with **2 failed** (707 passed, 21 ignored), so cargo stops before the remaining test binaries. Reproduced 3 of 3 times with `cargo test -p xcl --lib -- f64_class_compare_vopc_and_vop3 v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat`. - `f64_class_compare_vopc_and_vop3` (existing test, `tests.rs:474`) still expects `(v12) >> fclass64(asdouble(v10, v11))`. With `fclass64` now taking `(uint l, uint h)`, the emitted text is `(v12) >> fclass64(v10, v11)`, `fclass64(v10, (v11 & 0x7FFFFFFFu))` and `fclass64(v10, (v11 ^ 0x80000000u))`, so the three `contains` checks need the `asdouble(...)` dropped. - `v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat` (new, `tests.rs:7180`): the emitted compare is right (`fclass(((v0 & 0x7FFFFFFFu) ^ 0x80000000u))`), but `!t.hlsl.contains("asfloat(")` checks the whole shader, and the shared helper preamble always has `asfloat(` (e.g. `fract_f`). The check needs to look at the compare line only, or for `fclass(asfloat(`. - Same head on the AMD Radeon iGPU of the 9800X3D (`XCL_ADAPTER=radeon`): the same two failures. - #1308, #1309 and #1318 all fix #1281 by applying VOP3 abs / neg on `v_cmp_class_f32` to the sign bit; #1308 and #1309 were opened about five minutes before this one, and both pass the full suite here. **Not tested** - The test binaries after the xcl lib (cargo stops at its failures), 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:34 UTC · original

Test report — RTX 3060 Ti (Windows 11), cargo test -p xcl --lib on the PR head merged with current main:

2 failures (707 passed, 2 failed, 21 ignored; single-threaded run — parallel runs also intermittently abort with 0xc0000005, same harness flake seen on unmodified main):

  1. gpu::recomp::tests::f64_class_compare_vopc_and_vop3 — pre-existing test still asserts the old helper signature: it expects fclass64(asdouble(v10, v11)), but this PR changed fclass64 to take (uint l, uint h). The test needs updating to the new call shape (e.g. fclass64(v10, v11) / fclass64(v10, (v11 & 0x7FFFFFFFu))).

  2. gpu::recomp::tests::v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat (new in this PR) — assert!(!t.hlsl.contains("asfloat(")) can never hold: the shared kernel prelude emits asfloat( unconditionally (e.g. fract_f, f16tof32 helpers), regardless of which instructions the program uses. The assertion needs to be scoped to the emitted compare expression rather than the whole t.hlsl.

The GPU-side behaviour itself looks right — gpu_cmp_class_f32_preserves_snan_and_denormals passes on this card.

**@⁠DavidM1911** on GitHub · 2026-11-24 15:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7136246908) Test report — RTX 3060 Ti (Windows 11), `cargo test -p xcl --lib` on the PR head merged with current `main`: **2 failures** (707 passed, 2 failed, 21 ignored; single-threaded run — parallel runs also intermittently abort with 0xc0000005, same harness flake seen on unmodified `main`): 1. `gpu::recomp::tests::f64_class_compare_vopc_and_vop3` — pre-existing test still asserts the old helper signature: it expects `fclass64(asdouble(v10, v11))`, but this PR changed `fclass64` to take `(uint l, uint h)`. The test needs updating to the new call shape (e.g. `fclass64(v10, v11)` / `fclass64(v10, (v11 & 0x7FFFFFFFu))`). 2. `gpu::recomp::tests::v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat` (new in this PR) — `assert!(!t.hlsl.contains("asfloat("))` can never hold: the shared kernel prelude emits `asfloat(` unconditionally (e.g. `fract_f`, `f16tof32` helpers), regardless of which instructions the program uses. The assertion needs to be scoped to the emitted compare expression rather than the whole `t.hlsl`. The GPU-side behaviour itself looks right — `gpu_cmp_class_f32_preserves_snan_and_denormals` passes on this card.
Author
Owner

@⁠mahfuzinam0045-spec on GitHub · 2026-11-24 16:26 UTC · original

Thanks @⁠futurepro62 and @⁠DavidM1911 for the test reports!

Pushed commit c02943a resolving both test assertions:

  • Updated f64_class_compare_vopc_and_vop3 to match the fclass64(uint l, uint h) argument shape (dropped asdouble(...)).
  • Scoped the asfloat check in v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat to !t.hlsl.contains("fclass(asfloat(") so it doesn't match the preamble helpers.
**@⁠mahfuzinam0045-spec** on GitHub · 2026-11-24 16:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7137683393) Thanks @⁠futurepro62 and @⁠DavidM1911 for the test reports! Pushed commit `c02943a` resolving both test assertions: - Updated `f64_class_compare_vopc_and_vop3` to match the `fclass64(uint l, uint h)` argument shape (dropped `asdouble(...)`). - Scoped the `asfloat` check in `v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat` to `!t.hlsl.contains("fclass(asfloat(")` so it doesn't match the preamble helpers.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 16:51 UTC · original

Retest of the new head c02943a: both tests I reported now pass on both GPUs.

  • RTX 5070 Ti (driver 616.64), XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored.
  • AMD Radeon iGPU of the 9800X3D (RDNA2), XCL_ADAPTER=radeon, same command: 753 passed, 0 failed, 41 ignored, nothing skipped.
  • f64_class_compare_vopc_and_vop3 and v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat are ok on both.

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this comment. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 16:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7138323014) Retest of the new head `c02943a`: **both tests I reported now pass on both GPUs.** - RTX 5070 Ti (driver 616.64), `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **753 passed, 0 failed, 41 ignored**. - AMD Radeon iGPU of the 9800X3D (RDNA2), `XCL_ADAPTER=radeon`, same command: **753 passed, 0 failed, 41 ignored**, nothing skipped. - `f64_class_compare_vopc_and_vop3` and `v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat` are `ok` on both. **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this comment. I checked it before posting.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 20:50 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:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7144117582) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 04:53 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 04:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7182987433) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin

Pull request closed

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