rdna2: record an ISA conformance corpus for the decoder #540

Closed
csj0oe wants to merge 3 commits from upstream-pr/540 into main
csj0oe commented 2026-11-29 21:08:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T21:08:21Z.


What

115 cases covering instruction classes across control-flow contexts, stages and operand modes, each recording the encoded words and the decode they are expected to produce (465 instruction lines). tools/isa_conformance/model.py builds a covering array over the four factors and tools/isa_conformance/record.py regenerates the matrix cases, the record and the coverage counts from the case files.

Coverage over the realizable matrix is complete: 182 of 182 pairwise and 10 of 10 dangerous triples, with the remaining combinations recorded as not realizable and the reason. The opcode table covers 45 of 1,088 mnemonics across 1,401 (encoding, opcode) keys; that ratio is honest — this is an interaction matrix, not an opcode sweep.

The suite found four decoder gaps, recorded as exact-set ratchets rather than fixed here: DPP and sub-dword instructions lose their first source, v_readlane_b32 reports a VGPR instead of the scalar destination, VOP3B secondary destinations are not operands, and SMEM soffset is missing. Fixing one fails the ratchet until the list shrinks.

Where the encoded words come from

Every bytes line is LLVM's encoding of the case text, and every line is llvm-objdump's reading of the same object. Reproduce one case by hand:

llvm-mc -triple=amdgcn -mcpu=gfx1030 -filetype=obj -o case.o case.s
llvm-objdump -d --show-raw-insn case.o

The whole corpus, including the matrix cases:

python3 tools/isa_conformance/record.py matrix     # covering-array case files
python3 tools/isa_conformance/record.py generate   # words, expected decode, coverage
python3 tools/isa_conformance/record.py all

It needs only llvm-mc and llvm-objdump on PATH, and it fails listing every case when one does not assemble, so a record entry cannot drift from its case text or lose an instruction. LLVM 22.1.8 produced this record.

Two cases carry # cpu: gfx1010 because v_mad_f32 and v_madak_f32 have no gfx1030 encoding; the directive is in the case file and the record. No case is hand-encoded any more: the sub-dword case that used to hold hand-written words is now v_mov_b32 v1, v2 dst_sel:BYTE_1 src0_sel:BYTE_0.

No licensed or restricted output is committed. Everything here is LLVM assembler and disassembler output for text in this tree: no container bytes, no vendor disassembly text, no SDK headers, tables or binaries.

Two naming differences, normalised in the test

The expected text keeps LLVM's spelling; the test normalises it instead of renaming the decoder's output:

  • LLVM names the encoding form — v_mov_b32_e32, v_add_f32_e64, v_mov_b32_dpp, v_mov_b32_sdwa — where the decoder names the operation, so the suffix is dropped from the expected mnemonic.
  • LLVM 22 names the low half of the condition register vcc_lo; the decoder reports vcc.

The DPP8 expected text now names its permutation, which the previous record omitted, so dpp8-mov joins both gap ratchets.

Regenerating the matrix

tools/isa_conformance/model.py holds the factors, the class bodies, the contexts and the dangerous triples. record.py matrix rewrites fixtures/isa-conformance/matrix/ and matrix.txt; tests/test_isa_conformance.py recomputes the counts and fails if the two disagree.

<!-- greyfinch-sync:brcly/TuxBox:issue:5555138028 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/540). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-29T21:08:21Z. --- ## What 115 cases covering instruction classes across control-flow contexts, stages and operand modes, each recording the encoded words and the decode they are expected to produce (465 instruction lines). `tools/isa_conformance/model.py` builds a covering array over the four factors and `tools/isa_conformance/record.py` regenerates the matrix cases, the record and the coverage counts from the case files. Coverage over the realizable matrix is complete: 182 of 182 pairwise and 10 of 10 dangerous triples, with the remaining combinations recorded as not realizable and the reason. The opcode table covers 45 of 1,088 mnemonics across 1,401 `(encoding, opcode)` keys; that ratio is honest — this is an interaction matrix, not an opcode sweep. The suite found four decoder gaps, recorded as exact-set ratchets rather than fixed here: DPP and sub-dword instructions lose their first source, `v_readlane_b32` reports a VGPR instead of the scalar destination, VOP3B secondary destinations are not operands, and SMEM `soffset` is missing. Fixing one fails the ratchet until the list shrinks. ## Where the encoded words come from Every `bytes` line is LLVM's encoding of the case text, and every `line` is `llvm-objdump`'s reading of the same object. Reproduce one case by hand: ```sh llvm-mc -triple=amdgcn -mcpu=gfx1030 -filetype=obj -o case.o case.s llvm-objdump -d --show-raw-insn case.o ``` The whole corpus, including the matrix cases: ```sh python3 tools/isa_conformance/record.py matrix # covering-array case files python3 tools/isa_conformance/record.py generate # words, expected decode, coverage python3 tools/isa_conformance/record.py all ``` It needs only `llvm-mc` and `llvm-objdump` on `PATH`, and it fails listing every case when one does not assemble, so a record entry cannot drift from its case text or lose an instruction. LLVM 22.1.8 produced this record. Two cases carry `# cpu: gfx1010` because `v_mad_f32` and `v_madak_f32` have no gfx1030 encoding; the directive is in the case file and the record. No case is hand-encoded any more: the sub-dword case that used to hold hand-written words is now `v_mov_b32 v1, v2 dst_sel:BYTE_1 src0_sel:BYTE_0`. **No licensed or restricted output is committed.** Everything here is LLVM assembler and disassembler output for text in this tree: no container bytes, no vendor disassembly text, no SDK headers, tables or binaries. ## Two naming differences, normalised in the test The expected text keeps LLVM's spelling; the test normalises it instead of renaming the decoder's output: - LLVM names the encoding form — `v_mov_b32_e32`, `v_add_f32_e64`, `v_mov_b32_dpp`, `v_mov_b32_sdwa` — where the decoder names the operation, so the suffix is dropped from the expected mnemonic. - LLVM 22 names the low half of the condition register `vcc_lo`; the decoder reports `vcc`. The DPP8 expected text now names its permutation, which the previous record omitted, so `dpp8-mov` joins both gap ratchets. ## Regenerating the matrix `tools/isa_conformance/model.py` holds the factors, the class bodies, the contexts and the dangerous triples. `record.py matrix` rewrites `fixtures/isa-conformance/matrix/` and `matrix.txt`; `tests/test_isa_conformance.py` recomputes the counts and fails if the two disagree.
brcly commented 2026-11-29 21:11:50 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:11:50Z.


Thanks. A covering array over instruction class, context, stage and operand form is a good way to find decoder gaps, and the four you found are useful. Two questions before we can review it:

  1. The 45 matrix/ cases come from tools/isa_conformance/model.py, which isn't in the PR. Could you add it, so the matrix can be regenerated and reviewed?
  2. How were the encoded words produced? If they come from an assembler we can all run (for example LLVM's llvm-mc for gfx1030), please say so and add the command; if any came from the console reference compiler, they can't be committed (the same issue as #539 and #531).
<!-- greyfinch-sync:brcly/TuxBox:comment:7262681844 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/540#issuecomment-7262681844). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T21:11:50Z. --- Thanks. A covering array over instruction class, context, stage and operand form is a good way to find decoder gaps, and the four you found are useful. Two questions before we can review it: 1. The 45 `matrix/` cases come from `tools/isa_conformance/model.py`, which isn't in the PR. Could you add it, so the matrix can be regenerated and reviewed? 2. How were the encoded words produced? If they come from an assembler we can all run (for example LLVM's `llvm-mc` for gfx1030), please say so and add the command; if any came from the console reference compiler, they can't be committed (the same issue as #539 and #531).
brcly commented 2026-11-29 22:03:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:03:04Z.


Thanks, this addresses it: the words now come from llvm-mc, which anyone can run. We're putting it through the full check on both of our cards now and will merge it (as one squashed commit) if it passes.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263360955 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/540#issuecomment-7263360955). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:03:04Z. --- Thanks, this addresses it: the words now come from `llvm-mc`, which anyone can run. We're putting it through the full check on both of our cards now and will merge it (as one squashed commit) if it passes.
brcly commented 2026-11-29 22:13:41 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:13:41Z.


Merged as 6bab5478 on main (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7263506919 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/540#issuecomment-7263506919). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:13:41Z. --- Merged as 6bab5478 on `main` (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!540
No description provided.