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

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

@⁠dadnotdaddy on GitHub · 2026-11-24 04:03 UTC · original
dadnotdaddy:fix-679 → main · +37 −1 · 2 files · 1 commits · closed without merging

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).

**@⁠dadnotdaddy** on GitHub · 2026-11-24 04:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/720) `dadnotdaddy:fix-679` → `main` · +37 −1 · 2 files · 1 commits · closed without merging 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).
v_fma_legacy_f32 / v_fmac_legacy_f32 with a zero factor (inf and NaN
included) add c to a +0 product, so c = -0 gives +0. The fma_legacy
helper returned c. The zero is cleared on the bits, as DXC folds
select(c == 0.0f, 0.0f, c) back to c.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:32 +00:00
github-bot closed this pull request 2026-11-26 04:30:32 +00:00
Author
Owner

@⁠dadnotdaddy on GitHub · 2026-11-24 04:11 UTC · original

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

**@⁠dadnotdaddy** on GitHub · 2026-11-24 04:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/720#issuecomment-7121798062) Closing in favour of #670; the bit-based version and its test are suggested there.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:14 UTC · original

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.

**@⁠MesshM** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/720#issuecomment-7121839864) 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.
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 04:15 UTC · original

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.
**@⁠lordon1a** on GitHub · 2026-11-24 04:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/720#issuecomment-7121857918) 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

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