Recompiler: apply abs and neg bitwise for v_cmp_class_f32 #1308

Closed
mahfuzinam0045-spec wants to merge 2 commits from upstream-pr/1318 into main
mahfuzinam0045-spec commented 2026-11-24 14:39:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T14:39:59Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:6584303472 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1318). Originally posted by [mahfuzinam0045-spec](https://github.com/mahfuzinam0045-spec) on 2026-11-24T14:39:59Z. --- 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.
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:47:07Z.


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

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


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.

<!-- greyfinch-sync:ivall/xcl:comment:7136246908 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1318#issuecomment-7136246908). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:34:08Z. --- 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.
mahfuzinam0045-spec commented 2026-11-24 17:06:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T16:26:59Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7137683393 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1318#issuecomment-7137683393). Originally posted by [mahfuzinam0045-spec](https://github.com/mahfuzinam0045-spec) on 2026-11-24T16:26:59Z. --- 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.
futurepro62 commented 2026-11-24 17:06:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:51:49Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7138323014 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1318#issuecomment-7138323014). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T16:51:49Z. --- 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.
upstream-sync closed this pull request 2026-11-24 21:05:33 +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:50:02Z.


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:7144117582 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7144117582). Originally posted by [ivall](https://github.com/ivall) on 2026-11-24T20:50:02Z. --- 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.
DavidM1911 commented 2026-11-26 05:05:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:53:06Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7182987433 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1318#issuecomment-7182987433). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T04:53:06Z. --- 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

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!1308
No description provided.