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

Open
github-bot wants to merge 1 commit from github-bot/gh-1258 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 13:49 UTC · original
b3IKK:recomp/i64-literal-sign-extend → main · +71 −13 · 2 files · 1 commits · open

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.
**@⁠b3IKK** on GitHub · 2026-11-24 13:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/1258) `b3IKK:recomp/i64-literal-sign-extend` → `main` · +71 −13 · 2 files · 1 commits · open 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.
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:40 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 14:01 UTC · original

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.

**@⁠dcastell1** on GitHub · 2026-11-24 14:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/1258#issuecomment-7133705825) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:02 UTC · original

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

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

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1258#issuecomment-7133736358) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib lib recomp: 190 passed, 0 failed. Thanks!
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:00 UTC · original

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.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1258#issuecomment-7153358579) **Tested** — [xcl-dev/xcl PR #1258](https://git.gtahub.st/github/xcl-dev--xcl/pulls/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`. ```powershell & "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.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 07:03 UTC · original

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.

**@⁠luckyteagirl** on GitHub · 2026-11-25 07:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1258#issuecomment-7155440839) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1258/head:github-bot/gh-1258'
git switch 'github-bot/gh-1258'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1258'
git switch 'github-bot/gh-1258'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1258'
git switch 'github-bot/gh-1258'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1258'
git switch 'main'
git merge --squash 'github-bot/gh-1258'
git switch 'main'
git merge --ff-only 'github-bot/gh-1258'
git switch 'main'
git merge 'github-bot/gh-1258'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.