Skip to content

Recompiler: sign-extend 32-bit literals for 64-bit signed integer operands - #1258

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/i64-literal-sign-extend
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/i64-literal-sign-extend

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

In RDNA2 ISA, a 32-bit literal constant (code == 255) used for a 64-bit signed integer (i64) operand is sign-extended to 64 bits, while u64 / b64 literals are zero-extended and f64 literals occupy the upper 32 bits. code64 only distinguished f64 vs non-f64, so negative 32-bit literals on _i64 instructions (v_cmp*_i64, v_ashrrev_i64, s_ashr_i64, s_bfe_i64, s_flbit_i32_i64, v_mad_i64_i32) were zero-extended instead.

This replaces f64: bool on code64 / read64 with Lit64 { U64, I64, F64 }, sign-extending 32-bit literals for i64 instructions while keeping u64/b64 and f64 unchanged.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: add Lit64 { U64, I64, F64 } and sign-extend 32-bit literals in code64 / read64 for i64 operations in salu64 and valu64.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_i64_literal_is_sign_extended covering V_CMP_EQ_I64, V_ASHRREV_I64, S_ASHR_I64, V_MAD_I64_I32, and V_CMP_EQ_U64 control across wave32 and split wave64 (verified failing before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib gpu_i64_literal_is_sign_extended: 1 passed, 0 failed across wave32 and split wave64 (failed on the GPU before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: ba00224055aeb359476ad614ad5ec971d360836f
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14472 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited emit.rs, wrote the fix and GPU test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.

…rands

In RDNA2 ISA, a 32-bit literal constant (code 255) used for a 64-bit
signed integer (i64) operand is sign-extended to 64 bits, while u64 /
b64 literals are zero-extended and f64 literals occupy the upper 32
bits. code64 only distinguished f64 vs non-f64, so negative 32-bit
literals on _i64 instructions (v_cmp*_i64, v_ashrrev_i64, s_ashr_i64,
s_bfe_i64, s_flbit_i32_i64, v_mad_i64_i32) were zero-extended instead.

Replace the `f64: bool` parameter on code64/read64 with `Lit64 { U64,
I64, F64 }`, sign-extending 32-bit literals for i64 instructions, with
a GPU test across wave32 and split wave64.

Assisted-by: OpenCode (Gemini 4 Neon)
@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@930e8b4 (baseline 751 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
752 passed; 0 failed; 41 ignored   (exit 0)

One more than the baseline; sign-extending 32-bit literals for 64-bit forms is exercised and green.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib lib recomp: 190 passed, 0 failed.

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

Tested — xcl-dev/xcl PR #1258 was open at ba00224055aeb359476ad614ad5ec971d360836f before and after the run. The checkout was clean and detached at that SHA both times.

STOR-WINLAB ran Windows 11 Enterprise Evaluation 25H2 x64 (26200.9974) on a Ryzen 7 3800X and Intel Arc A770 (driver 32.0.101.9175), using Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc) and DXC/DXIL 1.9.2609.5.

  • cargo test --locked -p xcl --lib --no-run completed outside the Arc lock in 1m 45s with exit 0. The debug build used two jobs, incremental compilation and debug info disabled, the assigned target slot, and private TEMP and TMP.
  • The exact prebuilt fixture ran under L:/XclTooling/Invoke-ArcTest.ps1 in a fresh PowerShell process with process-scoped RemoteSigned. It used XCL_ADAPTER=A770, XCL_DIRECT_DXIL=0, and XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64.
& "L:\XclTooling\verify-pr1523-1362129-t3-cf2e05e7\target\debug\build\xcl\77aca8ccb20e299f\out\xcl-77aca8ccb20e299f.exe" gpu::recomp::tests::gpu_i64_literal_is_sign_extended --exact --nocapture --test-threads=1

Result — 1 passed, 0 failed, 0 ignored, 0 GPU skips, 728 filtered out, 0.56s. The fixture and wrapper both exited 0. The stock fixture ran standalone wave32. Both comparison masks read back as 0x00000000_FFFFFFFF, covering signed -17 sign extension and the unsigned zero-extension control. The scalar arithmetic shift read back -4. On all 32 lanes, the vector arithmetic shift read back -4 and the multiply-add read back -100.

Not tested — Native or split wave64, direct DXIL, other adapters, the full suite, and retail smoke.

AI use — T3 Code / Codex (gpt-6.2-sol) ran and reported the verification.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native wave64 GPU check of exact PR head ba00224055aeb359476ad614ad5ec971d360836f. The PR description lists AMD/native wave64 as untested.

Tested

  • Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5; debug test build.
  • XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=0; cargo test --locked -p xcl --lib -j 2 gpu_i64_literal_is_sign_extended -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED. gpu_waves() runs this fixture in both wave64 and wave32 on the selected AMD adapter. It exercises the HLSL emitter's signed i64 literal path and includes the unsigned control case.

This is the focused GPU regression only. I did not run the full workspace suite, direct DXIL mode, or a paired title smoke on this PR; the existing RX 6800M full-suite baseline has GPU device-suspension failures unrelated to this focused test.

AI-assisted checkout, testing, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was used.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@b3IKK this PR fixes the HLSL path; the direct-DXIL path (XCL_DIRECT_DXIL=1) has the same zero-extension: read64/code64 in gpu/dxil/lower.rs always zero-extend a 32-bit literal into a 64-bit operand, so a negative literal of a signed 64-bit operand gets a zero high word there.

A direct-path change with a GPU test is on a branch you are welcome to take into this PR: upipibi@6fd538f3 (lower.rs +12/-4: read64 marks the signed 64-bit operands, i.e. _I64 names and V_MAD_I64_I32's third operand, and code64 fills the high word with 0xFFFFFFFF for a negative literal there). The test gpu_direct_i64_literal_is_sign_extended covers v_cmp_eq/lt_i64, s_ashr_i64, s_bfe_i64, s_flbit_i32_i64, v_ashrrev_i64, v_mad_i64_i32, with v_cmp_eq_u64 as a control. The commit also carries a test-only check that the direct path orders -0 below +0 in float min/max (it passes on main).

RTX 3070 8 GB, driver 616.56, Windows 11, debug, on main 8b957bec: the new test fails 3/3 without the change (every signed case; the unsigned control right) and passes 3/3 with it; cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 with it: 1311 passed, 0 failed, 27 ignored. Not tested: AMD/Intel, a title run.

AI-assisted (Claude Code, Claude Opus 5.5): found it by porting VIctory #447's fix, wrote the change and test, ran them, wrote this.

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.

6 participants