The B3 oracle (#309) checks v_not_b32, v_bfrev_b32, v_ffbh_u32,
v_ffbl_b32, v_ffbh_i32 and v_swap_b32 against the guide on both CPU
interpreters, but its native Metal half was skipped because the
translator did not accept the forms. This adds the VOP1 registry file and
operand rule, decoder dispatch, IR and MSL lowering (v_swap_b32 writes
both VGPRs, each merged under EXEC), fixture and goldens, and removes
the oracle's skip from scripts/test-gpu.sh.
A new CPU test checks that the compiler accepts every case of the
oracle and rejects each of its rejections at the same word.
v_mov_b32 stays hand-written.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
s_mov_b32 was the last hand-written SOP1 decode path. It becomes
ScalarUnaryOp::MovB32 under a new sop1_move operand rule that matches the
old hand-written domain exactly (it accepts more SDST and SSRC0 classes
than sop1_sgpr, which other unary forms keep).
A decode sweep of 33,664 s_mov_b32 words shows no behaviour change: the
21,010 accepted words differ only in the instruction's name and the 12,654
rejections are identical. IR and MSL goldens are unchanged.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Declares s_movk_i32, s_cmovk_i32, s_cmpk_{eq,lg,gt,ge,lt,le}_{i32,u32},
s_addk_i32 and s_mulk_i32 as registry data under the new operand rules
sopk_sgpr and sopk_compare (SDST s0-s105 only, SIMM16 never a literal),
with the operations mov and cmov, the sext_simm16 primitive and an XML
check of the 16-bit immediate. The decoder dispatches them through the
generated ScalarImmediateOp and ScalarImmediateCompareOp (the fixed
0xbbfd0000 fence keeps its own decoding) and the translator folds them
into its scalar state like SOP2 and SOPC, refusing writes to s0-s7.
The guide-derived oracle in tests/validation/tests/sopk.rs is unchanged.
Adds IR and MSL goldens for the new fixture, LLVM-checked decoder words,
a known answer, an isa dispatch test and generator unit tests.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
v_and_b32, v_or_b32, v_xor_b32, v_lshlrev_b32, v_lshrrev_b32 and
v_ashrrev_i32 (_e32) are now registry forms under a new operand rule
vop2_vgpr2: both sources VGPRs, the subset the hand-written decoder
accepted. The rule shares the VectorAluOp enum with vop2_vgpr; the
generator renders one enum per shared rule set and an operand_rule()
the decoder dispatches on. VectorBinary gains And, Or, Xor and the three
shifts with the count masked to S0[4:0]; the shifts declare reversed
sources, and the generator now checks the XML count format on SRC0 for
reversed forms. The six hand-written Instruction variants, decoder arms
and shader Binary variants are removed; the runtime-region allowlist
admits exactly the same six forms.
No behaviour change: 132,608 VOP2/VOP1/SOP1 words decode to the same
text, length and error before and after; the MSL goldens are unchanged.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
- Includes must be `<root stem>/<family>.toml`, so a family file cannot
live outside the registry directory or be aliased past the repeat
guard. The coverage report (and through it the RDNA2 planner) now uses
the generator's loader, so the family-file guards apply to every
consumer.
- A variant's explicit XML operand formats, destination included, must
equal its base encoding's; malformed variant fields are diagnosed
instead of raising.
- Variants get their own generated enum (VectorAluVop3Op: from_word,
base, assembly_name, semantics), so Instruction::VectorAluVop3 cannot
name an undeclared encoding and formatting cannot panic.
- The planner no longer counts a variant-only operand rule as a rule that
can host new forms of its family (V_FMA_F32 was shown as reuse-ready).
- The isa test checks that no first word of another 64-bit family
(VOP3B) selects a VOP3 variant; docs describe the variant files.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
An [[encoding_variant]] re-encodes a declared form in another family: it
names the form, the family, its opcode there and that encoding's operand
rule, and inherits the rest. The XML check runs on the inherited
declaration, and the generator rejects variants of undeclared forms, in
the form's own family, duplicates, rules that cannot encode the form and
forms that use a variant-only rule. It emits from_<family>_word and
<family>_assembly_name on the base enum and one FORMS row per variant.
rdna2/vop3.toml declares the vop3_vgpr2 rule (the subset the hand-written
decoder accepted: VGPR sources, no modifiers, unused SRC2) and the VOP3
encoding of V_ADD_NC_U32. The decoder dispatches it through
VectorAluOp::from_vop3_word into Instruction::VectorAluVop3, which replaces
AddNoCarryU32; the shader lowers it through the VOP2 form's template and
still admits only v_add_nc_u32_e64 inside a runtime s_cbranch_vccz region.
Goldens, known answers and the LLVM oracle are unchanged.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds the four constant Wave32 VOPC compares as registry forms with the
relations f and t (guide Table 59 offsets 0 and 7), valid only for the
vopc_vcc rule, backed by false_b32/true_b32 primitives. They keep the
#239 contract: sources are decoded and checked as for every compare,
VCC_LO := EXEC & existing lanes & test, fully written, and the mask is
lane-derived. Their MSL wave mask reads no operand bits. A new
LLVM-assembled fixture covers F clearing a stale VCC, T and F under
partial EXEC, T reading vcc_lo and runtime s_cbranch_vccz on both
results; the oracle merged from task/215-vopc-oracle supplies the
reference side.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
The v_cmp_{lt,eq,le,gt,ne,ge}_{i32,u32}_e32 forms from #239 are now
registry data under a new vopc_vcc operand rule (SRC0 a vector_source,
VSRC1 a VGPR, destination implicitly vcc_lo). The decoder dispatches them
through the generated VectorCompareOp instead of a hand-written opcode
table, and the hand-written VectorCompareOp struct in xenora-isa is gone.
No behaviour change: goldens, known answers and the LLVM oracle are
unchanged.
The vocabulary gains vcc = "lane_mask", allowed exactly for the VOPC rule
and required to account for the XML's implicit VCC output, and wave =
"wave32", now allowed exactly for that rule (its one entry point is the
Wave32 compute fixture ABI) and still rejected elsewhere. exec must stay
unchanged, so v_cmpx cannot be declared.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Review follow-up: the generator now rejects a form whose XML lists an
implicit operand other than SCC (for example the VCC carry of
v_add_co_ci_u32 or the VCC select of v_cndmask_b32), since the
vocabulary can only declare VCC and EXEC unchanged. New known-answer
tests read a lane-derived vcc_lo as VOP2 SRC0 (also on native Metal)
and require the forms to be refused inside a runtime s_cbranch_vccz skip
region. The LLVM comparison normalises inline SRC0 for the registry VOP2
forms as for VOPC; docs and counts follow.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}, v_min/max_{i32,u32},
v_xnor_b32 and v_{add,sub,subrev}_nc_u32 as registry data under a new
vop2_vgpr operand rule (VGPR destination; SRC0 a VGPR, s0-s105, vcc_lo,
an inline integer or a literal; VGPR VSRC1). Vector forms select a
per-lane VectorBinary from their declared operation and signedness, and
the shader lowers each VectorBinary through one typed MSL template; SUBREV
declares source_order = reversed. Variant names are now unique per
generated enum. The decoder shares the VOPC SRC0 decode, and the
translator binds a result to the slot it was pushed at, since operand
constants may now be pushed first. The oracle merged from
task/215-vop2-oracle supplies the reference side; a new LLVM-assembled
fixture computes every lane from its own input.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds s_min/max_{i32,u32}, s_cselect_b32, s_bfm_b32, s_mul_i32,
s_mul_hi_{u32,i32}, s_bfe_{u32,i32}, s_absdiff_i32 and
s_lshl1..4_add_u32 as registry data over new shared primitives. The
vocabulary gains a selected_src0 SCC effect (min and max: S0 won the
strict compare), the select's SCC input (carry_in = scc, required for
cselect), a declared shift_amount for the shift-and-add forms, and a
check that BFE's S1 descriptor is unsigned in the XML. The generated
ScalarAluOp::evaluate now returns an optional SCC, so forms whose XML
shows no SCC output leave it unchanged in the translator. The decoder
picks them up through the generated SOP2 table; the oracle merged from
task/215-sop2-arith-oracle supplies the reference side. A new
LLVM-assembled fixture chains all sixteen.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Review follow-up: the native test only checked that compilation failed,
so a regressed destination guard still passed when a later instruction
read an uninitialized SGPR (shown by allowing vcc_lo as a destination).
It now requires a decode error at the SOP1 offset. Also check that no
registry form duplicates a hand-written decoder form.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds eleven SOP1 forms as registry data: complement, bit reverse, bit
counts, find-first and find-last searches, sign extension and absolute
value. Sign extension declares source_bits, which the generator checks
against the XML's 8- and 16-bit source operands; forms whose XML shows
no SCC output must declare SCC unchanged. The decoder dispatches them
through the generated SOP1 table after s_mov_b32, and the translator
folds them with ScalarUnaryOp::evaluate. The separately written oracle
from task/215-sop1-oracle supplies the reference side.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds a compare operation with a declared relation and the sopc_scalar
operand rule, so all twelve s_cmp_*_{i32,u32} forms are registry data.
The decoder dispatches them through the generated OP table and the
translator resolves SCC with ScalarCompareOp::test; the hand-written
s_cmp_eq_u32 path and its opcode constant are gone. A new LLVM-assembled
fixture records every compare's SCC, and the separately written oracle
from task/215-stage-d-oracle supplies the reference side.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds andn2, orn2, nand, nor, xnor, lshl, lshr and ashr as registry
primitives with a declared shift-count width that the generator applies
as a mask and checks against the XML's unsigned count operand. The forms
reach the decoder and translator through the generated dispatch with no
per-form Rust. The independent oracle side lands separately.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
generate_semantics.py validates the registry against its closed
vocabulary and the pinned XML snapshot (opcode, family, SCC input and
output, operand widths and signed formats) and emits static Rust tables.
The decoder now selects SOP2 operations through the generated from_word
match, and ScalarAluOp's mnemonic, SCC read and evaluation come from the
registry through shared primitives instead of hand-written per-opcode
code. The nine SOP2 opcode entries leave generate_rdna2.py.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
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>
#185 left both forms unsupported because the pinned XML says only
"carry-out" for them. The AMD RDNA 2 ISA reference guide (GPUOpen,
section 12.1 SOP2 Instructions, p. 101-102, and section 5.3 Scalar
Condition Code, p. 33) defines SCC for both as signed overflow:
add overflows when the operands share a sign that the result lacks;
subtract when the operands' signs differ and the result's sign differs
from S0's. The guide also confirms the unsigned rules used in #185.
Adds both forms to the generated opcodes, the decoder, the reference
(exact signed result must fit in i32), the independent interpreter (the
guide's sign-bit rule over its ripple adder) and the translator, plus
400 boundary programs, eight hand-worked overflow and no-overflow cases
(-1 + 1 and 0 - 1 carry or borrow but do not overflow) and two signed
overflows in the scalar ALU fixture. Inverting the overflow rule in any
one implementation fails three tests. s_min_i32 and the other SOP2
forms stay unsupported.
Refs #185
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
Adds s_add_u32, s_sub_u32, s_addc_u32, s_subb_u32, s_and_b32, s_or_b32
and s_xor_b32 across the chain: generated opcodes from the pinned AMD
XML, a typed ScalarAlu instruction, decoding, the reference interpreter,
the independent semantic-review interpreter and the translator, which
resolves scalar state and SCC as it already does for s_mov/s_cmp.
v_mov_b32_e32 may now read a normal SGPR, so results reach vector code
as constants.
SCC: the XML states carry-out for additions, carry-in for ADDC/SUBB and
nonzero results for bitwise forms. For subtraction it says carry-out
without fixing the polarity; LLVM's lowering of usubo and of 64-bit
subtraction to s_sub_u32/s_subb_u32 requires SCC to be the borrow.
s_add_i32/s_sub_i32 stay unsupported: no pinned source settles whether
their SCC is the carry or signed overflow.
Verified with an original LLVM-assembled fixture and 1,400 boundary
programs (every form, 10x10 operands, SCC clear and set) against exact
integer definitions; translator, reference (exact integers) and
independent interpreter (bit-serial ripple adder) all agree, and all
1,401 programs match on native Metal with validation. LLVM agrees on
every encoding. Breaking any one implementation fails the tests.
Fixes#185
Independent review fixes: both interpreters now require a known SGPR
for v_mov_b32 from an SGPR even in an inactive lane, as translation
does; alias, literal and inline cases also assert the translated result
and run on Metal; rejections are pinned to the SOP2 word's offset; GPU
status is recorded as local evidence with acceptance pending.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
xenora shaders inspect passed each identified instruction to decode() on
its own. decode() checks that every branch target lands on an instruction
in the stream it was given, and a lone branch has no other instruction to
land on, so every supported s_branch and s_cbranch_* was reported as
"unsupported operands" (3 of 15 rows in bitwise-branch.bin).
Add decode_at(), which decodes one instruction at its real stream offset
without the stream-wide target check, and DecodedInstruction::branch_target().
inspect now identifies the whole stream first and checks each branch
target against those boundaries, reporting a bad target separately.
decode() is rebuilt on decode_at() with unchanged behaviour.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
The decoder knew 25 hand-matched forms, so any other instruction stopped
decoding with no record of what it was or how long it was. A two-stage
generator now reduces AMD's public RDNA 2 XML to all 1,460 base forms,
with a committed snapshot so CI can check the generated table offline.
identify() finds any form's exact length, including literal, SDWA, DPP
and NSA words, and the shaders CLI reports discovered against executable
forms so metadata coverage is never read as GPU support.
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
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>
Compare high vector-register encodings against LLVM and retain the upstream objc2 MIT text. Record the attribution and SDK redistribution questions that still block license sign-off.
Signed-off-by: Ranveer Soni <git@ranveersoni.me>
Add gfx1030 decoding, semantic validation, Metal shader generation, and an independent CPU interpreter for three reproducible compute fixtures. Include native Metal tests, LLVM fixture verification, and the existing CI and Phase 01 handoff.
Verified formatting, all-features Clippy and tests, LLVM decoding, native ARM64 linkage, and all three demo fixtures with Metal API and shader validation enabled.
Signed-off-by: Ranveer Soni <git@ranveersoni.me>