fix: the Rust RDNA 2 interpreter refuses an indexed register past 32 bits #402

Open
github-bot wants to merge 2 commits from github-bot/gh-402 into main AGit
Owner

@⁠Luke-Ervin on GitHub · 2026-11-26 17:26 UTC · original
Luke-Ervin:fix/rdna2-ref-movrel-index-overflow → main · +52 −10 · 4 files · 2 commits · open

Change

The Rust reference interpreter (crates/anyxboxx-rdna2-ref/src/movrel.rs) now refuses a movrel register index that passes 2^32, as the Python model does. Before, it added the register number and M0 as u32:

M0 = 0xFFFFFFFD, s_movrels_b32 s102, s47   →   47 + 0xFFFFFFFD = 0x10000002C
  • Release build: the sum wrapped to 44, so the instruction ran and copied s44 (a wrong result reported as success, against rule 3).
  • Debug build: the addition panicked (attempt to add with overflow) instead of returning the interpreter's error.
  • Python model (emu/rdna2_exec_movrel.py): unbounded integers, index 0x10000002C, refused as outside the model (Untranslated), which is what its docstring specifies.

check() now takes the register and the offset separately and adds them in u64 before applying the same range and even-pair rules. Nothing changes for sums below 2^32.

Affected forms: s_movrels_b32/b64, s_movreld_b32/b64, v_movrels_b32, v_movreld_b32, v_movrelsd_b32. Not affected: the _2 forms and v_swaprel_b32 (10-bit fields of M0, cannot overflow) and v_swap_b32 (no offset).

docs/rust-full-status.md and docs/fr/rust-full-status.md record the finding. No README row or test-count change (1902 collected, still 1900+).

Linked issue: none.

Verification

Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of main at 47759e8, 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

Reproduction before the fix (input to anyxboxx-rdna2-ref): lanes 32, scc 0, primitive 0, s 124 FFFFFFFD, s 44 12345678, program BEE62E2F BF810000. Release printed s 102 12345678; debug panicked at movrel.rs:134. Both now print error untranslated.

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, through tests/test_rdna2_ref_parity.py.
  • How it was found: the parity generator of that file, run on 6,000 more seeds with special values in the scalar registers. The 300 seeded programs set M0 below 256, so a large M0 only appears when an earlier random instruction writes s124.
  • Test data: built in the tests (no external data).
  • Failure case: test_indexed_registers_past_32_bits_are_refused_by_both_models (seven forms × M0 = 0xFFFFFFFD, 0xFFFFFFFF, 0x80000000, plus M0 = 1 as the in-range control) fails on the old release binary. The Rust unit test an_index_past_32_bits_is_refused_not_wrapped pins the refusal.

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

**@⁠Luke-Ervin** on GitHub · 2026-11-26 17:26 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/402) `Luke-Ervin:fix/rdna2-ref-movrel-index-overflow` → `main` · +52 −10 · 4 files · 2 commits · open ## Change The Rust reference interpreter (`crates/anyxboxx-rdna2-ref/src/movrel.rs`) now refuses a movrel register index that passes 2^32, as the Python model does. Before, it added the register number and M0 as `u32`: ``` M0 = 0xFFFFFFFD, s_movrels_b32 s102, s47 → 47 + 0xFFFFFFFD = 0x10000002C ``` - Release build: the sum wrapped to 44, so the instruction ran and copied s44 (a wrong result reported as success, against rule 3). - Debug build: the addition panicked (`attempt to add with overflow`) instead of returning the interpreter's error. - Python model (`emu/rdna2_exec_movrel.py`): unbounded integers, index `0x10000002C`, refused as outside the model (`Untranslated`), which is what its docstring specifies. `check()` now takes the register and the offset separately and adds them in `u64` before applying the same range and even-pair rules. Nothing changes for sums below 2^32. Affected forms: `s_movrels_b32/b64`, `s_movreld_b32/b64`, `v_movrels_b32`, `v_movreld_b32`, `v_movrelsd_b32`. Not affected: the `_2` forms and `v_swaprel_b32` (10-bit fields of M0, cannot overflow) and `v_swap_b32` (no offset). `docs/rust-full-status.md` and `docs/fr/rust-full-status.md` record the finding. No README row or test-count change (1902 collected, still `1900+`). Linked issue: none. ## Verification Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of `main` at `47759e8`, 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 ``` Reproduction before the fix (input to `anyxboxx-rdna2-ref`): `lanes 32`, `scc 0`, `primitive 0`, `s 124 FFFFFFFD`, `s 44 12345678`, `program BEE62E2F BF810000`. Release printed `s 102 12345678`; debug panicked at `movrel.rs:134`. Both now print `error untranslated`. 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, through `tests/test_rdna2_ref_parity.py`. - How it was found: the parity generator of that file, run on 6,000 more seeds with special values in the scalar registers. The 300 seeded programs set M0 below 256, so a large M0 only appears when an earlier random instruction writes s124. - Test data: built in the tests (no external data). - Failure case: `test_indexed_registers_past_32_bits_are_refused_by_both_models` (seven forms × M0 = `0xFFFFFFFD`, `0xFFFFFFFF`, `0x80000000`, plus M0 = 1 as the in-range control) fails on the old release binary. The Rust unit test `an_index_past_32_bits_is_refused_not_wrapped` pins the refusal. ## 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)
The movrel instructions address a register by "register number in the
instruction + M0". The Rust port (crates/anyxboxx-rdna2-ref/src/movrel.rs)
added the two as u32. M0 is a full 32-bit register, so the sum can pass 2^32:

  M0 = 0xFFFFFFFD, s_movrels_b32 s102, s47   ->   47 + 0xFFFFFFFD = 0x10000002C

- In a release build the sum wrapped to 44, which is in range, so the
  instruction ran and copied s44. That is a wrong result reported as success.
- In a debug build the same addition panicked ("attempt to add with
  overflow") instead of returning the interpreter's own error.
- The Python model (emu/rdna2_exec_movrel.py) uses unbounded integers, sees
  0x10000002C, and refuses it as outside the model, which is what its
  docstring specifies: the hardware's behaviour for an index outside the
  registers is not described, so it raises Untranslated.

So the two reference interpreters disagreed, and the Rust one broke rule 3 of
AGENTS.md (no fake success). The Python is the model the port is checked
against, and its refusal is the documented behaviour, so the Rust is the side
that changes.

What changed: check() now takes the register and the offset separately and
adds them in u64, then applies the same range and even-pair rules. Nothing
changes for sums below 2^32. The four call sites (vector destination, vector
source, scalar source, scalar destination) pass the two parts instead of
their u32 sum. The error message prints the unwrapped index, as the Python
does.

Affected forms: s_movrels_b32/b64, s_movreld_b32/b64, v_movrels_b32,
v_movreld_b32, v_movrelsd_b32. Not affected: the _2 forms and v_swaprel_b32,
which add 10-bit fields of M0 to a register number below 512 and cannot
overflow, and v_swap_b32, which adds nothing.

Why the existing tests missed it: the 300 seeded parity programs set M0 below
256, so a large M0 only appears when an earlier random instruction happens to
write s124. It was found by running the same generator on 6,000 more seeds
with special values (NaN patterns, 0xFFFFFFFF, ...) in the scalar registers;
one program wrote a large value to M0 and then ran s_movrels_b32.

Tests:
- movrel.rs: an_index_past_32_bits_is_refused_not_wrapped (fails to compile
  against the old check(); the behaviour it pins is the refusal).
- tests/test_rdna2_ref_parity.py:
  test_indexed_registers_past_32_bits_are_refused_by_both_models runs the
  seven affected forms with M0 = 0xFFFFFFFD, 0xFFFFFFFF and 0x80000000 and
  expects "error untranslated" from both interpreters, plus M0 = 1 as the
  in-range control. It fails on the old release binary and passes now.

docs/rust-full-status.md and its French version record the finding.

Not checked: Windows. The change is plain integer arithmetic with no
platform-specific code.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CVSn4bUDfLBFvceKVLPSX5
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:30:56 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 17:26 UTC · original · edited 2026-11-26 17:28 UTC

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:28:18.533446Z 1fe066a 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 17:26 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/402#issuecomment-7199035184) · edited 2026-11-26 17:28 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"1fe066aa3d339ccd8284052c4d7f579501e8ccbd","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:28:18.533446Z">2026-11-26T17:28:18.533446Z</relative-time> | `1fe066a` | 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>
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 23:21 UTC · original

The movrel overflow regression catches the old arithmetic in an optimized Windows build. On b676bbc429aa3c98ab36b7d3b4907a6dd1935618 all three movrel tests passed in debug and release. In an isolated copy of the exact reference crate, I then restored wrapping only in check; the regression failed because the unsupported index returned success. Pinned source and regression. This crate-only run excludes launcher and audio.

The PR also merges cleanly against the actual post-#454 b6d86cf. A useful final guard is to keep the overflow case in the release-mode reference test job, where the original wrong success is observable. PortBridge · AI-assisted test report.

**@⁠akimfomin** on GitHub · 2026-11-26 23:21 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/402#issuecomment-7205467131) The movrel overflow regression catches the old arithmetic in an optimized Windows build. On `b676bbc429aa3c98ab36b7d3b4907a6dd1935618` all three movrel tests passed in debug and release. In an isolated copy of the exact reference crate, I then restored wrapping only in `check`; the regression failed because the unsupported index returned success. [Pinned source and regression](https://github.com/LooperSalty/AnyXboxX/blob/b676bbc429aa3c98ab36b7d3b4907a6dd1935618/crates/anyxboxx-rdna2-ref/src/movrel.rs#L61-L76). This crate-only run excludes launcher and audio. The PR also merges cleanly against the actual post-#454 `b6d86cf`. A useful final guard is to keep the overflow case in the release-mode reference test job, where the original wrong success is observable. [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted test report.
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/402/head:github-bot/gh-402'
git switch 'github-bot/gh-402'

Merge

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