fix: the Rust RDNA 2 interpreter refuses a register group past v255 instead of aborting #437

Open
github-bot wants to merge 3 commits from github-bot/gh-437 into main AGit
Owner

@⁠Luke-Ervin on GitHub · 2026-11-26 18:46 UTC · original
Luke-Ervin:fix/rdna2-vgpr-pair-past-v255 → main · +122 −7 · 8 files · 3 commits · open

Change

The Rust reference interpreter (crates/anyxboxx-rdna2-ref) now returns its operand error when a VGPR group runs past v255, instead of aborting.

A 64-bit vector result is written to vdst, vdst + 1; with vdst = 255 there is no second register. Five places indexed wave.v for such a group without checking where it ends, and the binary aborted (index out of bounds: the len is 256 but the index is 256; the release profile aborts on panic):

File What was indexed
wide.rs 64-bit result of the f64 operations and the 64-bit shifts
div.rs 64-bit result of v_div_scale/fmas/fixup_f64
vop3_forms.rs 64-bit result of v_mad_u64_u32 (v_mad_i64_i32 shares the code but is refused earlier in both models, for its signed carry)
sad.rs (×2) 64-bit result and 64-bit source S2 of v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8; 128-bit result and 128-bit source S2 of v_mqsad_u32_u8 (four registers, from v253)

The crate already answers this case on the source side: compare::read64 returns Error::Operand for a 64-bit source pair at v255, and the memory, image, typed-buffer and LDS code check their groups the same way. These five sites were missing the check.

  • Wave::vgpr_group(first, count) returns first when the count registers exist, Error::Operand otherwise.
  • Each site calls it before its first write (or read, for the 128-bit source), so a refused instruction changes nothing in the wave. Like read64, the check is inside the lane loop: with no active lane the instruction still does nothing and succeeds. Programs that ran before run exactly as they did; only the aborts change.

Left open, for the maintainers: the Python model raises IndexError in all of these cases (an uncaught list index, after writing the low half of the result in the first active lane), which the parity harness does not turn into an error line, so the two models cannot be compared on these programs yet. Whether the Python should raise Untranslated there, with the Rust following, is not decided here. The new test states the current pairing (error operand / IndexError) explicitly, and is named for what it checks (..._is_an_operand_error_in_rust), so a later change has to update it on purpose.

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

Linked issue: none.

Verification

Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of main at f088a43, and again merged with the newest main (74dfb48) and with #402 and #403 (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                → 1455 passed, 449 skipped
python -m pytest tests/test_rdna2_ref_parity.py → 42 passed
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!
cargo test -p anyxboxx-rdna2-ref → 137 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, program D70100FF 02020481 BF810000 (v_ashrrev_i64 v[255:256], 1, v[2:3]). The process aborted at wide.rs:251; it now prints error operand.

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 bounds checking on a Vec. No game was run.

Oracle and test data

  • How the list was established: every VOP1, VOP2, VOP3, VOP3P and VOPC opcode was run through the release binary with the destination at v255 and v254 and with sources at v255, v254, v0–v2 and an inline constant. 29 mnemonics aborted, all at these five lines; after the change none does. The first was found by the parity generator on extra seeds (v_ashrrev_i64 with vdst = 255). The generator's VOP3 encoder keeps vdst below 255 only for names ending in _f64, so the 64-bit shifts, the VOP3 forms of v_cvt_f64_* and the SAD forms can still be drawn with a destination group past v255; the 300 seeded programs happen not to.
  • Oracle: for the cases that fit (one register lower), the Python model through assert_same. For the refused cases there is no shared error line yet (see "Left open").
  • Test data: built in the tests (no external data).
  • Failure case: test_a_register_group_past_v255_is_an_operand_error_in_rust fails on the old binary, whose process aborts. It runs 15 programs across the five sites: eleven 64-bit results (nine VOP3, two VOP1), the 128-bit result of v_mqsad_u32_u8, the 64-bit S2 pair of the two packed SAD forms and the 128-bit S2 of v_mqsad_u32_u8. The source registers are filled first with values that differ by lane and register, so the programs that fit write non-zero results that both models must agree on. Rust unit tests: a_register_group_must_end_at_v255 (wave.rs) and a_64_bit_result_at_v255_is_refused_without_mutation (wide.rs).

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

**@⁠Luke-Ervin** on GitHub · 2026-11-26 18:46 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/437) `Luke-Ervin:fix/rdna2-vgpr-pair-past-v255` → `main` · +122 −7 · 8 files · 3 commits · open ## Change The Rust reference interpreter (`crates/anyxboxx-rdna2-ref`) now returns its operand error when a VGPR group runs past v255, instead of aborting. A 64-bit vector result is written to `vdst`, `vdst + 1`; with `vdst = 255` there is no second register. Five places indexed `wave.v` for such a group without checking where it ends, and the binary aborted (`index out of bounds: the len is 256 but the index is 256`; the release profile aborts on panic): | File | What was indexed | |---|---| | `wide.rs` | 64-bit result of the f64 operations and the 64-bit shifts | | `div.rs` | 64-bit result of `v_div_scale/fmas/fixup_f64` | | `vop3_forms.rs` | 64-bit result of `v_mad_u64_u32` (`v_mad_i64_i32` shares the code but is refused earlier in both models, for its signed carry) | | `sad.rs` (×2) | 64-bit result and 64-bit source S2 of `v_qsad_pk_u16_u8`, `v_mqsad_pk_u16_u8`; 128-bit result and 128-bit source S2 of `v_mqsad_u32_u8` (four registers, from v253) | The crate already answers this case on the source side: `compare::read64` returns `Error::Operand` for a 64-bit source pair at v255, and the memory, image, typed-buffer and LDS code check their groups the same way. These five sites were missing the check. - `Wave::vgpr_group(first, count)` returns `first` when the `count` registers exist, `Error::Operand` otherwise. - Each site calls it before its first write (or read, for the 128-bit source), so a refused instruction changes nothing in the wave. Like `read64`, the check is inside the lane loop: with no active lane the instruction still does nothing and succeeds. Programs that ran before run exactly as they did; only the aborts change. **Left open, for the maintainers:** the Python model raises `IndexError` in all of these cases (an uncaught list index, after writing the low half of the result in the first active lane), which the parity harness does not turn into an error line, so the two models cannot be compared on these programs yet. Whether the Python should raise `Untranslated` there, with the Rust following, is not decided here. The new test states the current pairing (`error operand` / `IndexError`) explicitly, and is named for what it checks (`..._is_an_operand_error_in_rust`), so a later change has to update it on purpose. `docs/rust-full-status.md` and `docs/fr/rust-full-status.md` record the finding. No README row or test-count change (1904 collected, still `1900+`). Linked issue: none. ## Verification Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of `main` at `f088a43`, and again merged with the newest `main` (`74dfb48`) and with #402 and #403 (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 → 1455 passed, 449 skipped python -m pytest tests/test_rdna2_ref_parity.py → 42 passed python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! cargo test -p anyxboxx-rdna2-ref → 137 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`, `program D70100FF 02020481 BF810000` (`v_ashrrev_i64 v[255:256], 1, v[2:3]`). The process aborted at `wide.rs:251`; it now prints `error operand`. 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 bounds checking on a `Vec`. No game was run. ## Oracle and test data - How the list was established: every VOP1, VOP2, VOP3, VOP3P and VOPC opcode was run through the release binary with the destination at v255 and v254 and with sources at v255, v254, v0–v2 and an inline constant. 29 mnemonics aborted, all at these five lines; after the change none does. The first was found by the parity generator on extra seeds (`v_ashrrev_i64` with `vdst = 255`). The generator's VOP3 encoder keeps `vdst` below 255 only for names ending in `_f64`, so the 64-bit shifts, the VOP3 forms of `v_cvt_f64_*` and the SAD forms can still be drawn with a destination group past v255; the 300 seeded programs happen not to. - Oracle: for the cases that fit (one register lower), the Python model through `assert_same`. For the refused cases there is no shared error line yet (see "Left open"). - Test data: built in the tests (no external data). - Failure case: `test_a_register_group_past_v255_is_an_operand_error_in_rust` fails on the old binary, whose process aborts. It runs 15 programs across the five sites: eleven 64-bit results (nine VOP3, two VOP1), the 128-bit result of `v_mqsad_u32_u8`, the 64-bit S2 pair of the two packed SAD forms and the 128-bit S2 of `v_mqsad_u32_u8`. The source registers are filled first with values that differ by lane and register, so the programs that fit write non-zero results that both models must agree on. Rust unit tests: `a_register_group_must_end_at_v255` (`wave.rs`) and `a_64_bit_result_at_v255_is_refused_without_mutation` (`wide.rs`). ## 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
A 64-bit vector result is written to the pair vdst, vdst + 1. With vdst = 255
there is no second register. Five places of crates/anyxboxx-rdna2-ref indexed
`wave.v` for such a group without checking where it ends, so the binary
aborted with "index out of bounds: the len is 256 but the index is 256" (the
release profile aborts on panic):

  wide.rs        64-bit result of the f64 operations and the 64-bit shifts
  div.rs         64-bit result of v_div_scale/fmas/fixup_f64
  vop3_forms.rs  64-bit result of v_mad_u64_u32 (v_mad_i64_i32 shares the
                 code but both models refuse it earlier, for its signed carry)
  sad.rs (x2)    64-bit result and 64-bit source S2 of v_qsad_pk_u16_u8 and
                 v_mqsad_pk_u16_u8; 128-bit result and 128-bit source S2 of
                 v_mqsad_u32_u8, which take four registers and overflow from
                 v253

An abort is not one of the interpreter's answers: the CLI prints nothing, and
the caller sees a dead process instead of an error line. The crate already
has the right answer for this case elsewhere: compare::read64 returns
Error::Operand ("paire de registres vectoriels hors plage") for a 64-bit
*source* pair at v255, and the memory, image, typed-buffer and LDS code check
their register groups the same way. These five sites were simply missing the
check.

What changed:

- Wave::vgpr_group(first, count) returns `first` when the `count` registers
  starting there exist, and Error::Operand otherwise.
- Each of the five sites calls it before its first write (or read, for the
  128-bit source), so a refused instruction changes nothing in the wave.
  Like read64, the check sits inside the lane loop: with no active lane the
  instruction still does nothing and succeeds, as before. Programs that ran
  before run exactly as they did; only the aborts change.

Why Operand and not Untranslated: it is what the crate already returns for
the same situation on the source side, and error.rs defines Operand as "an
operand or register the model refuses". The Python model raises IndexError in
all of these cases (an uncaught list index, after it has written the low half
of the result in the first active lane), which the parity harness does not
turn into an error line, so the two models cannot be compared on these
programs yet. Whether the Python should raise Untranslated
there instead, with the Rust following, is a decision for the maintainers and
is not taken here; the new test states the current pairing explicitly so that
a later change has to update it on purpose.

How the list was established: every VOP1, VOP2, VOP3, VOP3P and VOPC opcode
was run through the release binary with the destination at v255 and v254 and
with sources at v255, v254, v0-v2 and an inline constant. 29 mnemonics
aborted, all at these five lines; after the change none does. The first one
was found by the parity generator on extra seeds (v_ashrrev_i64 with
vdst = 255): the generator's VOP3 encoder keeps vdst below 255 only for names
ending in `_f64`, so the 64-bit shifts, the VOP3 forms of v_cvt_f64_* and the
SAD forms can still be drawn with a destination group past v255.

Tests:
- wave.rs: a_register_group_must_end_at_v255.
- wide.rs: a_64_bit_result_at_v255_is_refused_without_mutation.
- tests/test_rdna2_ref_parity.py:
  test_a_register_group_past_v255_is_an_operand_error_in_rust, 15 programs
  across all five sites: eleven 64-bit results (nine VOP3, two VOP1), the
  128-bit result of v_mqsad_u32_u8, the 64-bit S2 pair of the two packed SAD
  forms and the 128-bit S2 of v_mqsad_u32_u8. Each must give "error operand"
  in Rust and IndexError in Python; the same instruction one register lower
  must run and agree in both. The source registers are filled with values
  that differ by lane and register first, so the programs that fit write
  non-zero results. It fails on the old binary (the process aborts).

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

Not checked: Windows. The change is bounds checking on a Vec.

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 18:47:02 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 18:47 UTC · original · edited 2026-11-26 18:49 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-26T18:49:27.049597Z 2c116ae 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 18:47 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/437#issuecomment-7200845859) · edited 2026-11-26 18:49 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"2c116aec3c653b76f40ada7540c041a798e612ec","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-26T18:49:27.049597Z">2026-11-26T18:49:27.049597Z</relative-time> | `2c116ae` | 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>
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/437/head:github-bot/gh-437'
git switch 'github-bot/gh-437'

Merge

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