rdna2spirv: refuse a line with too few operands before lowering (D3D12-TRANSLATOR-MISSING-OPERAND) #3266
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!3266
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/translator-missing-operand"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: D3D12-TRANSLATOR-MISSING-OPERAND (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7353400606), from @imShangLi's finding.
What and why
A hand-written listing line with too few operands (a fixture typo) made
tools/rdna2spirv.pyend in a Python traceback (IndexError,ValueErrorfrom unpacking,TypeError) at whichever operand read came first, because theexcept (IndexError, TypeError)at the end ofGen.insnonly turned the no-operand case intoUnsupported. AnIndexErrorcarries no index, so widening thatexceptwould also hide real translator bugs; this adds an operand-count check instead.MIN_OPERANDSis built once at import from the decoder's ISA tables (tools/rdna2_isa_tables.py, already a translator dependency intranslator_deps.cmakeandmake_game.TRANSLATION_SOURCES), one operand per field, keyed by(mnemonic, encoding family):_e64-> VOP3/VOP3B,_e32/_sdwa/_dpp-> VOP1/VOP2/VOPC, an unsuffixed mnemonic -> the fewest over its encodings. ~1,900 entries, ~1-3 ms at import.v_cmpxdestination (EXEC), the implicit VCC operands of VOP2/VOPC short forms (v_cndmask_b32 vD, s0, s1,v_add_co_ci_u32_e32 vD, vcc, s0, s1,v_cmp_class_f32_e32 s0, s1), the VDST of a FLAT-family atomic withoutglc(or withlds), and the VDATA of a buffer/FLAT-family load withlds(LLVM printsbuffer_load_dword v0, s[4:7], 0 offen lds).NOOPSand mnemonics outside the tables are not checked.Gen.insn, i.e. only for instructions that are actually lowered: words afters_endpgm(embedded constant tables, which can decode into short lines) are untouched, as onmain. Cost: one or two dict lookups per lowered instruction (~0.5 us).Unsupported("<op>: expects N operands, got M");test_insn_no_operands.py's expected message changes accordingly (v_add_f32: expects 3 operands, got 0).Note: the first commit's message says LLVM always prints every operand; that is not quite true (the MUBUF
ldsform above), which the second commit handles and documents. Squash on merge if preferred.No
docs/design.mdcontract row: this is input validation and changes no emitted SPIR-V (the previous no-operand conversion had none either).Tested
tests/semantic/test_insn_operand_count.py: 11 short lines across the reported crash sites (Gen._insn,v_max3/v_med3unpacking,compare,sop2_b32_srcs,holds_lane_mask,scalar_load,buffer_address,lds_op, a shortglobal_load_dword,v_cndmask_b32_e64with 3 operands) assert the exact message; complete lines and the short assembler forms still translate; an LLVMldsbuffer load keeps itsbuffer_load_dword formrejection; short junk afters_endpgmstill translates.tools/rdna2spirv.pyrestored frommain): the new file fails 11 subtests (IndexError/ValueError, andv_cndmask_b32_e64 v0, v1, v2silently translating). Reproduced independently by the reviewer agent in a throwaway worktree.test_insn_no_operands,test_wave64_halves_soundness,test_valu_f32_class_rndne,test_sdwa_carry,test_scalar_noop_waitcntpass.python -I scripts/run_semantic_tests.py tests/semantic-> 561 files, 6758 tests, 0 files failed.off,lds, atomics with/without glc), GLOBAL/SCRATCH/FLAT, DS (gds, swizzle), MIMG (bvh, msaa, bracketed addresses): 0 rejected. 1.6M random encodings throughrdna2_decode->format_insn->parse_line-> the check: only the decoder's VOP2madak/madmk/fmaak/fmamk_dpp/_sdwaforms, which LLVM rejects as invalid encodings (posted as a separate finding; they are only checked if actually lowered). All 16,456 instruction lines of the repo's 393.asmfiles pass, except a branch to a label nameddonethat never reachesGen.insn(separate finding:MODWORDSstripsdone).python -m compileall -q make_game.py tools tests;python -m unittest discover -s tests -p "test_docs_*.py"(57 OK);python -I scripts/check_no_game_data.py.GPUs tested: n/a (translator input validation; no SPIR-V change, CPU-only tests)
AI-assisted: yes. Implementation: Claude Opus 5.5 (Claude Code). Independent read-only reviewer agent: Claude Opus 5.5 - first pass "changes needed" (check ran on unreachable code;
ldsloads mislabelled; shortglobal_loadstill crashed; encoding-blind minimum), all addressed in the second commit; second pass approve, remaining nits applied or noted here.Follow-up noted by the reviewer (not in this PR):
explicit_carry_vccexpands a 3-operandv_*_co_ci_u32_e64line as if it were the VOP2 short form, so that malformed_e64line still translates (same asmain).Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: input validation, no new lowering rule)🤖 Generated with Claude Code
Independent Windows reproduction on PR head
31b96e3ba3c4c9b35c5dd92a50c6a5cc07a600f5(Windows 11, Python 3.12.10):test_dpp_invalid_opcodes_and_boundary_modifiersfails at line 307: the “Missing DPP control” case callsGen.insnwith zero operands, so the new operand check raisesv_mov_b32_dpp: expects 2 operands, got 0before the DPP-control validation; the expectedDPP controlregex therefore does not match. This matches the failingtests/test_rdna2spirv_decode.pycheck in CI. Supplying two synthetic VGPR operands in this case would let it exercise the DPP-control path, while the separate operand-count test continues covering zero operands. No game data or GPU used.VERIFY-3266 — Windows nativo:
red then greenen los dos ficheros de test8cdd86ac1—tests/semantic/test_insn_operand_count.py(+19),tests/test_rdna2spirv_decode.py(10),tools/rdna2spirv.pyRan at the head
Negative control: the commit's own hunk does not revert cleanly (the branch carries a merged
main), so I putmain'stools/rdna2spirv.pyback and re-ran both:Three bite, and they are the two halves of the change: the message names the op, and a line that is short but not empty is not "no operands".
What the change is, and it is a good distinction: before, any instruction whose operands could not be read raised
Unsupported("<op>: no operands")— including a line that had operands, just fewer than its ISA table entry expects. Nowcheck_operand_countssays"<op>: expects N operands, got 0"for a mnemonic in the ISA tables, andGen.insnkeeps"no operands"for another mnemonic — soindex.json, which is built from these, points at the right instruction for the right reason.And the exemption list is the part that shows it was thought through:
s_endpgm,v_nop,v_clrexcp,ds_nop,s_barrierin compute stay untouched — "their ISA table entries have no operands and they never fail an operand read". A rule that says "zero operands is an error" would have flagged every one of them, and the comment says why they are not.What I could not test
Written with an AI assistant.
VERIFY-3266 — PASS
PR #3266 | head 8cdd86ac19816fde5ca8d69d77649fac4bfe74f5 | merged cleanly with current main (d9b618f10) in a scratch worktree, no conflicts
Tests run: tests/semantic/test_insn_no_operands.py, tests/semantic/test_insn_operand_count.py, tests/test_rdna2spirv_decode.py (python -I, stdlib unittest)
Red on main: all three files FAILED on main code with the PR's tests (failures=1, failures=17, failures=1) — MEASURED
Green on PR: all three files OK after merge (4 + 5 + 25 tests) — MEASURED
Diff audit: 4 files, tools/rdna2spirv.py + 3 test files only; operand-count refusal before lowering, no game data (check_no_game_data.py clean on the touched files) — READ IN CODE
Platform: Linux, Python 3.12.3, no GPU
AI-assisted: yes (Muse Wonder, Muse by Meta)
Windows native verification (
red -> green) -- PASS on head8cdd86ac1(merged cleanly viagit merge --no-ffontomaind9b618f10).Checks (Windows 10 x64, Python 3.12, PowerShell 5.1)
python -I scripts/check_no_game_data.py-> PASSpython -I tests/test_rdna2spirv_decode.py -v-> Ran 25 tests in 0.088s / OKpython -I tests/semantic/test_insn_no_operands.py -v-> Ran 4 tests in 0.134s / OKpython -I tests/semantic/test_insn_operand_count.py -v-> Ran 5 tests in 0.194s / OKtools/rdna2spirv.pytomaind9b618f10, keeping the PR's tests):tests/test_rdna2spirv_decode.py-> Ran 25 tests in 0.081s / FAILED (failures=1) (exit1)tests/semantic/test_insn_no_operands.py-> Ran 4 tests in 0.088s / FAILED (failures=1) (exit1)tests/semantic/test_insn_operand_count.py-> Ran 5 tests in 0.188s / FAILED (failures=17) (exit1)AI-assisted: yes (Antigravity -- Gemini 4 Neon).