Skip to content

test_rdna2_decode: check the decoder's bytes against the assembled ones (parity fails on main with LLVM 21 and 23) - #4867

Open
lines9686-rgb wants to merge 1 commit into
ItsNotRexed:mainfrom
lines9686-rgb:test-rdna2-decode-parity
Open

lines9686-rgb wants to merge 1 commit into
ItsNotRexed:mainfrom
lines9686-rgb:test-rdna2-decode-parity

Conversation

@lines9686-rgb

Copy link
Copy Markdown

Item: new TEST item, claimed in #4816 (#4816 (comment)).

tests/test_rdna2_decode.py::test_parity_with_llvm_mc_on_shader_fixtures fails on main with both llvm-mc versions I have, while tools/rdna2_decode.py decodes the bytes correctly both times. The test assembles each fixture, disassembles the bytes with llvm-mc and compares the decoder to that listing:

  • llvm-mc 21.1.8 (the version the Linux CI installs, and the one make_game puts under %USERPROFILE%\.leonida\llvm-mc): disassembling v_cvt_f16_u16_sdwa v5, 1.0 ... src0_sel:WORD_1 (ps_sdwa_f16_const), it prints the re-encoding ff148500 003c0000 and the operand 15360, where the assembled bytes are f2148500 and the decoder says 1.0. Fix: the decoder's bytes are checked against the assembled bytes; operands are compared only where llvm-mc's printed encoding round-trips, with an upper bound (fewer than 5 per run) so the comparison keeps meaning something.
  • llvm-mc 23.1.6 (conda-forge, which docs/testing.md suggests on Windows): it prints exp's null target as the null register (special), the decoder as a target, as LLVM 21 does (ps_w64_a_discard). Both spellings now compare as one.

Test-only; the decoder is unchanged.

Tested

Windows 11, Python 3.12:

LLVM_MC main de67135 this branch
llvm-mc 21.1.8 FAILED (ps_sdwa_f16_const: f9a00a7ef2148500 != f9a00a7eff148500003c0000) OK
llvm-mc 23.1.6 FAILED (ps_w64_a_discard: target/special null) OK
none OK (parity test skips) OK

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code

The llvm-mc parity test failed on main with both LLVMs here although the
decoder was right:
- llvm-mc 21.1.8 re-encodes `v_cvt_f16_u16_sdwa v5, 1.0` (ps_sdwa_f16_const)
  when disassembling it, printing ff...003c0000 and "15360" for the inline
  f2...; the test compared against that. The decoder's bytes are now checked
  against the assembled bytes, and operands only where llvm-mc's printed
  encoding round-trips (at most a handful may not).
- llvm-mc 23.1.6 prints exp's null target as the null register; the decoder
  names it a target, as LLVM 21 does. Both spellings compare as one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent synthetic comparison at 8d43709 and #2811 3b47b72 including #2786. Both parity loops passed on LLVM 21.1.8 and 23.1.6. On LLVM 21 both catch an opcode mutation, but changing the decoded SDWA source from 1.0 to 2.0 passed this PR’s parity loop and failed the stack’s operand comparison. The dedicated SDWA test does cover this literal. The parity loops conflict on integration; retain the stack’s operand/modifier checks when LLVM re-encodes. AI-assisted CPU only.

@DenRakEiw

Copy link
Copy Markdown

Tested on Windows 11 / Python 3.12.10 at head 8d43709a218256f6997d69564fc4c957edd74543.

  • Trial-merge onto origin/main: Clean (git merge --no-commit --no-ff and git diff --cached --check exited 0).
  • Tests:
    • python -I tests/test_rdna2_decode.py: 8 passed, 1 skipped (test_parity_with_llvm_mc_on_shader_fixtures skipped because llvm-mc is not installed in this environment, so the modified parity path itself was not exercised live).

Code read: test_parity_with_llvm_mc_on_shader_fixtures cleanly handles LLVM 23's exp ... null operand kind and LLVM 21's SDWA re-encoding by checking decoder bytes against assembled raw bytes and capping re-encoded operand skips at < 5.

AI-assisted review (Gemini 4 Neon).

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS (review only; the parity test itself was skipped here).

py -3 -I tests/test_rdna2_decode.py gives 9 tests with 1 skipped, compileall clean, and the merge is clean. No llvm-mc and no encodings in the fixtures, so I probed the new logic offline instead: the byte check at tests/test_rdna2_decode.py:272-274 aligns over the real 5-insn SDWA sequence and decodes the PR's f9a00a7ef2148500 to the assembled bytes, and the exp null case differs before the norm_arg patch at :221 and matches after it. Both blocks do what the body claims.

One nit: there is no assert at == len(raw) after the loop at :274, so a final encoding shorter than expected would pass silently. Add it and this is solid.

AI-assisted review, no game files, no GPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants