Files
betterxen/docs/shaders/instruction-coverage.md
T
elforeign 0749330868 shader: Wave32 VOPC integer compares with VCC/EXEC rules
Adds v_cmp_{lt,eq,le,gt,ne,ge}_{i32,u32}_e32 across the chain: opcodes
generated from the pinned AMD XML, one typed VectorCompare instruction
(relation + signedness, table-driven decode), the reference interpreter,
the independent semantic-review interpreter, typed IR and MSL.

Rules (RDNA 2 ISA guide 3.9, 2.1, 3.3; contract in
docs/shaders/vector-compare.md): VCC_LO[n] = EXEC_LO[n] & test(lane n),
always fully written, so empty EXEC gives 0 and reads no source; VCC_HI
becomes unknown; EXEC, SCC and VGPRs are unchanged. A lane-derived
VCC_LO may feed only s_cbranch_vccz, v_mov_b32 vN, vcc_lo and another
compare's SRC0, so EXEC never becomes data-dependent. A runtime
s_cbranch_vccz is wave-uniform: the skipped code may hold only integer
vector ALU instructions with initialized destinations, checked whether
or not it is taken, and lowers to selects at the join.

The Metal kernel makes no SIMD-group, threadgroup or barrier assumption:
each thread rebuilds its RDNA wave's mask by recomputing the 32 lanes'
operands from their input words, bounded by threads_per_grid. The
reference now runs lockstep Wave32 waves; absent lanes of a final
partial wave contribute 0.

Verified with an original LLVM-assembled fixture and 251 programs
(every form on 10 boundary values in both operand orders, partial and
empty EXEC, both runtime branch edges in one dispatch, mask chains,
32 pinned rejections) against exact integer definitions. Translator,
reference and second interpreter agree on CPU; all 252 programs match
on native Metal with validation; LLVM agrees on every encoding.
Breaking any implementation (signedness, EXEC masking, empty EXEC,
absent-lane bound, join polarity or uniformity) fails the tests.

Fixes #186

Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
2026-11-24 02:22:19 -06:00

16 KiB
Raw Blame History

gfx1030 instruction coverage

For counts of every gfx1030 form in AMD's metadata against forms Xenora can execute, run xenora shaders coverage. Its "discovered" column is metadata coverage, not execution support.

The decoder accepts an explicitly tagged, little-endian gfx1030 Wave32 stream with 32 lanes per wave under the synthetic memory ABI. 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. CPU and GPU entries refer to the original synthetic fixture workloads. The wider LLVM operand matrix exercises decoding only. ABI means application binary interface. VGPRs are vector general-purpose registers and SGPRs are scalar general-purpose registers.

Form Operands Size or word Recognized Decoded LLVM Lowering Reference CPU GPU
buffer_load_dword MUBUF, VGPR data/index, four normal SGPRs, idxen, zero offsets and remaining flags 8 B yes yes three-way passed MSL load implemented fixture verified fixture verified
s_waitcnt vmcnt(0) SOPP, exact immediate 0x3f70; other counters disabled by their maximum values 4 B yes yes three-way passed verified load wait implemented fixture verified fixture verified
v_mov_b32_e32 VOP1, VGPR destination, VGPR, normal SGPR (wave-uniform, known during translation), vcc_lo (known or a compare mask) or inline integer or literal source, plus the inline bit pattern for +1.0f 4 or 8 B yes yes three-way passed constant or register value implemented fixture verified fixture verified
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 three-way passed MSL unsigned add implemented fixture verified fixture verified
buffer_store_dword MUBUF, VGPR data/index, four normal SGPRs, idxen, zero offsets and remaining flags 8 B yes yes three-way passed MSL store implemented fixture verified fixture verified
s_waitcnt_vscnt null, 0 SOPK, exact null source and zero immediate 4 B yes yes three-way passed verified store wait implemented fixture verified fixture verified
s_endpgm SOPP, zero immediate 4 B yes yes three-way passed verified termination implemented fixture verified fixture verified
s_mov_b32 Normal SGPR or EXEC/VCC half destination and normal SGPR, inline integer or literal source BE880387 yes yes three-way passed resolved scalar state implemented fixture verified fixture verified
s_cmp_eq_u32 Normal SGPR or integer operands, with at most one source selecting a literal BF068708 yes yes three-way passed resolved SCC implemented fixture verified fixture verified
s_add_u32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = carry-out 80088308 yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_sub_u32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = borrow 808A8180 yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_add_i32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = signed overflow 8110C109 yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_sub_i32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = signed overflow 8191C110 yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_addc_u32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; adds SCC; SCC = carry-out 820980FF 7FFFFFFF yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_subb_u32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; subtracts SCC; SCC = borrow 828B0809 yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_and_b32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 870D090C yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_or_b32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 880ED00D yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_xor_b32 SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 890C0A0B yes yes three-way passed resolved scalar state and SCC implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_lt_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 < S1), fully written 7D020701 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_eq_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 == S1), fully written 7D040280 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_le_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 <= S1), fully written 7D060208 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_gt_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 > S1), fully written 7D0802D0 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_ne_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 != S1), fully written 7D0A0301 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_ge_i32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 >= S1), fully written 7D0C02FF 80000001 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_lt_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 < S1), fully written 7D820701 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_eq_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 == S1), fully written 7D8402FF 80000000 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_le_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 <= S1), fully written 7D860208 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_gt_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 > S1), fully written 7D8802C0 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_ne_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 != S1), fully written 7D8A026A yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
v_cmp_ge_u32_e32 VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 >= S1), fully written 7D8C0D01 yes yes three-way passed per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_cbranch_scc0 Nonnegative signed dword displacement BF840002 yes yes three-way passed resolved conditional branch implemented fixture verified fixture verified
s_branch Nonnegative signed dword displacement BF820001 yes yes three-way passed resolved branch implemented fixture verified fixture verified
v_and_b32_e32 Two VGPR sources and one VGPR destination 36020702 yes yes three-way passed MSL bitwise AND implemented fixture verified fixture verified
v_xor_b32_e32 Two VGPR sources and one VGPR destination 3A020702 yes yes three-way passed MSL bitwise XOR implemented fixture verified fixture verified
v_add_f32_e32 Two VGPR sources and one VGPR destination 06020702 yes yes three-way passed MSL FP32 add implemented fixture verified fixture verified
v_mul_f32_e32 Two VGPR sources and one VGPR destination 10020702 yes yes three-way passed MSL FP32 multiply implemented fixture verified fixture verified
v_or_b32_e32 Two VGPR sources and one VGPR destination 3803FF01 yes yes three-way passed MSL bitwise OR implemented fixture verified fixture verified on Apple M5
v_lshlrev_b32_e32 Two VGPR sources and one VGPR destination 34020501 yes yes three-way passed MSL logical left shift with a five-bit count implemented fixture verified fixture verified on Apple M5
v_lshrrev_b32_e32 Two VGPR sources and one VGPR destination 2DFFFF01 yes yes three-way passed MSL logical right shift with a five-bit count implemented fixture verified fixture verified on Apple M5
v_ashrrev_i32_e32 Two VGPR sources and one VGPR destination 31FFFF01 yes yes three-way passed MSL signed right shift with a five-bit count implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_cbranch_execz Nonnegative signed dword displacement BF880001 yes yes three-way passed resolved Wave32 EXEC_LO zero check implemented local known-answer test passed local Apple M5 readback passed; acceptance pending
s_cbranch_vccz Nonnegative signed dword displacement BF860001 yes yes three-way passed resolved Wave32 VCC_LO zero check, or a wave-uniform join select after a vector compare implemented local known-answer test passed local Apple M5 readback passed; acceptance pending

Automated three-way comparison

LLVM 23.1.6, the production decoder and the independent reference decoder matched 650 instructions across ten streams: the eight synthetic fixtures, a high-register sequence and an operand 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 42 compute forms in this document.

The matrix checks the 81 inline integer selectors in VOP1, SOP1, SOPC and SOP2, forced literals that could otherwise be inline, literal selection in either SOPC or SOP2 operand, every supported SOP2 form, every VOPC compare with VGPR, SGPR, vcc_lo, inline and literal sources, VOP1 SGPR and vcc_lo sources, 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.

Five malformed LLVM probes produced diagnostics, and 25 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 every case in the unsupported-encoding list. 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.

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 record the XML revision and license.

Operand and execution notes

AMD RDNA 2 ISA §§12.3–12.5 and 12.7 define the scalar and vector 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.