Recompiler: legacy FMA with a zero product returns +0 for c = -0 (#679) #715

Closed
dadnotdaddy wants to merge 1 commit from upstream-pr/720 into main
dadnotdaddy commented 2026-11-24 04:03:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by dadnotdaddy on 2026-11-24T04:03:49Z.


Fixes #679. With a zero factor, fma_legacy returned c; the hardware returns c + (+0), so c = -0 gave -0 instead of +0. The helper now returns asfloat(select(c == 0.0f, 0u, asuint(c))): on the bits, so DXC can't fold it back to c (the approach the issue suggests).
Test: gpu_fma_legacy_with_a_zero_factor_adds_plus_zero, VOP3 and VOP2 forms, c = -0 with 05, -05, 5*-0, 0inf, -0NaN, plus pass-through cases. Fails on main (lane 0 returns 0x80000000), passes with the fix on an RTX 2070 SUPER; cargo test --workspace passes.
Overlaps draft #670 (same bug, precise add instead of bits, bundled with an XAsync change); this is the fix alone.
AI-assisted (Claude Code).

<!-- greyfinch-sync:ivall/xcl:issue:6574342727 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/720). Originally posted by [dadnotdaddy](https://github.com/dadnotdaddy) on 2026-11-24T04:03:49Z. --- Fixes #679. With a zero factor, `fma_legacy` returned `c`; the hardware returns `c + (+0)`, so c = -0 gave -0 instead of +0. The helper now returns `asfloat(select(c == 0.0f, 0u, asuint(c)))`: on the bits, so DXC can't fold it back to `c` (the approach the issue suggests). Test: `gpu_fma_legacy_with_a_zero_factor_adds_plus_zero`, VOP3 and VOP2 forms, c = -0 with 0*5, -0*5, 5*-0, 0*inf, -0*NaN, plus pass-through cases. Fails on main (lane 0 returns 0x80000000), passes with the fix on an RTX 2070 SUPER; `cargo test --workspace` passes. Overlaps draft #670 (same bug, `precise` add instead of bits, bundled with an XAsync change); this is the fix alone. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 06:59:39 +00:00
dadnotdaddy commented 2026-11-24 07:06:09 +00:00 (Migrated from github.com)

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


Closing in favour of #670; the bit-based version and its test are suggested there.

<!-- greyfinch-sync:ivall/xcl:comment:7121798062 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/720#issuecomment-7121798062). Originally posted by [dadnotdaddy](https://github.com/dadnotdaddy) on 2026-11-24T04:11:58Z. --- Closing in favour of #670; the bit-based version and its test are suggested there.
MesshM commented 2026-11-24 07:06:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T04:14:40Z.


Test run of 2b5f6741f37542281d388df748737f9fad39a58f on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_fma_legacy_with_a_zero_factor_adds_plus_zero passes, VOP3 and VOP2 forms.

Review: Returning c + (+0) on the bits (select(c == 0.0f, 0u, asuint(c))) gives +0 for c = −0 and keeps every other c, and DXC cannot fold it back to c. Related to #719, which tests the same instruction and describes a zero product as "returning c"; that is exactly the case this PR corrects for c = −0. None of #719's cases uses c = −0, so the two do not conflict, but #719's wording could say c + 0. I found nothing to change here.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

<!-- greyfinch-sync:ivall/xcl:comment:7121839864 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/720#issuecomment-7121839864). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:14:40Z. --- Test run of `2b5f6741f37542281d388df748737f9fad39a58f` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **702 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 661 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `gpu_fma_legacy_with_a_zero_factor_adds_plus_zero` passes, VOP3 and VOP2 forms. **Review:** Returning `c + (+0)` on the bits (`select(c == 0.0f, 0u, asuint(c))`) gives +0 for c = −0 and keeps every other c, and DXC cannot fold it back to `c`. **Related to #719**, which tests the same instruction and describes a zero product as "returning c"; that is exactly the case this PR corrects for c = −0. None of #719's cases uses c = −0, so the two do not conflict, but #719's wording could say c + 0. I found nothing to change here. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
lordon1a commented 2026-11-24 07:06:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by lordon1a on 2026-11-24T04:15:49Z.


Independent test report on 2b5f674:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build, DXC 1.9.2609.5 (01b62ad4)
  • Command: cargo test -p xcl --lib gpu_fma_legacy_with_a_zero_factor_adds_plus_zero -- --nocapture
  • Result: 1 passed, 0 failed, 0 ignored in 0.71s

Not tested

  • AMD / wave64, Intel GPU, retail title (xcl-smoke)

AI use

  • Antigravity (Google DeepMind agent) — fetched 2b5f674 in a detached worktree, audited the diff, ran the test suite, and posted this report.
<!-- greyfinch-sync:ivall/xcl:comment:7121857918 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/720#issuecomment-7121857918). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T04:15:49Z. --- Independent test report on `2b5f674`: **Tested** - Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver `616.64`, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), `rustc 1.100.0` (`x86_64-pc-windows-gnullvm`), debug build, DXC `1.9.2609.5` (`01b62ad4`) - Command: `cargo test -p xcl --lib gpu_fma_legacy_with_a_zero_factor_adds_plus_zero -- --nocapture` - Result: **1 passed, 0 failed, 0 ignored** in `0.71s` **Not tested** - AMD / wave64, Intel GPU, retail title (`xcl-smoke`) **AI use** - Antigravity (Google DeepMind agent) — fetched `2b5f674` in a detached worktree, audited the diff, ran the test suite, and posted this report.

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