fix: the Rust RDNA 2 interpreter sign-extends a literal for signed 64-bit scalar sources #403

Merged
Luke-Ervin merged 3 commits from upstream-pr/403 into main 2026-11-27 12:57:16 +00:00
Luke-Ervin commented 2026-11-26 17:32:03 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Luke-Ervin on 2026-11-26T17:32:03Z.


Change

The Rust reference interpreter (crates/anyxboxx-rdna2-ref/src/scalar.rs) now sign-extends a 32-bit literal read as S0 by s_ashr_i64, s_bfe_i64 and s_flbit_i32_i64, as the Python model does.

AMD's RDNA 2 ISA (November 2020), 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". The Python applies it through signed_literal_s0 (emu/rdna2_exec_bits.py); the Rust port had not carried it over and zero-extended every 64-bit literal. Before this change:

Instruction Rust Python
s_flbit_i32_i64 s51, 0xFFFFFFF0 32 60
s_ashr_i64 s[40:41], 0x80000000, 1 0x0000000040000000 0xFFFFFFFFC0000000
s_bfe_i64 of 0x80000000 (offset 4, width 40) 0x0000000008000000 0xFFFFFFFFF8000000

read_signed64_s0 sign-extends only when S0 is the literal code; a register pair or an inline constant is read unchanged. binary_signed64 is the two-operand helper for s_ashr_i64 and s_bfe_i64; the generic binary() is untouched, so no other instruction changes. The unsigned and bitwise 64-bit sources (s_bfe_u64, s_flbit_i32_b64, s_mov_b64…) keep zero-extending.

docs/rust-full-status.md and docs/fr/rust-full-status.md record the finding. No README row or test-count change.

A second commit corrects the French docs line only: "bitwise" is "bit à bit", not "binaires" (which reads as "two-operand"). Its message also corrects a count in the first commit's message (three unsigned or bitwise controls, not four), which was left as it is rather than rewritten on an open pull request.

Linked issue: none.

Verification

Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of main at 47759e8 (and again with the second commit, same results; and merged with the newest main, 74dfb48, with #402 and the third fix: 1458 passed, 449 skipped), with anyxboxx-rdna2-ref and anyxboxx-pe built by cargo build --release -p anyxboxx-rdna2-ref -p anyxboxx-pe:

python -m pytest                → 1453 passed, 449 skipped
python -m pytest tests/test_rdna2_ref_parity.py → 41 passed
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!
cargo test -p anyxboxx-rdna2-ref → 136 passed; 0 failed
cargo clippy -p anyxboxx-rdna2-ref --all-targets -- -D warnings → no warnings
cargo fmt --check -p anyxboxx-rdna2-ref → clean

Not run (the 449 skipped tests): everything that needs Windows, the C++ runtime, dxc or a GPU, and the Rust crates that only build for Windows; cargo test --workspace for the same reason. No Windows machine was available. The change is plain integer arithmetic. No game was run.

Oracle and test data

  • Oracle: the Python model (test_signed_64_bit_sources_sign_extend_a_32_bit_literal in tests/test_rdna2_exec_bits.py pins its values against the ISA), through tests/test_rdna2_ref_parity.py.
  • How it was found: the parity generator of that file, run on 48,000 more seeds. One program ran s_flbit_i32_i64 on the literal 0xFACE5766 (Rust 0x20, Python 0x25). The 300 seeded programs never paired one of these three instructions with a literal whose bit 31 is set.
  • Test data: built in the tests (no external data).
  • Failure case: test_signed_64_bit_sources_sign_extend_a_literal_in_both_models fails on the old release binary. It compares the two interpreters on the three signed instructions and three unsigned or bitwise controls (s_bfe_u64, s_flbit_i32_b64, s_mov_b64) with five literals, and checks two values outright. The Rust unit test a_literal_is_sign_extended_for_a_signed_64_bit_source_only repeats the Python test's cases.

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 the English and French READMEs (test_readme_sync.py checks it). No README change needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none in this PR.
  • Code taken from another project: none in this PR.

This change was made with AI assistance (Claude Code): the bug was found, fixed and tested by the AI as described above. It was not tested on Windows.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CVSn4bUDfLBFvceKVLPSX5

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5514576561 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/403). Originally posted by [Luke-Ervin](https://github.com/Luke-Ervin) on 2026-11-26T17:32:03Z. --- ## Change The Rust reference interpreter (`crates/anyxboxx-rdna2-ref/src/scalar.rs`) now sign-extends a 32-bit literal read as S0 by `s_ashr_i64`, `s_bfe_i64` and `s_flbit_i32_i64`, as the Python model does. AMD's RDNA 2 ISA (November 2020), 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". The Python applies it through `signed_literal_s0` (`emu/rdna2_exec_bits.py`); the Rust port had not carried it over and zero-extended every 64-bit literal. Before this change: | Instruction | Rust | Python | |---|---|---| | `s_flbit_i32_i64 s51, 0xFFFFFFF0` | 32 | 60 | | `s_ashr_i64 s[40:41], 0x80000000, 1` | `0x0000000040000000` | `0xFFFFFFFFC0000000` | | `s_bfe_i64` of `0x80000000` (offset 4, width 40) | `0x0000000008000000` | `0xFFFFFFFFF8000000` | `read_signed64_s0` sign-extends only when S0 is the literal code; a register pair or an inline constant is read unchanged. `binary_signed64` is the two-operand helper for `s_ashr_i64` and `s_bfe_i64`; the generic `binary()` is untouched, so no other instruction changes. The unsigned and bitwise 64-bit sources (`s_bfe_u64`, `s_flbit_i32_b64`, `s_mov_b64`…) keep zero-extending. `docs/rust-full-status.md` and `docs/fr/rust-full-status.md` record the finding. No README row or test-count change. A second commit corrects the French docs line only: "bitwise" is "bit à bit", not "binaires" (which reads as "two-operand"). Its message also corrects a count in the first commit's message (three unsigned or bitwise controls, not four), which was left as it is rather than rewritten on an open pull request. Linked issue: none. ## Verification Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of `main` at `47759e8` (and again with the second commit, same results; and merged with the newest `main`, `74dfb48`, with #402 and the third fix: 1458 passed, 449 skipped), with `anyxboxx-rdna2-ref` and `anyxboxx-pe` built by `cargo build --release -p anyxboxx-rdna2-ref -p anyxboxx-pe`: ``` python -m pytest → 1453 passed, 449 skipped python -m pytest tests/test_rdna2_ref_parity.py → 41 passed python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! cargo test -p anyxboxx-rdna2-ref → 136 passed; 0 failed cargo clippy -p anyxboxx-rdna2-ref --all-targets -- -D warnings → no warnings cargo fmt --check -p anyxboxx-rdna2-ref → clean ``` Not run (the 449 skipped tests): everything that needs Windows, the C++ runtime, `dxc` or a GPU, and the Rust crates that only build for Windows; `cargo test --workspace` for the same reason. No Windows machine was available. The change is plain integer arithmetic. No game was run. ## Oracle and test data - Oracle: the Python model (`test_signed_64_bit_sources_sign_extend_a_32_bit_literal` in `tests/test_rdna2_exec_bits.py` pins its values against the ISA), through `tests/test_rdna2_ref_parity.py`. - How it was found: the parity generator of that file, run on 48,000 more seeds. One program ran `s_flbit_i32_i64` on the literal `0xFACE5766` (Rust `0x20`, Python `0x25`). The 300 seeded programs never paired one of these three instructions with a literal whose bit 31 is set. - Test data: built in the tests (no external data). - Failure case: `test_signed_64_bit_sources_sign_extend_a_literal_in_both_models` fails on the old release binary. It compares the two interpreters on the three signed instructions and three unsigned or bitwise controls (`s_bfe_u64`, `s_flbit_i32_b64`, `s_mov_b64`) with five literals, and checks two values outright. The Rust unit test `a_literal_is_sign_extended_for_a_signed_64_bit_source_only` repeats the Python test's cases. ## 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 the English and French READMEs (`test_readme_sync.py` checks it). No README change needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none in this PR. - [x] Code taken from another project: none in this PR. This change was made with AI assistance (Claude Code): the bug was found, fixed and tested by the AI as described above. It was not tested on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01CVSn4bUDfLBFvceKVLPSX5
chatgpt-codex-connector[bot] commented 2026-11-26 17:32:15 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T17:32:15Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T17:33:53.593789Z 3f7435a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7199187572 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/403#issuecomment-7199187572). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-26T17:32:15Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3f7435abd86e731a5d416b1ccb6df99d5ffc4867","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T17:33:53.593789Z">2026-11-26T17:33:53.593789Z</relative-time> | `3f7435a` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!403
No description provided.