Skip to content

Recompiler: VOP3 abs / neg on the shift-add and align ops act on the sign bit - #2058

Open
upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:fix/shift-add-sign-mods
Open

upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:fix/shift-add-sign-mods

Conversation

@upipibi

@upipibi upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Both paths dropped the VOP3 ABS / NEG source modifiers of the shift-add ops (v_lshl_add_u32, v_add_lshl_u32) and the align ops (v_alignbit_b32, v_alignbyte_b32). RDNA2 applies them to the source's sign bit, as for a float: abs is x & 0x7fffffff and neg is x ^ 0x80000000. With neg on the addend, v_lshl_add_u32 5, 2, 1 gave 21, where the hardware gives 0x80000015.

Sources for the rule: boykopovar/AnyPS5#25964 measured both opcodes with every abs/neg combination on gfx1036 (RDNA2) and gfx1201 (RDNA4) with their hardware oracle: 196/196 words match the sign-bit operations on each. boykopovar/AnyPS5#25799 measured the align ops on gfx1036: on src1, abs clears and neg flips bit 31, which a shift brings into the result. On src0 and the shift amount they can't change the result, so applying them there is harmless. With neg on src1, v_alignbit_b32 0, 1, 31 gave 0 where the hardware gives 1.

What is in it

  • recomp/emit.rs and dxil/lower_valu.rs: the shift-adds and the align ops apply abs then neg to each source as bit operations. Other integer VOP3 ops are unchanged, since only these four are measured.
  • recomp/tests.rs: gpu_shift_add_abs_neg_act_on_the_sign_bit covers neg on src2 of v_lshl_add_u32 and abs on src0 of v_add_lshl_u32 with a zero shift, chosen so the modifier can't be shifted out. gpu_align_abs_neg_act_on_the_sign_bit covers neg and abs on src1 of both align ops.

Tested

  • On an RTX 3070 (Ampere, driver 616.56), Windows 11, debug, on main 5ce558f:
  • new tests: main fails both on both paths (21 for 0x80000015; 0 for 1). This branch passes them with XCL_DIRECT_DXIL=0 and 1.
  • gpu_ tests (--skip gpu_sparse_vram): 134 passed with XCL_DIRECT_DXIL=0; with 1, 133 passed and 1 failed, gpu_image_get_resinfo_1d_array, which also fails on main (Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046 fixes it).
  • dxil:: units: 136 passed.

Regression run
I have no retail title here. Could someone with one post the xcl-smoke blocks for main and this head?

Not tested

  • AMD, titles.

AI use

  • AI-assisted (Claude Code, Claude Opus 5.5): wrote the change, the tests and this description, and ran the tests above. Synthetic tests only; no game files.

🤖 Generated with Claude Code

upipibi and others added 2 commits November 24, 2026 20:17
…n the sign bit

Both paths dropped the VOP3 ABS / NEG source modifiers of the shift-add
ops: neg on the addend of v_lshl_add_u32 5, 2, 1 gave 21. RDNA2 applies
them to the source's sign bit as on a float (x & 0x7fffffff, x ^
0x80000000): 0x80000015 there. Measured by AnyPS5#25964 on gfx1036 and
gfx1201 (196/196 words each).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on the sign bit

Both paths dropped them too: neg on src1 of v_alignbit_b32 0, 1, 31 gave
0 for 1. RDNA2 applies them to bit 31 of each source, which a shift
brings into the result from src1 (AnyPS5#25799, gfx1036; on src0 and the
shift amount they cannot change the result, so applying them there is
harmless).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upipibi upipibi changed the title Recompiler: VOP3 abs / neg on v_lshl_add_u32 and v_add_lshl_u32 act on the sign bit Recompiler: VOP3 abs / neg on the shift-add and align ops act on the sign bit Nov 25, 2026
@JJAutoCompare

Copy link
Copy Markdown

Tested

I ran the two checked-in VOP3 sign-bit fixtures on clean PR head 7a62a796287b06882663220725482da58a124188. I rechecked the PR after the run and confirmed it was open at that SHA.

Windows 11 Enterprise Evaluation (build 26200.9974), AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), and DXC/DXIL 1.9.2609.5. The Cargo test profile was unoptimized with debug info disabled.

$env:CARGO_TARGET_DIR = 'L:/XclTooling/pr1512-tiling-edges-fddfa267/target'
$env:CARGO_BUILD_JOBS = '2'
$env:CARGO_INCREMENTAL = '0'
$env:CARGO_PROFILE_DEV_DEBUG = '0'
$env:CARGO_PROFILE_TEST_DEBUG = '0'
$env:TEMP = 'L:/XclTooling/pr2058'
$env:TMP = $env:TEMP
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = "$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64"
cargo test -p xcl --lib --no-run --message-format=json

# Executable reported by Cargo. The Arc lock covered only test execution.
$testExe = 'L:/XclTooling/pr1512-tiling-edges-fddfa267/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    foreach ($backend in '0', '1') {
        $env:XCL_DIRECT_DXIL = $backend
        & $testExe --exact gpu::recomp::tests::gpu_shift_add_abs_neg_act_on_the_sign_bit --nocapture --test-threads=1
        & $testExe --exact gpu::recomp::tests::gpu_align_abs_neg_act_on_the_sign_bit --nocapture --test-threads=1
    }
}
  • HLSL → DXC (XCL_DIRECT_DXIL=0) ran both fixtures. 2 passed, 0 failed, 0 ignored, 0 skipped.
  • Direct DXIL (XCL_DIRECT_DXIL=1) ran both fixtures. 2 passed, 0 failed, 0 ignored, 0 skipped.
  • On both backends, the lane 0 readback matched all five 32-bit fixture assertions. The shift-add results were 0x80000015 for v_lshl_add_u32 with NEG and 0x00000004 for v_add_lshl_u32 with ABS. The align results were 0x00000001 for v_alignbit_b32 with NEG, 0x00000080 for v_alignbyte_b32 with NEG, and 0x00000000 for v_alignbit_b32 with ABS.

Not tested

Other modifier and operand combinations, other GPUs, a main baseline, the full workspace suite, and retail-title smoke runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the tests, checked the exact PR head and fixture assertions, and wrote this report.

@JoaoPauluu

Copy link
Copy Markdown

A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, a different compiler from a native-Windows run: this PR's 2 new tests pass.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 7a62a79 as it is (merge base with main 5ce558f), no uncommitted changes. The lib test binary runs under Wine, one test per process.
    • gpu_align_abs_neg_act_on_the_sign_bit: ok, not skipped
    • gpu_shift_add_abs_neg_act_on_the_sign_bit: ok, not skipped

Not tested

  • the whole suite on this head, a retail title, native Windows, AMD.

AI use

  • Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

4 participants