fix: the Rust RDNA 2 interpreter sign-extends a literal for signed 64-bit scalar sources #403
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!403
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-403"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Luke-Ervin on GitHub · 2026-11-26 17:32 UTC · original
Luke-Ervin:fix/rdna2-ref-signed64-literal→main· +103 −5 · 4 files · 3 commits · openChange
The Rust reference interpreter (
crates/anyxboxx-rdna2-ref/src/scalar.rs) now sign-extends a 32-bit literal read as S0 bys_ashr_i64,s_bfe_i64ands_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:s_flbit_i32_i64 s51, 0xFFFFFFF0s_ashr_i64 s[40:41], 0x80000000, 10x00000000400000000xFFFFFFFFC0000000s_bfe_i64of0x80000000(offset 4, width 40)0x00000000080000000xFFFFFFFFF8000000read_signed64_s0sign-extends only when S0 is the literal code; a register pair or an inline constant is read unchanged.binary_signed64is the two-operand helper fors_ashr_i64ands_bfe_i64; the genericbinary()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.mdanddocs/fr/rust-full-status.mdrecord 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
mainat47759e8(and again with the second commit, same results; and merged with the newestmain,74dfb48, with #402 and the third fix: 1458 passed, 449 skipped), withanyxboxx-rdna2-refandanyxboxx-pebuilt bycargo build --release -p anyxboxx-rdna2-ref -p anyxboxx-pe:Not run (the 449 skipped tests): everything that needs Windows, the C++ runtime,
dxcor a GPU, and the Rust crates that only build for Windows;cargo test --workspacefor the same reason. No Windows machine was available. The change is plain integer arithmetic. No game was run.Oracle and test data
test_signed_64_bit_sources_sign_extend_a_32_bit_literalintests/test_rdna2_exec_bits.pypins its values against the ISA), throughtests/test_rdna2_ref_parity.py.s_flbit_i32_i64on the literal0xFACE5766(Rust0x20, Python0x25). The 300 seeded programs never paired one of these three instructions with a literal whose bit 31 is set.test_signed_64_bit_sources_sign_extend_a_literal_in_both_modelsfails 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 testa_literal_is_sign_extended_for_a_signed_64_bit_source_onlyrepeats the Python test's cases.Checklist
E_NOTIMPL), never a fake success.test_readme_sync.pychecks it). No README change needed.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
s_ashr_i64, s_bfe_i64 and s_flbit_i32_i64 read S0 as a signed 64-bit integer. When S0 is the 32-bit literal, AMD's RDNA 2 ISA (November 2020, section 6.2.1, "Literal Expansion to 64 bits", p. 43) says: "64-bit unsigned integer: zero extended to 64 bits; 64-bit signed integer: sign extended to 64 bits". The Python model has done this since the fix for these three instructions (signed_literal_s0 in emu/rdna2_exec_bits.py, tested by test_signed_64_bit_sources_sign_extend_a_32_bit_literal). The Rust port (crates/anyxboxx-rdna2-ref/src/scalar.rs) did not carry it over: read_scalar turns the literal into a u64 by zero extension for every 64-bit source, and these three instructions used it unchanged. Results with a literal whose bit 31 is set were therefore wrong in Rust and different from the Python: s_flbit_i32_i64 s51, 0xFFFFFFF0 Rust 32, Python 60 s_ashr_i64 s[40:41], 0x80000000, 1 Rust 0x0000000040000000, Python 0xFFFFFFFFC0000000 s_bfe_i64 (offset 4, width 40) Rust 0x0000000008000000, Python 0xFFFFFFFFF8000000 What changed: - read_signed64_s0 reads S0 as before and sign-extends it from 32 bits only when S0 is the literal code. A register pair or an inline constant is read unchanged, as in the Python (which only rewrites the literal). - binary_signed64 is the two-operand helper for s_ashr_i64 and s_bfe_i64 (64-bit signed S0, 32-bit S1, 64-bit result, SCC from the result); the generic binary() is left alone, so no other instruction changes. - s_flbit_i32_i64 uses read_signed64_s0 directly. S1 keeps reading the plain 32-bit literal. In the Python, S1 shares the rewritten literal, but both instructions only read its low 23 bits (shift count, or offset and width), so the two agree for every value. The unsigned and bitwise 64-bit sources (s_bfe_u64, s_flbit_i32_b64, s_mov_b64, ...) keep zero-extending; the tests check that too. Why the existing tests missed it: the 300 seeded parity programs never paired one of these three instructions with a literal whose bit 31 is set. It was found by running the same generator on 48,000 more seeds; one program ran s_flbit_i32_i64 on the literal 0xFACE5766 (Rust 0x20, Python 0x25). Tests: - scalar.rs: a_literal_is_sign_extended_for_a_signed_64_bit_source_only, the cases of the Python test, plus a register pair read without extension. - tests/test_rdna2_ref_parity.py: test_signed_64_bit_sources_sign_extend_a_literal_in_both_models compares the two interpreters on the three signed instructions and four unsigned or bitwise controls with five literals, and checks two values outright so that two models wrong in the same way cannot pass. It fails on the old binary. docs/rust-full-status.md and its French version record the finding. Not checked: Windows. The change is plain integer arithmetic. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01CVSn4bUDfLBFvceKVLPSX5@chatgpt-codex-connector[bot] on GitHub · 2026-11-26 17:32 UTC · original · edited 2026-11-26 17:33 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
3f7435aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.