Recompiler: apply NEG_HI as ABS on v_dot2_f32_f16's f32 accumulator #1286

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

@⁠emirduran707 on GitHub · 2026-11-24 14:20 UTC · original
emirduran707:recomp-dot2-f32-f16-abs-src2 → main · +54 −0 · 2 files · 1 commits · closed without merging

v_dot2_f32_f16 applied only NEG bit 2 to its f32 accumulator (src2). NEG_HI bit 2, which for an f32 operand of a VOP3P instruction is its absolute-value modifier, was ignored. LLVM shows the encoding: its llvm.amdgcn.fdot2.ll codegen test (v_fdot2_abs_c) expects v_dot2_f32_f16 v0, v0, v1, v2 neg_hi:[0,0,1] for fabs(c). SIDefines.h defines NEG_HI = ABS, and the src2 operand is selected with SelectVOP3PModsF32 → SelectVOP3Mods, which folds fabs into it. With v1 = v2 = two halves of 1.0 and v3 = -5.0, neg_hi:[0,0,1] gives 7.0 on the hardware and gave -3.0 here.

The accumulator now takes abs for NEG_HI bit 2, then the negation for NEG bit 2, the same order v_fma_mix* uses in this file.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: the modifier.
  • crates/xcl/src/gpu/recomp/tests.rs: dot2_f32_f16_neg_hi_on_src2_is_abs (translation, no GPU) and gpu_dot2_f32_f16_abs_neg_on_src2 (neg_hi → 7.0, neg plus neg_hi → -3.0, neg alone → 7.0).

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on fb14017: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests (the new GPU test ran and passed on this adapter)
  • the translation test without the change fails (no abs on the accumulator); with it it passes; the GPU test was run only with the change

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: fb1401743aeab7fcb5fc4477f1af878b08a4689d
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1539 (PresentX 1540)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17149 MB

Not tested

  • NVIDIA and Intel GPUs, and wave32-only adapters.
  • With #1145 (SRC2 inline constants of this instruction) and #1157 (GPU tests of it): both merge cleanly with this, and #1157's cases do not set NEG_HI bit 2.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the tests and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

**@⁠emirduran707** on GitHub · 2026-11-24 14:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286) `emirduran707:recomp-dot2-f32-f16-abs-src2` → `main` · +54 −0 · 2 files · 1 commits · closed without merging `v_dot2_f32_f16` applied only NEG bit 2 to its f32 accumulator (src2). NEG_HI bit 2, which for an f32 operand of a VOP3P instruction is its absolute-value modifier, was ignored. LLVM shows the encoding: its `llvm.amdgcn.fdot2.ll` codegen test (`v_fdot2_abs_c`) expects `v_dot2_f32_f16 v0, v0, v1, v2 neg_hi:[0,0,1]` for `fabs(c)`. `SIDefines.h` defines `NEG_HI = ABS`, and the src2 operand is selected with `SelectVOP3PModsF32` → `SelectVOP3Mods`, which folds `fabs` into it. With v1 = v2 = two halves of 1.0 and v3 = -5.0, `neg_hi:[0,0,1]` gives 7.0 on the hardware and gave -3.0 here. The accumulator now takes `abs` for NEG_HI bit 2, then the negation for NEG bit 2, the same order `v_fma_mix*` uses in this file. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: the modifier. - `crates/xcl/src/gpu/recomp/tests.rs`: `dot2_f32_f16_neg_hi_on_src2_is_abs` (translation, no GPU) and `gpu_dot2_f32_f16_abs_neg_on_src2` (neg_hi → 7.0, neg plus neg_hi → -3.0, neg alone → 7.0). **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace -- --test-threads=4` on fb14017: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests (the new GPU test ran and passed on this adapter) - the translation test without the change fails (no `abs` on the accumulator); with it it passes; the GPU test was run only with the change **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19650 MB ``` this PR: ``` xcl-smoke v1 commit: fb1401743aeab7fcb5fc4477f1af878b08a4689d gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1539 (PresentX 1540) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17149 MB ``` **Not tested** - NVIDIA and Intel GPUs, and wave32-only adapters. - With #1145 (SRC2 inline constants of this instruction) and #1157 (GPU tests of it): both merge cleanly with this, and #1157's cases do not set NEG_HI bit 2. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the change, the tests and this description; I reviewed the diff and ran the tests and smoke runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_dot2_f32_f16 applied only NEG[2] to SRC2 and ignored NEG_HI[2]. SRC2
is an f32 operand, and for an f32 operand of a VOP3P instruction the
NEG_HI bit is its ABS modifier, as v_fma_mix* already decodes it:

- LLVM SIDefines.h, SISrcMods: "NEG_HI = ABS"
- AMDGPUISelDAGToDAG.cpp, SelectVOP3PModsF32 calls SelectVOP3Mods, which
  folds fabs into the ABS bit
- llvm.amdgcn.fdot2.ll, v_fdot2_abs_c: fabs(c) selects to
  "v_dot2_f32_f16 v0, v0, v1, v2 neg_hi:[0,0,1]"

So |c| was read as c, and -|c| as -c. With v1 = v2 = 0x3C003C00 and
v3 = -5.0, neg_hi:[0,0,1] gives 7.0 (was -3.0) and neg_lo:[0,0,1]
neg_hi:[0,0,1] gives -3.0 (was 7.0). ABS is applied before NEG, as in
v_fma_mix*.

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

@⁠thehollowedone on GitHub · 2026-11-24 14:31 UTC · original

Independent mixed-operand GPU check on fb14017, Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug.

I ran v_dot2_f32_f16 with mixed-sign packed inputs and lane-varying FP32 accumulators. The shader tested a plain control, ABS with a low-half sign change, ABS with a high-half sign change, and ABS followed by NEG with both packed halves negated. The PR matched all four expected outputs in all 32 wave32 lanes and 64 split-wave64 lanes. With only the parent emitter restored, the plain control still matched, and each ABS form mismatched on 16/32 wave32 lanes and 32/64 split-wave64 lanes.

The two stock tests and the added mixed-operand check passed on the PR with no skips. Synthetic shaders only. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-24 14:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7134517240) Independent mixed-operand GPU check on [`fb14017`](https://github.com/ivall/xcl/commit/fb1401743aeab7fcb5fc4477f1af878b08a4689d), Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug. I ran `v_dot2_f32_f16` with mixed-sign packed inputs and lane-varying FP32 accumulators. The shader tested a plain control, ABS with a low-half sign change, ABS with a high-half sign change, and ABS followed by NEG with both packed halves negated. The PR matched all four expected outputs in all 32 wave32 lanes and 64 split-wave64 lanes. With only the parent emitter restored, the plain control still matched, and each ABS form mismatched on 16/32 wave32 lanes and 32/64 split-wave64 lanes. The two stock tests and the added mixed-operand check passed on the PR with no skips. Synthetic shaders only. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 14:32 UTC · original · edited 2026-11-24 14:40 UTC

Full-suite run, since this PR has no test report yet. Tested exact head fb14017 (on its base 47efa2e).

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: 743 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: dot2_f32_f16_neg_hi_on_src2_is_abs, gpu_dot2_f32_f16_abs_neg_on_src2.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored, no skips.

Not tested

  • 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:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7134555134) · edited 2026-11-24 14:40 UTC Full-suite run, since this PR has no test report yet. Tested exact head `fb14017` (on its base `47efa2e`). **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`: **743 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `dot2_f32_f16_neg_hi_on_src2_is_abs`, `gpu_dot2_f32_f16_abs_neg_on_src2`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **743 passed, 0 failed, 41 ignored**, no skips. **Not tested** - 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

@⁠regiumlepidi on GitHub · 2026-11-25 00:10 UTC · original

RTX 5070 Ti: fb14017 merged into main 8e87fc7 passes its tests on the default path; the GPU test still fails with XCL_DIRECT_DXIL=1

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves), driver 617.42; Ryzen 7 9800X3D; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; Windows SDK 10.0.26100.0, DXC 1.8.2502.11; debug; no XCL_SAMPLE_*
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture, one run per cell; PR head fb1401743aeab7fcb5fc4477f1af878b08a4689d merged locally into 8e87fc7b62a87ea589ccb9ea6182f514016cf7db, no conflicts (passed / failed / ignored):
tree default XCL_DIRECT_DXIL=1
main 8e87fc7 986 / 4 / 45 985 / 5 / 45
merge 988 / 4 / 45 986 / 6 / 45
  • Default path: dot2_f32_f16_neg_hi_on_src2_is_abs and gpu_dot2_f32_f16_abs_neg_on_src2 pass. The 4 failures are fuzz_validate_and_gpu_0 to _3 (#1905, this driver), as on main
  • XCL_DIRECT_DXIL=1: those 4, offline_compute_pipeline_is_reused_by_a_second_process (fails on main too) and gpu_dot2_f32_f16_abs_neg_on_src2: wave32 lane 0 v_dot2_f32_f16 neg_hi:[0,0,1], left 3225419776 (-3.0), right 1088421888 (7.0). The PR's diff touches only recomp/emit.rs and recomp/tests.rs
  • Negative control, only the PR's tests.rs change applied to main 8e87fc7: both new tests fail on both paths; the GPU test with the values above
  • 26 SKIPPED lines in each run (18 no wave64, 1 const mask + wave64, 3 per-lane form refused, Developer Mode, d3d12SDKLayers.dll, heap windows, debug layer); none names the new tests

Not tested

  • the wave64 half of the GPU test (gpu_waves() runs wave32 only here), release build, any retail title, other GPUs or drivers

Direct translator patch
gpu_dot2_f32_f16_abs_neg_on_src2 fails with XCL_DIRECT_DXIL=1 because the direct translator has the same bug: dxil/lower_wide.rs ignores NEG_HI[2] on the accumulator. The patch below mirrors this PR there. With this PR's commit and the patch on main 8e87fc7, the new tests pass on both paths, and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 gives 988 / 4 / 45 (default) and 987 / 5 / 45 (direct); the failures are the same as on main. Take it into this PR if you like, or say if you would rather it go in a separate PR stacked on this one.

Patch (applies with git apply on this PR merged into main 8e87fc7)
diff --git a/crates/xcl/src/gpu/dxil/lower_wide.rs b/crates/xcl/src/gpu/dxil/lower_wide.rs
index 6c40030..2173572 100644
--- a/crates/xcl/src/gpu/dxil/lower_wide.rs
+++ b/crates/xcl/src/gpu/dxil/lower_wide.rs
@@ -67,6 +67,8 @@ impl Lw {
             "v_dot2_f32_f16" | "v_dot2c_f32_f16" => {
                 let c = if name == "v_dot2_f32_f16" {
                     let c = self.f(src(2));
+                    // SRC2 is f32: its NEG_HI bit is ABS (applied before NEG), as in v_fma_mix*
+                    let c = if neg_hi >> 2 & 1 == 1 { self.fabs(c) } else { c };
                     if neg >> 2 & 1 == 1 {
                         self.fneg(c)
                     } else {

AI use

  • Claude Code with Claude Opus 5.5: read the diff, ran the tests, wrote the patch and this report.
**@⁠regiumlepidi** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7148233161) **RTX 5070 Ti: `fb14017` merged into `main` `8e87fc7` passes its tests on the default path; the GPU test still fails with `XCL_DIRECT_DXIL=1`** **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves), driver 617.42; Ryzen 7 9800X3D; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; Windows SDK 10.0.26100.0, DXC 1.8.2502.11; debug; no `XCL_SAMPLE_*` - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture`, one run per cell; PR head `fb1401743aeab7fcb5fc4477f1af878b08a4689d` merged locally into `8e87fc7b62a87ea589ccb9ea6182f514016cf7db`, no conflicts (passed / failed / ignored): | tree | default | `XCL_DIRECT_DXIL=1` | |---|---|---| | `main` `8e87fc7` | 986 / 4 / 45 | 985 / 5 / 45 | | merge | 988 / 4 / 45 | 986 / 6 / 45 | - Default path: `dot2_f32_f16_neg_hi_on_src2_is_abs` and `gpu_dot2_f32_f16_abs_neg_on_src2` pass. The 4 failures are `fuzz_validate_and_gpu_0` to `_3` (#1905, this driver), as on `main` - `XCL_DIRECT_DXIL=1`: those 4, `offline_compute_pipeline_is_reused_by_a_second_process` (fails on `main` too) and `gpu_dot2_f32_f16_abs_neg_on_src2`: `wave32 lane 0 v_dot2_f32_f16 neg_hi:[0,0,1]`, left `3225419776` (-3.0), right `1088421888` (7.0). The PR's diff touches only `recomp/emit.rs` and `recomp/tests.rs` - Negative control, only the PR's `tests.rs` change applied to `main` `8e87fc7`: both new tests fail on both paths; the GPU test with the values above - 26 `SKIPPED` lines in each run (18 no wave64, 1 const mask + wave64, 3 per-lane form refused, Developer Mode, `d3d12SDKLayers.dll`, heap windows, debug layer); none names the new tests **Not tested** - the wave64 half of the GPU test (`gpu_waves()` runs wave32 only here), release build, any retail title, other GPUs or drivers **Direct translator patch** `gpu_dot2_f32_f16_abs_neg_on_src2` fails with `XCL_DIRECT_DXIL=1` because the direct translator has the same bug: `dxil/lower_wide.rs` ignores NEG_HI[2] on the accumulator. The patch below mirrors this PR there. With this PR's commit and the patch on `main` `8e87fc7`, the new tests pass on both paths, and `cargo test --workspace --locked --no-fail-fast -- --test-threads=4` gives 988 / 4 / 45 (default) and 987 / 5 / 45 (direct); the failures are the same as on `main`. Take it into this PR if you like, or say if you would rather it go in a separate PR stacked on this one. <details><summary>Patch (applies with <code>git apply</code> on this PR merged into <code>main</code> <code>8e87fc7</code>)</summary> ```diff diff --git a/crates/xcl/src/gpu/dxil/lower_wide.rs b/crates/xcl/src/gpu/dxil/lower_wide.rs index 6c40030..2173572 100644 --- a/crates/xcl/src/gpu/dxil/lower_wide.rs +++ b/crates/xcl/src/gpu/dxil/lower_wide.rs @@ -67,6 +67,8 @@ impl Lw { "v_dot2_f32_f16" | "v_dot2c_f32_f16" => { let c = if name == "v_dot2_f32_f16" { let c = self.f(src(2)); + // SRC2 is f32: its NEG_HI bit is ABS (applied before NEG), as in v_fma_mix* + let c = if neg_hi >> 2 & 1 == 1 { self.fabs(c) } else { c }; if neg >> 2 & 1 == 1 { self.fneg(c) } else { ``` </details> **AI use** - Claude Code with Claude Opus 5.5: read the diff, ran the tests, wrote the patch and this report.
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-25 08:26 UTC · original

Test report for head fb14017 as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 743 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's tests: dot2_f32_f16_neg_hi_on_src2_is_abs and gpu_dot2_f32_f16_abs_neg_on_src2 ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • AMD / native wave64; release build; a smoke run on a title; the head merged onto current main; XCL_DIRECT_DXIL=1 (this run used the default HLSL path)

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote this report; the run is mine.
**@⁠xpatfussy69x** on GitHub · 2026-11-25 08:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7157022513) Test report for head `fb14017` as pushed (not merged onto current `main`) – NVIDIA, wave32. **Tested** - NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5 - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 743 passed, 0 failed, 41 ignored - SKIPPED GPU tests on this adapter: 2 (no wave64) - this PR's tests: `dot2_f32_f16_neg_hi_on_src2_is_abs` and `gpu_dot2_f32_f16_abs_neg_on_src2` ran and passed - no `XCL_SAMPLE_*` data set (game-data tests not run) **Not tested** - AMD / native wave64; release build; a smoke run on a title; the head merged onto current `main`; `XCL_DIRECT_DXIL=1` (this run used the default HLSL path) **AI use** - Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote this report; the run is mine.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:24 UTC · original

Superseded/landed via #1979 (which preserved the emit.rs + ests.rs commit with authorship and added the lower_wide.rs XCL_DIRECT_DXIL=1 counterpart so both backends pass gpu_dot2_f32_f16_abs_neg_on_src2).

**@⁠raylitebull** on GitHub · 2026-11-25 18:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7170874515) Superseded/landed via #1979 (which preserved the emit.rs + ests.rs commit with authorship and added the lower_wide.rs XCL_DIRECT_DXIL=1 counterpart so both backends pass gpu_dot2_f32_f16_abs_neg_on_src2).
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-25 18:46 UTC · original

Closing as landed on \main\ via #1979 (\c09ccf). Thanks for preserving authorship and adding the Direct DXIL counterpart.

**@⁠emirduran707** on GitHub · 2026-11-25 18:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1286#issuecomment-7171376842) Closing as landed on \main\ via #1979 (\c09ccf\). Thanks for preserving authorship and adding the Direct DXIL counterpart.

Pull request closed

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