fix: sign-extend a 32-bit literal in the signed 64-bit scalar sources (s_ashr_i64, s_bfe_i64, s_flbit_i32_i64) #240

Manually merged
github merged 1 commit from gh-pr/240/head into gh-pr/240/base 2026-11-26 05:39:34 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:49 UTC · original
lcg007xd-c:fix/salu-i64-literal-sign-extend → main · +39 −3 · 2 files · 1 commits · merged 2026-11-25 21:07 UTC

Change

s_ashr_i64, s_bfe_i64 and s_flbit_i32_i64 read S0 as a signed 64-bit integer, but in the reference interpreter a 32-bit literal in S0 was zero-extended like any other 64-bit scalar source. Silent wrong values on main (4f2cf5c):

s_ashr_i64 s[40:41], 0x80000000, 1          → 0x00000000_40000000   (now 0xFFFFFFFF_C0000000)
s_bfe_i64  s[44:45], 0x80000000, {off 4, width 40} → 0x00000000_08000000   (now 0xFFFFFFFF_F8000000)
s_flbit_i32_i64 s51, 0xFFFFFFF0             → 32                    (now 60)

Source: AMD, "RDNA 2" ISA, November 2020, §6.2.1, "Literal Expansion to 64 bits" (printed p. 43): "Literal constants are 32-bits, but they can be used as sources which normally require 64-bit data. They are expanded to 64 bits following these rules: 64 bit float: the lower 32-bit are padded with zero. 64-bit unsigned integer: zero extended to 64 bits. 64-bit signed integer: sign extended to 64 bits." The operand types come from the same document: D.i64 = signext(S0.i64) >> S1.u[5:0] (S_ASHR_I64, §12.1), S0.i64 for S_BFE_I64, and S_FLBIT_I32_I64 counts the bits equal to the sign bit (§12.3).

A small wrapper, rdna2_exec_bits.signed_literal_s0, sign-extends the literal before these three instructions run. The unsigned and bitwise 64-bit sources keep zero-extending (s_bfe_u64, s_mov_b64, s_flbit_i32_b64, the _b64 logic). The test pins that too.

HLSL: no change. The recompiler does not translate these three instructions (Untranslatable: non traduite en HLSL : s_ashr_i64 …), so there is nothing to keep in parity.

Linked issue: none. VIctory settled the same ISA rule for its own lowering (signed_64_bit_operands_sign_extend_their_literal, cited in Marvisak/VIctory#2254); no code is taken from it.

Verification

Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip):

python -m pytest                → 6 failed, 1009 passed, 315 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

The 6 failures are the same as on main on this machine and unrelated: 2 in test_jour_j.py (manifest name case on Linux, #237) and 4 in test_rdna2_exec_fma.py (NaN quieting on Python 3.14, #238).

Not run: the Windows CI job and GPU/WARP (no HLSL change).

Oracle and test data

  • New test_signed_64_bit_sources_sign_extend_a_32_bit_literal (tests/test_rdna2_exec_bits.py) computes the expected values by hand from the ISA pseudo-code: s_ashr_i64 of 0x80000000 (with SCC) and of the positive 0x7FFFFFFF, and s_bfe_i64 against s_bfe_u64 on the same literal and field. It also checks s_flbit_i32_i64 against s_flbit_i32_b64 on 0xFFFFFFF0, and that s_mov_b64 still zero-extends.
  • Failure case: the test fails on main (pair(wave, 40) == 0x40000000, expected 0xFFFFFFFF_C0000000).
  • Not measured on hardware: no RDNA 2 GPU was available here. The rule is the ISA's own text.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: the same change in all 9 languages (test_readme_sync.py checks it). (No README change: no new encodings, still 1300+.)
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:49 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/240) `lcg007xd-c:fix/salu-i64-literal-sign-extend` → `main` · +39 −3 · 2 files · 1 commits · merged 2026-11-25 21:07 UTC ## Change `s_ashr_i64`, `s_bfe_i64` and `s_flbit_i32_i64` read S0 as a **signed** 64-bit integer, but in the reference interpreter a 32-bit literal in S0 was zero-extended like any other 64-bit scalar source. Silent wrong values on `main` (`4f2cf5c`): ``` s_ashr_i64 s[40:41], 0x80000000, 1 → 0x00000000_40000000 (now 0xFFFFFFFF_C0000000) s_bfe_i64 s[44:45], 0x80000000, {off 4, width 40} → 0x00000000_08000000 (now 0xFFFFFFFF_F8000000) s_flbit_i32_i64 s51, 0xFFFFFFF0 → 32 (now 60) ``` Source: AMD, "RDNA 2" ISA, November 2020, §6.2.1, "Literal Expansion to 64 bits" (printed p. 43): "Literal constants are 32-bits, but they can be used as sources which normally require 64-bit data. They are expanded to 64 bits following these rules: 64 bit float: the lower 32-bit are padded with zero. 64-bit unsigned integer: zero extended to 64 bits. **64-bit signed integer: sign extended to 64 bits**." The operand types come from the same document: `D.i64 = signext(S0.i64) >> S1.u[5:0]` (S_ASHR_I64, §12.1), `S0.i64` for S_BFE_I64, and S_FLBIT_I32_I64 counts the bits equal to the sign bit (§12.3). A small wrapper, `rdna2_exec_bits.signed_literal_s0`, sign-extends the literal before these three instructions run. The unsigned and bitwise 64-bit sources keep zero-extending (`s_bfe_u64`, `s_mov_b64`, `s_flbit_i32_b64`, the `_b64` logic). The test pins that too. HLSL: no change. The recompiler does not translate these three instructions (`Untranslatable: non traduite en HLSL : s_ashr_i64` …), so there is nothing to keep in parity. Linked issue: none. VIctory settled the same ISA rule for its own lowering (`signed_64_bit_operands_sign_extend_their_literal`, cited in Marvisak/VIctory#2254); no code is taken from it. ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip): ``` python -m pytest → 6 failed, 1009 passed, 315 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` The 6 failures are the same as on `main` on this machine and unrelated: 2 in `test_jour_j.py` (manifest name case on Linux, #237) and 4 in `test_rdna2_exec_fma.py` (NaN quieting on Python 3.14, #238). Not run: the Windows CI job and GPU/WARP (no HLSL change). ## Oracle and test data - New `test_signed_64_bit_sources_sign_extend_a_32_bit_literal` (`tests/test_rdna2_exec_bits.py`) computes the expected values by hand from the ISA pseudo-code: `s_ashr_i64` of `0x80000000` (with SCC) and of the positive `0x7FFFFFFF`, and `s_bfe_i64` against `s_bfe_u64` on the same literal and field. It also checks `s_flbit_i32_i64` against `s_flbit_i32_b64` on `0xFFFFFFF0`, and that `s_mov_b64` still zero-extends. - Failure case: the test fails on `main` (`pair(wave, 40) == 0x40000000`, expected `0xFFFFFFFF_C0000000`). - Not measured on hardware: no RDNA 2 GPU was available here. The rule is the ISA's own text. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). (No README change: no new encodings, still `1300+`.) - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
s_ashr_i64, s_bfe_i64 and s_flbit_i32_i64 read S0 as a signed 64-bit
integer, but a literal there was zero-extended like any other 64-bit
source: s_ashr_i64 s[40:41], 0x80000000, 1 gave 0x40000000. The RDNA 2
ISA, section 6.2.1 "Literal Expansion to 64 bits" (p. 43): "64-bit
unsigned integer: zero extended to 64 bits; 64-bit signed integer: sign
extended to 64 bits". It now gives 0xFFFFFFFF_C0000000. Unsigned and
bitwise 64-bit sources (s_bfe_u64, s_mov_b64, s_flbit_i32_b64) keep
zero-extending. The HLSL recompiler does not translate these three
instructions, so only the interpreter changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:39:32 +00:00
github manually merged commit 646edeb904 into gh-pr/240/base 2026-11-26 05:39:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.