Skip to content

Recompiler: apply ABS / NEG on v_mov_b32, v_cndmask_b32 and two cvts - #802

Open
upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:fix/vop-abs-neg
Open

upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:fix/vop-abs-neg

Conversation

@upipibi

@upipibi upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The VOP3 (and SDWA / DPP16) forms of v_mov_b32, v_cndmask_b32, v_cvt_f32_f16 and v_cvt_f64_f32 take the ABS / NEG source modifiers, and XCL dropped them on both backends: the four arms used the raw source, while every other float source goes through fsrc / fh / f64v. v_cndmask_b32_e64 v5, -v1, |v2|, vcc with v1 = 1.0, v2 = -2.0 gave 1.0 / -2.0 where -1.0 / 2.0 is right.

References: the RDNA 2 ISA says of V_CNDMASK_B32 and V_MOV_B32 that floating-point modifiers are valid and the instruction "is suitable for negating or taking the absolute value of a floating-point value" (VOP2 opcode 1, VOP1 opcode 1, with the example v_mov_b32 v0, -v1). LLVM folds fneg / fabs of select operands into V_CNDMASK_B32_e64 (VOPSelectModsPat, SIInstructions.td), and its MC tests encode v_cndmask_b32_e64 v5, -v1, |v2|, vcc (gfx10_asm_vop2.s), v_cvt_f32_f16_e64 v5, -v1 and v_cvt_f64_f32_e64 v[5:6], -v1 (gfx10_asm_vop1.s). LLVM itself never puts modifiers on v_mov_b32 (VOPProfile_MOV has none); the ISA text is the only source for that one.

The modifiers are applied on the sign bit, as valu64 already does for f64 sources (abs clears it, then neg flips it). The move and the select stay untyped, so a NaN keeps its payload and -0 and denormals pass bit-exact. For v_cvt_f32_f16 they act on bit 15 of the f16 input, for v_cvt_f64_f32 on the f32 input.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: helper sign_mods, used by the v_mov_b32 / v_mov_fed_b32, v_cndmask_b32 and v_cvt_f32_f16 arms of valu and the v_cvt_f64_f32 arm of valu64.
  • crates/xcl/src/gpu/dxil/lower_valu.rs, lower_wide.rs (second commit): the same on the direct translator. Lw::sign_mod applies abs / neg on the sign bit; it is used by the v_mov_b32 / v_mov_fed_b32, v_cndmask_b32 and v_cvt_f32_f16 arms and by v_cvt_f64_f32 in valu64.
  • crates/xcl/src/gpu/recomp/tests.rs: GPU test gpu_abs_neg_on_move_select_and_conversions. v_cndmask_b32_e64 -v1, |v2| with VCC alternating per lane, on (1.0, -2.0), a quiet NaN with a payload against a negative signalling NaN, (-0, -0) and denormals; v_mov_b32_e64 -v1 and -|v2| on the same inputs; v_cvt_f32_f16_e64 -v and |v| on 1.0, -0, -2.0, 0.5; v_cvt_f64_f32_e64 -v and |v| on 1.0, -0, -3.5, 0.25. All results compared as bits.

Tested

  • AMD, run by oni-swr (comment, thanks) at the exact head fed16e7, as-is: Radeon RX 7800 XT (RDNA3, native wave64, driver 32.0.31035.1003), Windows 11, debug, DXC 1.9.0.5512. gpu_abs_neg_on_move_select_and_conversions passes with XCL_DIRECT_DXIL=0 and =1. gpu_ tests: 135 passed, 1 failed with =0; 134 passed, 2 failed with =1. Workspace (--test-threads=4): 1154 passed, 1 failed. The failures aren't this PR's. fuzz_validate_and_gpu_1 (seed 722) is the known RDNA3 failure on main. gpu_image_get_resinfo_1d_array on the direct path comes from this head's base cbc296a, which predates Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046's fix for it (5ebaf3eb).
  • NVIDIA GeForce RTX 3070, driver 616.56, AMD Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0, debug
  • Rebased onto main cbc296a (one conflict: main changed v_rcp_f64 to rcp_d; kept that). At fed16e7: the new test passes with XCL_DIRECT_DXIL=0 and 1; gpu_ tests 135 passed with XCL_DIRECT_DXIL=0, 134 passed and 1 failed with 1. The failure is gpu_image_get_resinfo_1d_array, which fails on main too (Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046 fixes it). dxil units: 151 passed.
  • Before the second commit, the new test failed with XCL_DIRECT_DXIL=1 at its first assertion (lane 0 v_cndmask_b32 -v1, |v2| gave 0xC0000000, expected 0x40000000).
  • Earlier, on the first version:
    • cargo test --workspace --no-fail-fast -- --test-threads=4 on 228f8e9: 705 passed, 0 failed, 41 ignored
    • SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64)
    • The new test fails on main (d5442d2) without the emit.rs change, at its first assertion: lane 0 v_cndmask_b32 -v1, |v2| gave 0xC0000000 (-2.0), expected 0x40000000 (2.0). It passes with the change.

Regression run

Pair for the current head fed16e7 against main 426a5a7, run by ThiagoAlexsander on the retail title (comment, thanks): RTX 5080 16 GB, scripts/smoke.ps1 -Seconds 60. Pasted as printed.

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: b6841dce
seconds: 60
exit: 0x0
frames shown: 1529 (PresentX 1529)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15235 MB
xcl-smoke v1
commit: fed16e7da66f8fbd563146123485168fd759fb96
gpu: NVIDIA GeForce RTX 5080
title: b6841dce
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15166 MB

Earlier pair, on the first version (228f8e9, HLSL change only), run by eizispark on an AMD Radeon RX 9070 XT (thanks):

main:

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14847 MB

PR:

xcl-smoke v1
commit: 228f8e920d1c45bfbeea77a978aa41b7af19587e
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1663 (PresentX 1663)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14860 MB

Not tested

  • Retail titles on NVIDIA / wave32 (the smoke run above is AMD RDNA4), AMD runs beyond oni-swr's above, and native wave64 on NVIDIA (the test's wave64 program ran in the split form on the 3070).
  • How often a title's shaders use these forms: no census over a shader pack was run.
  • Whether the console honours NEG / ABS on v_mov_b32: the ISA says so, but no compiler I could check emits it.
  • SDWA and DPP16 forms of the four instructions: they take the same Mods and now the same path, but the test uses VOP3 only.

AI use

  • AI-assisted (Claude Code, Claude Opus 5.5): found the bug in a read-through of the recompiler, checked it against the ISA and LLVM, wrote the fix, the test and this description, and ran the tests above.

🤖 Generated with Claude Code

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@eizispark, thanks again for the #761 pair. If you have time for more, these four of ours also only need the xcl-smoke pair (main plus head, same title and duration); they're recompiler and disassembler changes:

I'll copy the blocks into each Regression run with credit. No pressure if you're busy.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 228f8e920d1c45bfbeea77a978aa41b7af19587e on AMD RDNA4. I merged it onto current main e50836b 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: 705 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 664 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_abs_neg_on_move_select_and_conversions passes.

Review: ABS / NEG are applied on the bits (clear / flip the sign bit at the operand's width), which keeps NaN payloads and matches how the hardware applies float modifiers to moves and selects. I found nothing to change.

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.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head 228f8e920d1c45bfbeea77a978aa41b7af19587e.

Code Review

  • Clean bit-level sign_mods helper (abs clears the sign bit first, then neg flips it, preserving NaN payloads, -0, and denormals) applied to v_mov_b32 / v_mov_fed_b32, v_cndmask_b32, v_cvt_f32_f16 (16-bit sign 0x8000), and v_cvt_f64_f32. No issues found.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 705 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific test (ok, executed on RTX 5080, not skipped):
    • gpu::recomp::tests::gpu_abs_neg_on_move_select_and_conversions
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • AMD/wave64 hardware (already covered above), release build, and retail titles.

AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.

@eizispark

Copy link
Copy Markdown

Hardware check of 228f8e920d1c45bfbeea77a978aa41b7af19587e (verified clean merge with main beaa245): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 705 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none)
  • cargo test -p xcl --lib gpu_abs_neg_on_move_select_and_conversions: 1 passed, 0 failed

Regression run
main (f4ce27c):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14847 MB

PR (228f8e9):

xcl-smoke v1
commit: 228f8e920d1c45bfbeea77a978aa41b7af19587e
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1663 (PresentX 1663)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14860 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @eizispark: both blocks are now in Regression run, credited.

@SlopTart

Copy link
Copy Markdown

2|
3|AMD/wave64 + release-build datapoint - the axes your row lists as not tested.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross x86_64-pc-windows-gnu, release profile, XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.
6|
7|Merged state: head 228f8e9 onto main beaa245, clean merge.
8|
9|Full suite, cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 10 failed, 41 ignored (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio firing that run (~2/5 rate, PR-independent). Nothing new fails. Your test passes bit-for-bit on RDNA3: gpu_abs_neg_on_move_select_and_conversions ok.
10|
11|Not tested: retail titles (none here), Windows, RDNA4.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

upipibi and others added 2 commits November 24, 2026 21:20
The VOP3, SDWA and DPP16 forms of v_mov_b32, v_cndmask_b32,
v_cvt_f32_f16 and v_cvt_f64_f32 carry the ABS / NEG source modifiers,
but these four arms used the raw source and dropped them, so
`v_cndmask_b32_e64 v5, -v1, |v2|, vcc` selected v1 / v2 unchanged.

The RDNA 2 ISA says of V_CNDMASK_B32 and V_MOV_B32 that floating-point
modifiers are valid and the instruction "is suitable for negating or
taking the absolute value of a floating-point value"; LLVM folds fneg /
fabs of select operands into V_CNDMASK_B32_e64 (VOPSelectModsPat) and
its MC tests encode these forms (gfx10_asm_vop2.s, gfx10_asm_vop1.s).

The modifiers are applied on the sign bit (abs clears it, then neg
flips it), as valu64 already does for f64 sources: the move and select
stay untyped, so NaN payloads, -0 and denormals pass bit-exact. For
v_cvt_f32_f16 they act on bit 15 of the f16 input, for v_cvt_f64_f32 on
the f32 input.

New GPU test gpu_abs_neg_on_move_select_and_conversions covers all four
with NaN, -0 and denormal inputs; it fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The direct translator dropped the same modifiers as the HLSL path did.
They act on the sign bit (Lw::sign_mod), on bit 15 of the f16 input of
v_cvt_f32_f16 and on the f32 input of v_cvt_f64_f32.
gpu_abs_neg_on_move_select_and_conversions failed with XCL_DIRECT_DXIL=1
at its first assertion and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@raylitebull

Copy link
Copy Markdown
Member

Diff review on \ ed16e7\ (\lower_valu.rs, \lower_wide.rs, \emit.rs, \ ests.rs) looks clean, and \Build and test\ is green. Two items remaining before merge: update Regression run in the PR body from \228f8e9\ to \ ed16e7\ (to pass \PR description), and add an AMD GPU verification run covering \ ed16e7\ (with \XCL_DIRECT_DXIL=1\ and \

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@raylitebull The smoke pair in the body is a run of 228f8e9, so I can't just change the commit to fed16e7: the block has to name the head that was run. I've asked for a fresh pair at fed16e7 and an AMD run in #1607 (request), and I'll paste them here when they come.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Test report: AMD Radeon RX 7800 XT (RDNA3, native wave64) for head fed16e7da66f8fbd563146123485168fd759fb96 (requested on #1607).

Setup: RX 7800 XT, driver 32.0.31035.1003, Windows 11 Pro 10.0.26200, rustc/cargo 1.100.0, debug build, DXC 1.9.0.5512 (dxc on PATH). Detached checkout of the PR head; the merge base is cbc296a, so it does not include ea088a5, and I did not merge it with current main.

Targeted (cargo test -p xcl --lib -- gpu_abs_neg_on_move_select_and_conversions --nocapture --test-threads=1):

  • XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignored
  • XCL_DIRECT_DXIL=1: 1 passed, 0 failed, 0 ignored

All gpu_ lib tests (cargo test -p xcl --lib -- gpu_ --test-threads=1):

  • XCL_DIRECT_DXIL=0: 135 passed, 1 failed, 1 ignored. The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722, res[30] = 0x1 vs CPU 0x7fffffff), the known RDNA3 failure on main. The PR does not touch it.
  • XCL_DIRECT_DXIL=1: 134 passed, 2 failed, 1 ignored. Failures: the same fuzz_validate_and_gpu_1, and gpu_image_get_resinfo_1d_array (lane 0 resinfo [4, 1, 1], expected [4, 3, 1]). The PR does not touch image resinfo. I did not run this test on main under XCL_DIRECT_DXIL=1, so I can't say whether it also fails there.

Full suite (cargo test --workspace --no-fail-fast -- --test-threads=4, env unset): 1154 passed, 1 failed, 46 ignored.

  • Lib: 1098 passed, 1 failed (fuzz_validate_and_gpu_1, as above), 26 ignored.
  • Integration binaries: all ok.
  • 7 SKIPPED lines, all in lower_dxil::tests (f16 / f32 conversion programs refused by the per-lane form). These are not coverage.

Not tested: retail title or scripts/smoke.ps1, NVIDIA, Intel, Wine/vkd3d, this PR merged with current main, gpu_image_get_resinfo_1d_array on main under XCL_DIRECT_DXIL=1.

AI use: this report was run and written by Claude Code (Claude Sonnet 5.5). I read the diff but did not change any code.

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.

8 participants