Skip to content

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

Closed
dadnotdaddy wants to merge 1 commit into
xcl-dev:mainfrom
dadnotdaddy:fix-679
Closed

dadnotdaddy wants to merge 1 commit into
xcl-dev:mainfrom
dadnotdaddy:fix-679

Conversation

@dadnotdaddy

Copy link
Copy Markdown

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

…-dev#679)

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 <noreply@anthropic.com>
@dadnotdaddy

Copy link
Copy Markdown
Author

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

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: v_fma_legacy_f32 / v_fmac_legacy_f32 return -0 for a zero product plus -0

3 participants