Files
betterxen/docs/shaders/instruction-coverage.md
T
Ranveer Soni 42fb3f67ad test: verify gfx1030 decoding against LLVM and the reference
Compare decoded operations, operands, and instruction spans for all supported forms. Cover literal and register boundaries and distinguish malformed streams from valid encodings outside the subset.

Signed-off-by: Ranveer Soni <git@ranveersoni.me>
2026-11-22 13:56:16 +05:30

79 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# gfx1030 instruction coverage
The decoder accepts an explicitly tagged, little-endian gfx1030 Wave32
stream under the [synthetic memory ABI](../adr/0003-demo-memory-model.md).
Recognition means that the opcode mask matches. Decode additionally checks
operands, flags, instruction width and any literal word. Register
initialization and memory safety require verification after decoding.
| Form | Accepted encoding and operands | Size | Recognized | Decoded | LLVM fixture comparison |
| --- | --- | --- | --- | --- | --- |
| `buffer_load_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | pass |
| `s_waitcnt vmcnt(0)` | SOPP, exact immediate `0x3f70`; other counters disabled by their maximum values | 4 B | yes | yes | pass |
| `v_mov_b32_e32` | VOP1, VGPR destination, VGPR or inline integer or literal source, plus the inline bit pattern for +1.0f | 4 or 8 B | yes | yes | pass for literal, inline zero and inline +1.0f |
| `v_add_nc_u32_e64` | VOP3, VGPR destination and two VGPR inputs, modifier fields clear, third source field encoded as inline zero | 8 B | yes | yes | pass |
| `buffer_store_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | pass |
| `s_waitcnt_vscnt null, 0` | SOPK, exact null source and zero immediate | 4 B | yes | yes | pass |
| `s_endpgm` | SOPP, zero immediate | 4 B | yes | yes | pass |
## Automated three-way comparison
LLVM 23.1.6, the production decoder and the independent reference decoder
matched 303 instructions across five streams. These include three fixtures,
a high-register sequence and a 266-instruction matrix assembled by LLVM.
The harness checks byte offsets, widths, encoded bytes from LLVM, mnemonic
and operands, and the typed reference operation against the production
operation. It covers all 15 forms in this document.
The matrix checks the 81 inline integer selectors in VOP1, SOP1 and SOPC,
forced literals that could otherwise be inline, literal selection in either
SOPC operand, high SGPR and VGPR indices, MUBUF descriptor and index
operands, and zero and nonzero forward branch displacements. The decoder
trace exposes MUBUF operands independently of the synthetic execution ABI,
which still requires the original index and resource bindings.
Three malformed LLVM probes produced diagnostics, and six valid encodings
or disassemblable branch sequences were deliberately rejected by both Xenora
decoders. Both Xenora decoders also reject all 37 interior truncation offsets
in the add fixture and all 18 existing unsupported-encoding cases.
These case counts overlap where the same bytes are used in distinct tests.
The truncated VOP1 literal is checked in Xenora only. LLVM 23.1.6's direct
literal-truncation probe crashed, so it is outside the automated LLVM
negative matrix.
This is form and operand-class coverage. The matrix does not enumerate
every register combination, literal value or forward displacement. LLVM
supplies encoding and disassembly evidence. The reference and semantic
review tests exercise execution, including both SCC outcomes and the exact
FP32 domain. The native GPU demo verifies the three executable fixtures.
```sh
scripts/assemble-fixture.sh --check
LLVM_BIN="$(brew --prefix llvm)/bin" cargo test --locked -p xenora-decoder --test gfx1030 -- --include-ignored --nocapture
cargo test --locked -p xenora-ref -p xenora-semantic-review
scripts/demo.sh
```
The [source notes](../research/rdna2.md) record the XML revision and license.
## Expansion variants
AMD RDNA 2 ISA §§12.3–12.5 and 12.7 define these forms. AMD's pinned XML
and native LLVM 23.1.6 agree on the representative words. The target of each
branch is the byte offset after its four-byte instruction plus four times the
sign-extended 16-bit displacement. This subset requires forward targets at
instruction boundaries. The vector forms carry two VGPR sources and no
modifiers. Floating-point arithmetic and its mode constraints are execution
requirements outside the decoder.
| Form | Operands | Representative LLVM encoding | Recognized | Decoded | LLVM fixture comparison |
| --- | --- | --- | --- | --- | --- |
| `s_mov_b32` | Normal SGPR destination and normal SGPR, inline integer or literal source | `BE880387` | yes | yes | pass |
| `s_cmp_eq_u32` | Normal SGPR or integer operands, with at most one source selecting a literal | `BF068708` | yes | yes | pass |
| `s_cbranch_scc0` | Nonnegative signed dword displacement | `BF840002` | yes | yes | pass |
| `s_branch` | Nonnegative signed dword displacement | `BF820001` | yes | yes | pass |
| `v_and_b32_e32` | Two VGPR sources and one VGPR destination | `36020702` | yes | yes | pass |
| `v_xor_b32_e32` | Two VGPR sources and one VGPR destination | `3A020702` | yes | yes | pass |
| `v_add_f32_e32` | Two VGPR sources and one VGPR destination | `06020702` | yes | yes | pass |
| `v_mul_f32_e32` | Two VGPR sources and one VGPR destination | `10020702` | yes | yes | pass |