diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 13:12:28 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 13:14:44 +0100 |
| commit | e901a7b99aa88d57009e5f9aca3ce838e5ccae8d (patch) | |
| tree | 33739b11a86a836d223a432f64ad3a0dae596685 /docs/isa_coverage.md | |
| parent | 99f99890c5ebe186ef2f9fe8ff6d675745d9e621 (diff) | |
tools: isa_coverage.py, RDNA2 ISA coverage of the translator from AMD's XML
Reads AMD's machine-readable RDNA2 ISA spec (path given with --isa, not vendored), scans
tools/rdna2spirv.py statically with ast and reports, per encoding, which instructions have a
rule, are refused or are unknown, plus every matched name that is not an RDNA2 instruction.
Tests use a small hand-written fixture; the real-XML test skips without LEONIDA_RDNA2_ISA_XML.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs/isa_coverage.md')
| -rw-r--r-- | docs/isa_coverage.md | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/docs/isa_coverage.md b/docs/isa_coverage.md new file mode 100644 index 000000000..c91d90b3d --- /dev/null +++ b/docs/isa_coverage.md | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | # RDNA2 ISA coverage of the translator | ||
| 2 | |||
| 3 | `tools/isa_coverage.py` compares the instructions of AMD's machine-readable RDNA2 ISA specification with what | ||
| 4 | `tools/rdna2spirv.py` has a rule for. It reads no game data and needs no GPU; it is a count over the public ISA and | ||
| 5 | the translator's source. | ||
| 6 | |||
| 7 | ## Getting the specification | ||
| 8 | |||
| 9 | AMD publishes the XML files on GPUOpen, [AMD machine-readable GPU ISA documentation](https://gpuopen.com/machine-readable-isa). | ||
| 10 | The zip is not in this repository (the RDNA2 file alone is 11 MB): | ||
| 11 | |||
| 12 | ```sh | ||
| 13 | curl -L -o isa.zip https://gpuopen.com/download/machine-readable-isa/latest/ | ||
| 14 | unzip isa.zip amdgpu_isa_rdna2.xml | ||
| 15 | ``` | ||
| 16 | |||
| 17 | The numbers below come from the package `AMD_GPU_MR_ISA_XML_2026_08_06.zip` (SHA-256 | ||
| 18 | `82404f1126761b7877595b622afa7e1f311f2f41e89a3abe9aaf8ad045c082e2`), whose `amdgpu_isa_rdna2.xml` is "AMD RDNA 2", | ||
| 19 | schema 1.1.1, release date 2026-02-20, and carries `<License>MIT</License>`. AMD's reader for the same files is the | ||
| 20 | C++ [isa_spec_manager](https://github.com/GPUOpen-Tools/isa_spec_manager) (MIT); the schema is documented there in | ||
| 21 | `documentation/spec_documentation.md`. This tool parses the XML itself with `xml.etree`. | ||
| 22 | |||
| 23 | ## Running it | ||
| 24 | |||
| 25 | ```sh | ||
| 26 | python -I tools/isa_coverage.py --isa amdgpu_isa_rdna2.xml # markdown report | ||
| 27 | python -I tools/isa_coverage.py --isa amdgpu_isa_rdna2.xml --list # plus the unknown instructions per encoding | ||
| 28 | python -I tools/isa_coverage.py --isa amdgpu_isa_rdna2.xml --json | ||
| 29 | python -I tools/isa_coverage.py --isa amdgpu_isa_rdna2.xml --llvm-mc llvm-mc # classify non-RDNA2 names with llvm-mc | ||
| 30 | ``` | ||
| 31 | |||
| 32 | `--isa` defaults to `$LEONIDA_RDNA2_ISA_XML`. With that variable set, | ||
| 33 | `python -I tests/test_isa_coverage.py` also checks the real translator against the real XML; without it those tests | ||
| 34 | skip and the rest runs on a small hand-written fixture in the same schema. | ||
| 35 | |||
| 36 | ## What the classes mean | ||
| 37 | |||
| 38 | The translator dispatches on the opcode string with one long if/elif chain (`Gen._insn`), so the tool reads the | ||
| 39 | source with `ast` instead of running it: | ||
| 40 | |||
| 41 | | class | meaning | | ||
| 42 | |---|---| | ||
| 43 | | handled-exact | the name is compared with `op` (`==`, `in`) or is a key of a mnemonic table (`NOOPS`, `F2`, ...) | | ||
| 44 | | handled-family | no exact name, but it starts with a prefix `_insn` or a method it hands `op` to tests with `op.startswith` | | ||
| 45 | | refused | the name sits in a test whose whole body is `raise Unsupported(...)` | | ||
| 46 | | unknown | none of these: the final `raise Unsupported(op)` is what it reaches | | ||
| 47 | |||
| 48 | Limits. "Handled" means a rule exists, not that the rule is right; the GPU tests and `tests/semantic` do that. | ||
| 49 | A broad prefix such as `ds_` marks every `ds_*` instruction handled-family even where a sub-dispatch refuses one | ||
| 50 | form, so read handled-family as an upper bound; the instructions whose branch contains a `raise Unsupported` are | ||
| 51 | listed separately ("handled but with operand forms that raise"). Names built by string formatting are invisible. | ||
| 52 | Only the AMD XML defines the denominator: it omits a few gfx1013 instructions that LLVM accepts (below), and lists | ||
| 53 | some that a desktop part does not execute. | ||
| 54 | |||
| 55 | ## Result (translator at `bb2e1842`, AMD XML of 2026-08-06) | ||
| 56 | |||
| 57 | 1,153 RDNA2 instructions: 418 handled-exact, 411 handled-family, 2 refused (`s_denorm_mode`, `s_round_mode`), 322 | ||
| 58 | unknown. The unknown ones cluster in groups the corpus does not need or that are not written yet: the f64 | ||
| 59 | transcendentals and `v_div_*`, FLAT and SCRATCH memory, the global atomics, the `image_gather4*` variants outside the | ||
| 60 | four `_l`/`_lz` forms, packed image formats (`*_pck`, `*_by2`), the 16-bit `v_pk_*` integer forms, `v_dot*`, and the | ||
| 61 | `*_saveexec` / `s_nand`/`s_nor`/`s_xnor` scalar forms. `python -I tools/isa_coverage.py --list` has the full list per | ||
| 62 | encoding. | ||
| 63 | |||
| 64 | Names the translator matches that are not in the RDNA2 XML (15), each checked with | ||
| 65 | `llvm-mc -arch=amdgcn -mcpu=gfx1013`: | ||
| 66 | |||
| 67 | | name | llvm-mc for gfx1013 | verdict | | ||
| 68 | |---|---|---| | ||
| 69 | | `s_and_b32_mask`, `s_or_b32_mask` | invalid instruction | dead: nothing in the repository produces them | | ||
| 70 | | `v_add_u16`, `v_sub_u16` | other GPU only | internal: `v_add_nc_u16` / `v_sub_nc_u16` are re-dispatched under these names | | ||
| 71 | | `v_subrev_u16`, `v_and_b16`, `v_or_b16`, `v_xor_b16` | other GPU only | dead GFX9 spellings, harmless | | ||
| 72 | | `s_delay_alu` | other GPU only (RDNA3) | deliberate, in `NOOPS` | | ||
| 73 | | `v_mac_f32`, `v_mad_f32`, `v_mad_legacy_f32`, `v_madak_f32`, `v_madmk_f32`, `s_get_waveid_in_workgroup` | valid | real gfx1013 instructions that AMD's XML omits | | ||
| 74 | |||
| 75 | None is a typo that breaks translation, so there is nothing to fix in the translator; the two `_mask` names and the | ||
| 76 | four dead 16-bit spellings are candidates for removal. No name ends in a suffix `base_op()` strips (`_e32`, `_e64`, | ||
| 77 | `_sdwa`, `_dpp`), and every `startswith` prefix matches at least one RDNA2 instruction. | ||