fix: the Rust RDNA 2 interpreter keeps the model's NaN for the unfused multiply-adds #484
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/484"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by Luke-Ervin on 2026-11-27T04:11:14Z.
Change
The Rust reference interpreter (
crates/anyxboxx-rdna2-ref) now returns the same NaN as the Python model for the unfused multiply-addsv_mac_f32,v_madmk_f32andv_madak_f32.They were written as the plain expression
a * b + c(vector.rs). Which NaN such an expression returns is not fixed by the language: with both a factor and the addend NaN, the compiler may evaluate the addition with its operands swapped, and here it did. The Rust returned the addend's NaN where the model (_mul_add, x86-64 arithmetic) returns the product's:v_madak_f32 v4, v1 (1.5), v2 (0x7FC00B0B), K =0x7FC00C0C0x7FC00C0C0x7FC00B0Bv_madmk_f32 v4, v1 (1.5), K =0x7FC00C0C,v2 (0x7FC00B0B)0x7FC00B0B0x7FC00C0Cv_mac_f32 v2 (acc 0x7FC00B0B), v3 (1.0), v1 (0x7FC00A0A)0x7FC00B0B0x7FC00A0Afloat::mul_add(a, b, c)writes the model's order out: the first NaN factor (a, thenb), or the NaN the product itself makes (∞ × 0), and only then a NaN addend. With no NaN operand it computesa * b + cas before (∞ − ∞ gives the processor's NaN, as in the model). The product's own NaN has to come before a NaN addend, as in(a * b) + c; a plain "first NaN operand" rule would get ∞ × 0 + NaN wrong.v_mac_f32,v_madmk_f32(a, K, b) andv_madak_f32(a, b, K) use it.v_mad_f32(vop3.rs) uses it too. It gave the model's NaN in this build, but only by the compiler's choice, and CI builds the crate for Windows at a different optimisation level, so it is written out rather than left to chance. Its results do not change here.The fused forms (
v_fma_f32,v_fmac_f32,v_fmamk_f32,v_fmaak_f32) are untouched: they go throughfloat::fma, which already picks the NaN explicitly.As with the port's other NaN rules (
float::fma, the float atomics,v_interp), this follows the model's host arithmetic, not a measured RDNA 2 result: the ISA does not say which NaN an unfused multiply-add returns.docs/rust-full-status.mdanddocs/fr/rust-full-status.mdrecord the finding. No README row or test-count change (1908 collected onmainwith this change, still1900+).Linked issue: none.
Verification
Run on Linux (Ubuntu, Python 3.13, Rust 1.98.1), on top of
mainatb62053f, and again merged with the newestmainand with #402, #403 and #437 (1459 passed, 452 skipped), withanyxboxx-rdna2-refandanyxboxx-pebuilt bycargo build --release -p anyxboxx-rdna2-ref -p anyxboxx-pe:Not run (the 452 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 new helper only compares and selects values, so its result no longer depends on how the compiler orders the operations. No game was run.Oracle and test data
tests/test_rdna2_ref_parity.py.mainwith #402, #403 and #437 merged in. Five programs ended with a different NaN in a register; the three traced were all av_madak_f32with a NaN K. With this change the same 60,000 programs end with the same values in both models.test_unfused_multiply_add_nans_match_the_python_modelfails on the old binary. It runsv_mad_f32,v_mac_f32(VOP2 and VOP3),v_madak_f32andv_madmk_f32with each of the three operand positions finite, +inf, +0 or a NaN whose payload names its position: 320 programs, all of which run in both models, with NaN results covering every position and the processor's NaN. It also checks two values outright, so that two models wrong in the same way cannot pass. Rust unit test:mul_add_keeps_the_nan_of_the_product_before_the_addend(float.rs).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
Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-27T04:11:27Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
4de8438ℹ️ 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.