mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
isa, decoder, shader, ref: the four VOP2 VCC-reading integer forms through the semantic registry (#215)
v_cndmask_b32, v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 (VOP2 e32, Wave32) read VCC_LO as the per-lane select or carry-in; the co_ci forms write the carry-out to VCC_LO. An independent guide-derived oracle, tests/validation/tests/vop2_vcc.rs, checks both CPU interpreters; its native Metal half is ignored until the lead runs it. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
1 parent
fb0544652b
commit
8e9ec8b9d1
29 files changed
+1156
-128
No files matched your search
@@ -16,6 +16,7 @@ remains unsupported.
|
||||
- Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits.
|
||||
|
||||
### Added
|
||||
- Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived CPU oracle. Native Metal verification and independent acceptance are pending. Part of #215.
|
||||
- Added delay-loaded imports to the static PE probe (#244). `xenora probe --mode static` now reads the PE32+ delay-load directory and lists each delay-loaded import in `imports.csv` with its DLL, symbol or ordinal, and delay import address table slot. A new `import_table` column, inserted after `iat_rva`, marks every row `ordinary` or `delayed`; `import_kind` stays the last column. The existing totals and `missing_imports.csv` still cover ordinary imports only, and the JSON report adds `delayed_imports`, `delayed_imported_dlls_count` and `delay_import_error`. The table is bounded by the directory's declared size, which must hold the empty descriptor that ends it, and each descriptor's DLL name, import address table and import name table must be present and start in section data. A table that breaks these rules, is truncated, sets a reserved attribute bit or uses the earlier virtual-address descriptor form is reported with the entries read before the problem. `xenora imports sync` leaves delayed rows out of its backlog. Inspection stays static: nothing is bound or executed. Covered by an original fixture (`fixtures/pe/delay-imports.exe`, generated by `fixtures/pe/delay-imports.py`) whose imports were cross-checked locally with `llvm-readobj --coff-imports` from LLVM 23.1.6; awaiting independent review.
|
||||
- Added the sixteen gfx1030 SOPK integer forms through the semantic registry: `s_movk_i32`, `s_cmovk_i32`, `s_cmpk_{eq,lg,gt,ge,lt,le}_{i32,u32}`, `s_addk_i32` and `s_mulk_i32` (AMD guide sections 12.2 and 13.1.2), with SDST s0-s105 only and SIMM16 sign-extended (zero-extended for the unsigned compares). The registry gained the operand rules `sopk_sgpr` and `sopk_compare` and the operations `mov` and `cmov`; the decoder and the scalar translation fold them like SOP2 and SOPC. An independent guide-derived oracle (`tests/validation/tests/sopk.rs`, 4,184 cases and 398 rejections on both CPU interpreters and native Metal), an LLVM-assembled fixture `scalar-immediate.s` with IR and MSL goldens, and the LLVM three-way decoder check cover them (part of #215).
|
||||
- Added an independent guide-derived oracle for the Wave32 16-bit (`v_cmp_{lt..ge}_{i16,u16}_e32`) and 64-bit (`v_cmp_{f..t}_{i64,u64}_e32`) integer compares in the reference and the second interpreter (6,212 lane cases, 1,208 rejections; contract in `docs/shaders/vector-compare.md` section 2a). The decoder and translator still reject these forms, and native Metal agreement is not yet shown. Part of #215.
|
||||
|
||||
@@ -14,8 +14,8 @@ use xenora_isa::{
|
||||
};
|
||||
|
||||
use xenora_isa::meta::EncodingFamily;
|
||||
pub use xenora_isa::semantics::VectorBinary;
|
||||
use xenora_isa::semantics::{FORM_IDS, OperandRule};
|
||||
pub use xenora_isa::semantics::{VectorBinary, VectorLowering, VectorVcc};
|
||||
|
||||
/// Metadata forms that [`decode`] turns into an [`Instruction`] for at least one
|
||||
/// operand combination: the hand-written forms below followed by every form of
|
||||
@@ -417,7 +417,10 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
let (_, src0, _) = vop2_registers(first, op.assembly_name())?;
|
||||
(VectorSource::Register(src0), 4)
|
||||
}
|
||||
_ => vector_src0(first, bytes, op.assembly_name())?,
|
||||
OperandRule::Vop2Vgpr | OperandRule::Vop2Vcc => {
|
||||
vector_src0(first, bytes, op.assembly_name())?
|
||||
}
|
||||
_ => unreachable!("non-VOP2 operand rule for VOP2 instruction"),
|
||||
};
|
||||
return Ok((
|
||||
Instruction::VectorAlu {
|
||||
|
||||
@@ -517,6 +517,10 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
src1,
|
||||
} => Op::VectorInteger(
|
||||
match op {
|
||||
VectorAluOp::CndmaskB32 => VectorInteger::Select,
|
||||
VectorAluOp::AddCoCiU32 => VectorInteger::AddCarry,
|
||||
VectorAluOp::SubCoCiU32 => VectorInteger::SubtractBorrow { reversed: false },
|
||||
VectorAluOp::SubrevCoCiU32 => VectorInteger::SubtractBorrow { reversed: true },
|
||||
VectorAluOp::MulI32I24 => VectorInteger::Multiply24 { signed: true },
|
||||
VectorAluOp::MulHiI32I24 => VectorInteger::MultiplyHigh24 { signed: true },
|
||||
VectorAluOp::MulU32U24 => VectorInteger::Multiply24 { signed: false },
|
||||
@@ -566,6 +570,7 @@ fn compares_fixture_instructions_against_llvm() {
|
||||
include_bytes!("../../../fixtures/rdna2/scalar-arith.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/scalar-immediate.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-integer.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-vcc.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-compare.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin"),
|
||||
high_registers,
|
||||
@@ -573,7 +578,7 @@ fn compares_fixture_instructions_against_llvm() {
|
||||
] {
|
||||
count += compare_against_llvm(fixture, &mut forms);
|
||||
}
|
||||
assert_eq!(forms.len(), 120, "forms compared: {forms:?}");
|
||||
assert_eq!(forms.len(), 124, "forms compared: {forms:?}");
|
||||
eprintln!(
|
||||
"{count} three-way instruction comparisons across {} forms",
|
||||
forms.len()
|
||||
@@ -870,7 +875,7 @@ fn normalize_llvm_assembly(assembly: &str, next_offset: usize) -> String {
|
||||
let target = next_offset + displacement * 4;
|
||||
format!("{mnemonic} -> 0x{target:04x}")
|
||||
}
|
||||
// VOPC and the registry VOP2 forms print SRC0 (the second operand) as bits.
|
||||
// VOPC and registry VOP2 forms print SRC0 as bits.
|
||||
mnemonic
|
||||
if mnemonic.starts_with("v_cmp_")
|
||||
|| VectorAluOp::ALL
|
||||
@@ -878,10 +883,11 @@ fn normalize_llvm_assembly(assembly: &str, next_offset: usize) -> String {
|
||||
.any(|op| op.assembly_name() == mnemonic) =>
|
||||
{
|
||||
let mut parts: Vec<String> = operands.split(", ").map(str::to_owned).collect();
|
||||
parts[1] = match literal_bits(&parts[1]) {
|
||||
let src = if parts.len() == 5 { 2 } else { 1 };
|
||||
parts[src] = match literal_bits(&parts[src]) {
|
||||
Some(bits) => format!("0x{bits:x}"),
|
||||
None => parts[1].parse::<i32>().map_or_else(
|
||||
|_| parts[1].clone(),
|
||||
None => parts[src].parse::<i32>().map_or_else(
|
||||
|_| parts[src].clone(),
|
||||
|value| format!("0x{:x}", value as u32),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -124,7 +124,7 @@ SHIFT_AMOUNTS = {1, 2, 3, 4}
|
||||
SOURCE_ORDER_KEY = "source_order"
|
||||
SOURCE_ORDERS = {"reversed"}
|
||||
SIGNEDNESS = {"unsigned": "Unsigned", "signed": "Signed", "bitwise": "Bitwise"}
|
||||
CARRY_IN = {"none": "None", "scc": "Scc"}
|
||||
CARRY_IN = {"none": "None", "scc": "Scc", "vcc": "Vcc"}
|
||||
SCC = {
|
||||
"unchanged": "Unchanged",
|
||||
"carry_out": "CarryOut",
|
||||
@@ -144,6 +144,11 @@ WAVE = {"any": "Any", "wave32": "Wave32"}
|
||||
# compute fixture ABI (docs/shaders/vector-compare.md section 2). Every other
|
||||
# kind must be "any".
|
||||
WAVE_BY_KIND = {"vector_compare": "wave32"}
|
||||
VCC_VECTOR_PRIMITIVES = {
|
||||
("cselect", "bitwise"): "Select",
|
||||
("add", "unsigned"): "AddCarry",
|
||||
("sub", "unsigned"): "SubtractBorrow",
|
||||
}
|
||||
EVIDENCE = {
|
||||
"reference": "Reference",
|
||||
"independent": "Independent",
|
||||
@@ -410,6 +415,24 @@ OPERAND_RULES = {
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
"vop2_vcc": {
|
||||
"rust": "Vop2Vcc",
|
||||
"enum": "VectorAluOp",
|
||||
"shape": {
|
||||
"family": "VOP2",
|
||||
"dst": {"field": "VDST", "class": "vgpr", "min": 0, "max": 255},
|
||||
"src": [
|
||||
{"field": "SRC0", "class": "vector_source"},
|
||||
{"field": "VSRC1", "class": "vgpr"},
|
||||
],
|
||||
"max_literals": 1,
|
||||
},
|
||||
"unsupported": {
|
||||
"src_vcc_hi", "src_exec", "src_m0", "src_ttmp", "src_null", "src_float_inline",
|
||||
"src_special",
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
"vop2_vgpr2": {
|
||||
"rust": "Vop2Vgpr2",
|
||||
"enum": "VectorAluOp",
|
||||
@@ -599,24 +622,27 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
operands = {}
|
||||
scc_in = scc_out = False
|
||||
implicit = set()
|
||||
vcc_writes = []
|
||||
vcc_operands = []
|
||||
for field, data_format, kind, size, is_input, is_output, _implicit, _encoded in variant["operands"]:
|
||||
if kind == "OPR_SSRC_SPECIAL_SCC":
|
||||
scc_in |= is_input
|
||||
scc_out |= is_output
|
||||
elif field:
|
||||
operands[field] = (data_format, size, is_input, is_output)
|
||||
elif kind == "OPR_VCC":
|
||||
vcc_operands.append((is_input, is_output))
|
||||
else:
|
||||
implicit.add(kind)
|
||||
if kind == "OPR_VCC":
|
||||
vcc_writes.append((is_input, is_output))
|
||||
# The vocabulary states SCC effects and a lane-mask VCC write; any other
|
||||
# implicit XML operand (such as an EXEC write) is undeclared.
|
||||
if form["carry_in"] == "vcc":
|
||||
if vcc_operands.count((True, False)) != 1:
|
||||
errors.append(f"{label}: carry_in vcc requires one implicit XML VCC input")
|
||||
if (True, False) in vcc_operands:
|
||||
vcc_operands.remove((True, False))
|
||||
if form["vcc"] == "lane_mask":
|
||||
# Exactly one fieldless VCC operand, written and not read.
|
||||
if vcc_writes != [(False, True)]:
|
||||
if vcc_operands != [(False, True)]:
|
||||
errors.append(f"{label}: vcc lane_mask but the XML has no implicit VCC output")
|
||||
implicit.discard("OPR_VCC")
|
||||
elif vcc_operands:
|
||||
implicit.add("OPR_VCC")
|
||||
if implicit:
|
||||
errors.append(f"{label}: XML implicit operands {sorted(implicit)} are not declared")
|
||||
if scc_in != (form["carry_in"] == "scc"):
|
||||
@@ -730,10 +756,13 @@ def validate(registry, snapshot):
|
||||
errors.append(f"{label}: variant {form['variant']!r} is reserved")
|
||||
if type(form["opcode"]) is not int or not 0 <= form["opcode"] <= U16_MAX:
|
||||
errors.append(f"{label}: invalid opcode")
|
||||
wave = WAVE_BY_KIND.get(_rule_kind(form), "any")
|
||||
reads_vcc = form["operands"] == "vop2_vcc"
|
||||
wave = "wave32" if reads_vcc else WAVE_BY_KIND.get(_rule_kind(form), "any")
|
||||
if (form["carry_in"] == "vcc") != reads_vcc:
|
||||
errors.append(f"{label}: implicit VCC input requires the vop2_vcc rule")
|
||||
if form["wave"] in WAVE and form["wave"] != wave:
|
||||
errors.append(f"{label}: wave {form['wave']} is not enforced for this rule (requires {wave})")
|
||||
lane_mask = _rule_kind(form) == "vector_compare"
|
||||
lane_mask = _rule_kind(form) == "vector_compare" or (reads_vcc and form["operation"] != "cselect")
|
||||
if form["vcc"] in MASK and (form["vcc"] == "lane_mask") != lane_mask:
|
||||
errors.append(
|
||||
f"{label}: vcc {form['vcc']} contradicts rule {form['operands']} "
|
||||
@@ -781,7 +810,7 @@ def validate(registry, snapshot):
|
||||
errors.append(f"{label}: unknown {SOURCE_ORDER_KEY} {order!r}")
|
||||
elif _rule_kind(form) != "vector":
|
||||
errors.append(f"{label}: {SOURCE_ORDER_KEY} on a non-vector form")
|
||||
if form["operation"] in SCC_READERS and form["carry_in"] != "scc":
|
||||
if not reads_vcc and form["operation"] in SCC_READERS and form["carry_in"] != "scc":
|
||||
errors.append(f"{label}: operation {form['operation']} reads SCC (requires carry_in scc)")
|
||||
if form["operation"] == "sext":
|
||||
bits = form.get(SOURCE_BITS_KEY)
|
||||
@@ -824,7 +853,8 @@ def validate(registry, snapshot):
|
||||
elif _rule_kind(form) == "vector":
|
||||
if RELATION_KEY in form:
|
||||
errors.append(f"{label}: {RELATION_KEY} on a non-compare operation")
|
||||
lowering = VECTOR_PRIMITIVES.get((form["operation"], form["signedness"]))
|
||||
key = (form["operation"], form["signedness"])
|
||||
lowering = (VCC_VECTOR_PRIMITIVES if reads_vcc else VECTOR_PRIMITIVES).get(key)
|
||||
primitive = None if lowering is None else ("unchanged", lowering, False)
|
||||
else:
|
||||
if RELATION_KEY in form:
|
||||
@@ -1042,7 +1072,7 @@ def render(registry, snapshot):
|
||||
"use crate::primitive;",
|
||||
"use crate::semantics::{",
|
||||
" CarryIn, Document, Evidence, FormSemantics, MaskEffect, Operation, OperandRule, SccEffect,",
|
||||
" Signedness, SpecRef, VectorBinary, Wave,",
|
||||
" Signedness, SpecRef, VectorBinary, VectorLowering, VectorVcc, Wave,",
|
||||
"};",
|
||||
"use crate::CompareRelation;",
|
||||
"",
|
||||
@@ -1232,7 +1262,7 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
f"pub enum {enum} {{",
|
||||
]
|
||||
for form in forms:
|
||||
carry = " plus SCC" if form["carry_in"] == "scc" else ""
|
||||
carry = {"scc": " plus SCC", "vcc": " with VCC input"}.get(form["carry_in"], "")
|
||||
what = f"compare {form[RELATION_KEY]}" if RELATION_KEY in form else form["operation"]
|
||||
effect = f"VCC = {form['vcc']}" if form["vcc"] != "unchanged" else f"SCC = {form['scc']}"
|
||||
out += [
|
||||
@@ -1431,14 +1461,16 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
" }",
|
||||
"",
|
||||
" /// The per-lane operation its MSL lowering uses.",
|
||||
" pub const fn lowering(self) -> VectorBinary {",
|
||||
" pub const fn lowering(self) -> VectorLowering {",
|
||||
" match self {",
|
||||
]
|
||||
out += [
|
||||
f" Self::{form['variant']} => "
|
||||
f"VectorBinary::{VECTOR_PRIMITIVES[(form['operation'], form['signedness'])]},"
|
||||
for form in forms
|
||||
]
|
||||
for form in forms:
|
||||
key = (form["operation"], form["signedness"])
|
||||
if form["operands"] == "vop2_vcc":
|
||||
lowering = f"Vcc(VectorVcc::{VCC_VECTOR_PRIMITIVES[key]})"
|
||||
else:
|
||||
lowering = f"Binary(VectorBinary::{VECTOR_PRIMITIVES[key]})"
|
||||
out.append(f" Self::{form['variant']} => VectorLowering::{lowering},")
|
||||
out += [
|
||||
" }",
|
||||
" }",
|
||||
|
||||
@@ -43,10 +43,10 @@ file = "amdgpu_isa_rdna2.xml"
|
||||
# variant Rust enum variant of the typed op
|
||||
# operation primitive (closed vocabulary in generate_semantics.py OPERATIONS)
|
||||
# signedness unsigned | signed | bitwise (bitwise iff a logical operation)
|
||||
# carry_in none | scc (scc for unsigned add/sub carry and the cselect condition)
|
||||
# carry_in none | scc | vcc (implicit scalar or per-lane condition or carry)
|
||||
# width operand and result width in bits
|
||||
# scc unchanged | carry_out | borrow | signed_overflow | nonzero | relation | selected_src0
|
||||
# vcc, exec unchanged (stated, not implied) | lane_mask (vcc of a Wave32 VOPC compare)
|
||||
# vcc, exec unchanged (stated, not implied) | lane_mask (Wave32 VOPC compare or VOP2 carry output)
|
||||
# wave any | wave32 (wave32 exactly for the VOPC lane-mask compares)
|
||||
# operands a key of [operand_rules]
|
||||
# spec references; at least one guide section with a page
|
||||
|
||||
@@ -348,3 +348,85 @@ wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[operand_rules.vop2_vcc]
|
||||
family = "VOP2"
|
||||
dst = { field = "VDST", class = "vgpr", min = 0, max = 255 }
|
||||
src = [
|
||||
{ field = "SRC0", class = "vector_source" },
|
||||
{ field = "VSRC1", class = "vgpr" },
|
||||
]
|
||||
# vector_source = VGPR, normal SGPR s0-s105, vcc_lo, inline integer -16..64, or a literal word.
|
||||
max_literals = 1
|
||||
unsupported = [
|
||||
"src_vcc_hi", "src_exec", "src_m0", "src_ttmp", "src_null", "src_float_inline", "src_special",
|
||||
]
|
||||
|
||||
[[form]]
|
||||
name = "V_CNDMASK_B32"
|
||||
family = "VOP2"
|
||||
opcode = 1
|
||||
variant = "CndmaskB32"
|
||||
operation = "cselect"
|
||||
signedness = "bitwise"
|
||||
carry_in = "vcc"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "wave32"
|
||||
operands = "vop2_vcc"
|
||||
spec = [{ document = "guide", section = "12.7", page = 131 }, { document = "guide", section = "3.9", page = 20 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_ADD_CO_CI_U32"
|
||||
family = "VOP2"
|
||||
opcode = 40
|
||||
variant = "AddCoCiU32"
|
||||
operation = "add"
|
||||
signedness = "unsigned"
|
||||
carry_in = "vcc"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "lane_mask"
|
||||
exec = "unchanged"
|
||||
wave = "wave32"
|
||||
operands = "vop2_vcc"
|
||||
spec = [{ document = "guide", section = "12.7", page = 134 }, { document = "guide", section = "3.9", page = 20 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_SUB_CO_CI_U32"
|
||||
family = "VOP2"
|
||||
opcode = 41
|
||||
variant = "SubCoCiU32"
|
||||
operation = "sub"
|
||||
signedness = "unsigned"
|
||||
carry_in = "vcc"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "lane_mask"
|
||||
exec = "unchanged"
|
||||
wave = "wave32"
|
||||
operands = "vop2_vcc"
|
||||
spec = [{ document = "guide", section = "12.7", page = 134 }, { document = "guide", section = "3.9", page = 20 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_SUBREV_CO_CI_U32"
|
||||
family = "VOP2"
|
||||
opcode = 42
|
||||
variant = "SubrevCoCiU32"
|
||||
operation = "sub"
|
||||
signedness = "unsigned"
|
||||
carry_in = "vcc"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "lane_mask"
|
||||
exec = "unchanged"
|
||||
wave = "wave32"
|
||||
operands = "vop2_vcc"
|
||||
source_order = "reversed"
|
||||
spec = [{ document = "guide", section = "12.7", page = 134 }, { document = "guide", section = "3.9", page = 20 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
+25
-2
@@ -23,6 +23,18 @@ pub use semantics_gen::{
|
||||
VectorAluOp, VectorAluVop3Op, VectorCompareOp,
|
||||
};
|
||||
|
||||
impl VectorAluOp {
|
||||
/// Whether this encoding takes a per-lane VCC_LO bit.
|
||||
pub fn reads_vcc(self) -> bool {
|
||||
self.semantics().carry_in == semantics::CarryIn::Vcc
|
||||
}
|
||||
|
||||
/// Whether this encoding replaces the Wave32 VCC_LO mask.
|
||||
pub fn writes_vcc(self) -> bool {
|
||||
self.semantics().vcc == semantics::MaskEffect::LaneMask
|
||||
}
|
||||
}
|
||||
|
||||
/// SGPR index of `vcc_lo`, the Wave32 vector condition code.
|
||||
pub const VCC_LO: u8 = 106;
|
||||
|
||||
@@ -355,9 +367,20 @@ impl fmt::Display for Instruction {
|
||||
write!(formatter, " vcc_lo, {src0}, v{src1}")
|
||||
}
|
||||
Self::VectorAlu {
|
||||
dst, src0, src1, ..
|
||||
op,
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
} => {
|
||||
write!(formatter, " v{dst}, {src0}, v{src1}")
|
||||
write!(formatter, " v{dst}, ")?;
|
||||
if op.writes_vcc() {
|
||||
write!(formatter, "vcc_lo, ")?;
|
||||
}
|
||||
write!(formatter, "{src0}, v{src1}")?;
|
||||
if op.reads_vcc() {
|
||||
write!(formatter, ", vcc_lo")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Branch { target }
|
||||
| Self::BranchSccZero { target }
|
||||
|
||||
@@ -148,13 +148,35 @@ pub enum Signedness {
|
||||
Bitwise,
|
||||
}
|
||||
|
||||
/// Whether the operation reads SCC.
|
||||
/// Per-lane VOP2 operation selected by the semantic registry.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorLowering {
|
||||
/// Two explicit operands, with no implicit lane input.
|
||||
Binary(VectorBinary),
|
||||
/// Two explicit operands and the lane's VCC bit.
|
||||
Vcc(VectorVcc),
|
||||
}
|
||||
|
||||
/// VOP2 primitives with an implicit per-lane VCC input.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorVcc {
|
||||
/// Choose S1 when the VCC bit is set, otherwise S0.
|
||||
Select,
|
||||
/// Unsigned addition with carry-in and carry-out.
|
||||
AddCarry,
|
||||
/// Unsigned subtraction with borrow-in and borrow-out.
|
||||
SubtractBorrow,
|
||||
}
|
||||
|
||||
/// Implicit condition or carry input.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum CarryIn {
|
||||
/// SCC is not read.
|
||||
/// No implicit condition or carry input.
|
||||
None,
|
||||
/// SCC as carry-in (add), borrow-in (sub) or the select condition (select).
|
||||
Scc,
|
||||
/// Per-lane Wave32 VCC_LO bit.
|
||||
Vcc,
|
||||
}
|
||||
|
||||
/// What a form writes to SCC.
|
||||
@@ -230,6 +252,8 @@ pub enum OperandRule {
|
||||
/// integer -16..64 or a literal word; VSRC1 is a VGPR. Everything else is
|
||||
/// rejected as unsupported.
|
||||
Vop2Vgpr,
|
||||
/// VOP2 general SRC0 and VGPR VSRC1 with an implicit VCC_LO input.
|
||||
Vop2Vcc,
|
||||
/// VOP2 vector, VGPR sources only: VDST is v0-v255; SRC0 and VSRC1 are VGPRs.
|
||||
/// Everything else (SGPR, inline, literal SRC0) is rejected as unsupported.
|
||||
Vop2Vgpr2,
|
||||
|
||||
+169
-45
@@ -5,7 +5,7 @@ use crate::meta::EncodingFamily;
|
||||
use crate::primitive;
|
||||
use crate::semantics::{
|
||||
CarryIn, Document, Evidence, FormSemantics, MaskEffect, Operation, OperandRule, SccEffect,
|
||||
Signedness, SpecRef, VectorBinary, Wave,
|
||||
Signedness, SpecRef, VectorBinary, VectorLowering, VectorVcc, Wave,
|
||||
};
|
||||
use crate::CompareRelation;
|
||||
|
||||
@@ -1503,7 +1503,7 @@ impl ScalarImmediateOp {
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP2 operations declared in the semantic registry (operand rules `vop2_vgpr`, `vop2_vgpr2`).
|
||||
/// VOP2 operations declared in the semantic registry (operand rules `vop2_vcc`, `vop2_vgpr`, `vop2_vgpr2`).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorAluOp {
|
||||
/// `v_mul_i32_i24` (VOP2 opcode 9): signed mul24, SCC = unchanged.
|
||||
@@ -1542,12 +1542,20 @@ pub enum VectorAluOp {
|
||||
OrB32,
|
||||
/// `v_xor_b32` (VOP2 opcode 29): bitwise xor, SCC = unchanged.
|
||||
XorB32,
|
||||
/// `v_cndmask_b32` (VOP2 opcode 1): bitwise cselect with VCC input, SCC = unchanged.
|
||||
CndmaskB32,
|
||||
/// `v_add_co_ci_u32` (VOP2 opcode 40): unsigned add with VCC input, VCC = lane_mask.
|
||||
AddCoCiU32,
|
||||
/// `v_sub_co_ci_u32` (VOP2 opcode 41): unsigned sub with VCC input, VCC = lane_mask.
|
||||
SubCoCiU32,
|
||||
/// `v_subrev_co_ci_u32` (VOP2 opcode 42): unsigned sub with VCC input, VCC = lane_mask.
|
||||
SubrevCoCiU32,
|
||||
}
|
||||
|
||||
/// VectorAluOp by VOP2 OP field value; `None` for undeclared opcodes.
|
||||
const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
None,
|
||||
None,
|
||||
Some(VectorAluOp::CndmaskB32),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@@ -1586,9 +1594,9 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
Some(VectorAluOp::AddNcU32),
|
||||
Some(VectorAluOp::SubNcU32),
|
||||
Some(VectorAluOp::SubrevNcU32),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(VectorAluOp::AddCoCiU32),
|
||||
Some(VectorAluOp::SubCoCiU32),
|
||||
Some(VectorAluOp::SubrevCoCiU32),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@@ -1614,7 +1622,7 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
|
||||
impl VectorAluOp {
|
||||
/// Every operation, in registry order.
|
||||
pub const ALL: [Self; 18] = [
|
||||
pub const ALL: [Self; 22] = [
|
||||
Self::MulI32I24,
|
||||
Self::MulHiI32I24,
|
||||
Self::MulU32U24,
|
||||
@@ -1633,6 +1641,10 @@ impl VectorAluOp {
|
||||
Self::AndB32,
|
||||
Self::OrB32,
|
||||
Self::XorB32,
|
||||
Self::CndmaskB32,
|
||||
Self::AddCoCiU32,
|
||||
Self::SubCoCiU32,
|
||||
Self::SubrevCoCiU32,
|
||||
];
|
||||
|
||||
/// Selects the operation from a first instruction word: the VOP2 encoding
|
||||
@@ -1665,6 +1677,10 @@ impl VectorAluOp {
|
||||
Self::AndB32 => "v_and_b32",
|
||||
Self::OrB32 => "v_or_b32",
|
||||
Self::XorB32 => "v_xor_b32",
|
||||
Self::CndmaskB32 => "v_cndmask_b32",
|
||||
Self::AddCoCiU32 => "v_add_co_ci_u32",
|
||||
Self::SubCoCiU32 => "v_sub_co_ci_u32",
|
||||
Self::SubrevCoCiU32 => "v_subrev_co_ci_u32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1689,6 +1705,10 @@ impl VectorAluOp {
|
||||
Self::AndB32 => 88,
|
||||
Self::OrB32 => 89,
|
||||
Self::XorB32 => 90,
|
||||
Self::CndmaskB32 => 91,
|
||||
Self::AddCoCiU32 => 92,
|
||||
Self::SubCoCiU32 => 93,
|
||||
Self::SubrevCoCiU32 => 94,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1713,30 +1733,38 @@ impl VectorAluOp {
|
||||
Self::AndB32 => "v_and_b32_e32",
|
||||
Self::OrB32 => "v_or_b32_e32",
|
||||
Self::XorB32 => "v_xor_b32_e32",
|
||||
Self::CndmaskB32 => "v_cndmask_b32_e32",
|
||||
Self::AddCoCiU32 => "v_add_co_ci_u32_e32",
|
||||
Self::SubCoCiU32 => "v_sub_co_ci_u32_e32",
|
||||
Self::SubrevCoCiU32 => "v_subrev_co_ci_u32_e32",
|
||||
}
|
||||
}
|
||||
|
||||
/// The per-lane operation its MSL lowering uses.
|
||||
pub const fn lowering(self) -> VectorBinary {
|
||||
pub const fn lowering(self) -> VectorLowering {
|
||||
match self {
|
||||
Self::MulI32I24 => VectorBinary::Mul24Signed,
|
||||
Self::MulHiI32I24 => VectorBinary::MulHi24Signed,
|
||||
Self::MulU32U24 => VectorBinary::Mul24Unsigned,
|
||||
Self::MulHiU32U24 => VectorBinary::MulHi24Unsigned,
|
||||
Self::MinI32 => VectorBinary::MinSigned,
|
||||
Self::MaxI32 => VectorBinary::MaxSigned,
|
||||
Self::MinU32 => VectorBinary::MinUnsigned,
|
||||
Self::MaxU32 => VectorBinary::MaxUnsigned,
|
||||
Self::XnorB32 => VectorBinary::Xnor,
|
||||
Self::AddNcU32 => VectorBinary::Add,
|
||||
Self::SubNcU32 => VectorBinary::Sub,
|
||||
Self::SubrevNcU32 => VectorBinary::Sub,
|
||||
Self::LshrrevB32 => VectorBinary::ShiftRight,
|
||||
Self::AshrrevI32 => VectorBinary::ArithmeticShiftRight,
|
||||
Self::LshlrevB32 => VectorBinary::ShiftLeft,
|
||||
Self::AndB32 => VectorBinary::And,
|
||||
Self::OrB32 => VectorBinary::Or,
|
||||
Self::XorB32 => VectorBinary::Xor,
|
||||
Self::MulI32I24 => VectorLowering::Binary(VectorBinary::Mul24Signed),
|
||||
Self::MulHiI32I24 => VectorLowering::Binary(VectorBinary::MulHi24Signed),
|
||||
Self::MulU32U24 => VectorLowering::Binary(VectorBinary::Mul24Unsigned),
|
||||
Self::MulHiU32U24 => VectorLowering::Binary(VectorBinary::MulHi24Unsigned),
|
||||
Self::MinI32 => VectorLowering::Binary(VectorBinary::MinSigned),
|
||||
Self::MaxI32 => VectorLowering::Binary(VectorBinary::MaxSigned),
|
||||
Self::MinU32 => VectorLowering::Binary(VectorBinary::MinUnsigned),
|
||||
Self::MaxU32 => VectorLowering::Binary(VectorBinary::MaxUnsigned),
|
||||
Self::XnorB32 => VectorLowering::Binary(VectorBinary::Xnor),
|
||||
Self::AddNcU32 => VectorLowering::Binary(VectorBinary::Add),
|
||||
Self::SubNcU32 => VectorLowering::Binary(VectorBinary::Sub),
|
||||
Self::SubrevNcU32 => VectorLowering::Binary(VectorBinary::Sub),
|
||||
Self::LshrrevB32 => VectorLowering::Binary(VectorBinary::ShiftRight),
|
||||
Self::AshrrevI32 => VectorLowering::Binary(VectorBinary::ArithmeticShiftRight),
|
||||
Self::LshlrevB32 => VectorLowering::Binary(VectorBinary::ShiftLeft),
|
||||
Self::AndB32 => VectorLowering::Binary(VectorBinary::And),
|
||||
Self::OrB32 => VectorLowering::Binary(VectorBinary::Or),
|
||||
Self::XorB32 => VectorLowering::Binary(VectorBinary::Xor),
|
||||
Self::CndmaskB32 => VectorLowering::Vcc(VectorVcc::Select),
|
||||
Self::AddCoCiU32 => VectorLowering::Vcc(VectorVcc::AddCarry),
|
||||
Self::SubCoCiU32 => VectorLowering::Vcc(VectorVcc::SubtractBorrow),
|
||||
Self::SubrevCoCiU32 => VectorLowering::Vcc(VectorVcc::SubtractBorrow),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1761,6 +1789,10 @@ impl VectorAluOp {
|
||||
Self::AndB32 => false,
|
||||
Self::OrB32 => false,
|
||||
Self::XorB32 => false,
|
||||
Self::CndmaskB32 => false,
|
||||
Self::AddCoCiU32 => false,
|
||||
Self::SubCoCiU32 => false,
|
||||
Self::SubrevCoCiU32 => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1785,6 +1817,10 @@ impl VectorAluOp {
|
||||
Self::AndB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::OrB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::XorB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::CndmaskB32 => OperandRule::Vop2Vcc,
|
||||
Self::AddCoCiU32 => OperandRule::Vop2Vcc,
|
||||
Self::SubCoCiU32 => OperandRule::Vop2Vcc,
|
||||
Self::SubrevCoCiU32 => OperandRule::Vop2Vcc,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2141,22 +2177,22 @@ impl VectorCompareOp {
|
||||
/// The validated registry row.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::CmpLtI32 => 91,
|
||||
Self::CmpEqI32 => 92,
|
||||
Self::CmpLeI32 => 93,
|
||||
Self::CmpGtI32 => 94,
|
||||
Self::CmpNeI32 => 95,
|
||||
Self::CmpGeI32 => 96,
|
||||
Self::CmpLtU32 => 97,
|
||||
Self::CmpEqU32 => 98,
|
||||
Self::CmpLeU32 => 99,
|
||||
Self::CmpGtU32 => 100,
|
||||
Self::CmpNeU32 => 101,
|
||||
Self::CmpGeU32 => 102,
|
||||
Self::CmpFI32 => 103,
|
||||
Self::CmpTI32 => 104,
|
||||
Self::CmpFU32 => 105,
|
||||
Self::CmpTU32 => 106,
|
||||
Self::CmpLtI32 => 95,
|
||||
Self::CmpEqI32 => 96,
|
||||
Self::CmpLeI32 => 97,
|
||||
Self::CmpGtI32 => 98,
|
||||
Self::CmpNeI32 => 99,
|
||||
Self::CmpGeI32 => 100,
|
||||
Self::CmpLtU32 => 101,
|
||||
Self::CmpEqU32 => 102,
|
||||
Self::CmpLeU32 => 103,
|
||||
Self::CmpGtU32 => 104,
|
||||
Self::CmpNeU32 => 105,
|
||||
Self::CmpGeU32 => 106,
|
||||
Self::CmpFI32 => 107,
|
||||
Self::CmpTI32 => 108,
|
||||
Self::CmpFU32 => 109,
|
||||
Self::CmpTU32 => 110,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -2292,13 +2328,13 @@ impl VectorAluVop3Op {
|
||||
/// The validated registry row of this encoding.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::AddNcU32 => 107,
|
||||
Self::AddNcU32 => 111,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity of every registry form and encoding variant, in registry order.
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 108] = [
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 112] = [
|
||||
("S_ADD_U32", EncodingFamily::Sop2),
|
||||
("S_SUB_U32", EncodingFamily::Sop2),
|
||||
("S_ADD_I32", EncodingFamily::Sop2),
|
||||
@@ -2390,6 +2426,10 @@ pub const FORM_IDS: [(&str, EncodingFamily); 108] = [
|
||||
("V_AND_B32", EncodingFamily::Vop2),
|
||||
("V_OR_B32", EncodingFamily::Vop2),
|
||||
("V_XOR_B32", EncodingFamily::Vop2),
|
||||
("V_CNDMASK_B32", EncodingFamily::Vop2),
|
||||
("V_ADD_CO_CI_U32", EncodingFamily::Vop2),
|
||||
("V_SUB_CO_CI_U32", EncodingFamily::Vop2),
|
||||
("V_SUBREV_CO_CI_U32", EncodingFamily::Vop2),
|
||||
("V_CMP_LT_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_EQ_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_LE_I32", EncodingFamily::Vopc),
|
||||
@@ -2410,7 +2450,7 @@ pub const FORM_IDS: [(&str, EncodingFamily); 108] = [
|
||||
];
|
||||
|
||||
/// One validated row per registry form, in registry order.
|
||||
pub static FORMS: [FormSemantics; 108] = [
|
||||
pub static FORMS: [FormSemantics; 112] = [
|
||||
FormSemantics {
|
||||
name: "S_ADD_U32",
|
||||
family: EncodingFamily::Sop2,
|
||||
@@ -4322,6 +4362,90 @@ pub static FORMS: [FormSemantics; 108] = [
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CNDMASK_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 1,
|
||||
operation: Operation::Select,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::Vcc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop2Vcc,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 131 }, SpecRef { document: Document::Guide, section: "3.9", page: 20 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_ADD_CO_CI_U32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 40,
|
||||
operation: Operation::Add,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::Vcc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::LaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop2Vcc,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 134 }, SpecRef { document: Document::Guide, section: "3.9", page: 20 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_SUB_CO_CI_U32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 41,
|
||||
operation: Operation::Sub,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::Vcc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::LaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop2Vcc,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 134 }, SpecRef { document: Document::Guide, section: "3.9", page: 20 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_SUBREV_CO_CI_U32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 42,
|
||||
operation: Operation::Sub,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::Vcc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::LaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop2Vcc,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 134 }, SpecRef { document: Document::Guide, section: "3.9", page: 20 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LT_I32",
|
||||
family: EncodingFamily::Vopc,
|
||||
|
||||
+64
-2
@@ -76,7 +76,7 @@ pub enum Op {
|
||||
},
|
||||
Vector(VectorAlu, u8, u8, u8),
|
||||
/// VOP2 32-bit integer form: VDST, SRC0 (VGPR, SGPR, `vcc_lo`, inline
|
||||
/// integer or literal) and VSRC1. Writes neither VCC nor SCC.
|
||||
/// integer or literal) and VSRC1, with implicit VCC for select/carry forms.
|
||||
VectorInteger(VectorInteger, u8, CompareSource, u8),
|
||||
/// VOP1 32-bit integer or bit form: VDST and SRC0 (VGPR, SGPR, `vcc_lo`,
|
||||
/// inline integer or literal). Writes neither VCC nor SCC.
|
||||
@@ -317,6 +317,12 @@ pub enum VectorAlu {
|
||||
/// section 12.7). None has a carry-in or carry-out.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorInteger {
|
||||
/// 1: select S1 when the lane's VCC bit is set.
|
||||
Select,
|
||||
/// 40: unsigned add with carry input and output.
|
||||
AddCarry,
|
||||
/// 41 / 42: unsigned subtract with borrow input and output.
|
||||
SubtractBorrow { reversed: bool },
|
||||
/// 9 / 11: D = low 32 bits of S0[23:0] * S1[23:0], sign-extended from
|
||||
/// bit 23 when `signed`.
|
||||
Multiply24 { signed: bool },
|
||||
@@ -340,6 +346,11 @@ impl VectorInteger {
|
||||
/// Opcode bits 30-25 of the VOP2 word.
|
||||
fn from_opcode(opcode: u8) -> Option<Self> {
|
||||
Some(match opcode {
|
||||
1 => Self::Select,
|
||||
40 => Self::AddCarry,
|
||||
41 | 42 => Self::SubtractBorrow {
|
||||
reversed: opcode == 42,
|
||||
},
|
||||
9 => Self::Multiply24 { signed: true },
|
||||
10 => Self::MultiplyHigh24 { signed: true },
|
||||
11 => Self::Multiply24 { signed: false },
|
||||
@@ -356,6 +367,34 @@ impl VectorInteger {
|
||||
})
|
||||
}
|
||||
|
||||
fn reads_vcc(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Select | Self::AddCarry | Self::SubtractBorrow { .. }
|
||||
)
|
||||
}
|
||||
|
||||
fn writes_vcc(self) -> bool {
|
||||
matches!(self, Self::AddCarry | Self::SubtractBorrow { .. })
|
||||
}
|
||||
|
||||
// Guide 12.7: carry/borrow is determined from the exact mathematical result.
|
||||
fn apply_vcc(self, a: u32, b: u32, bit: u32) -> (u32, bool) {
|
||||
match self {
|
||||
Self::Select => (if bit == 0 { a } else { b }, false),
|
||||
Self::AddCarry => {
|
||||
let exact = u64::from(a) + u64::from(b) + u64::from(bit);
|
||||
(exact as u32, exact > u64::from(u32::MAX))
|
||||
}
|
||||
Self::SubtractBorrow { reversed } => {
|
||||
let (minuend, subtrahend) = if reversed { (b, a) } else { (a, b) };
|
||||
let exact = i64::from(minuend) - i64::from(subtrahend) - i64::from(bit);
|
||||
(exact as u32, exact < 0)
|
||||
}
|
||||
_ => unreachable!("VOP2 operation does not read VCC"),
|
||||
}
|
||||
}
|
||||
|
||||
/// D for S0 = `a`, S1 = `b`, from exact i64 arithmetic reduced modulo 2^32.
|
||||
fn apply(self, a: u32, b: u32) -> u32 {
|
||||
let field = |bits: u32, signed: bool| {
|
||||
@@ -393,6 +432,9 @@ impl VectorInteger {
|
||||
Self::Add => a.wrapping_add(b),
|
||||
Self::Subtract => a.wrapping_sub(b),
|
||||
Self::SubtractReverse => b.wrapping_sub(a),
|
||||
Self::Select | Self::AddCarry | Self::SubtractBorrow { .. } => {
|
||||
unreachable!("VOP2 operation requires VCC")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1087,13 +1129,33 @@ fn execute_wave(program: &[DecodedInstruction], input: &[u32]) -> Result<Vec<u32
|
||||
}
|
||||
check(src1)?;
|
||||
}
|
||||
let incoming = if exec != 0 && kind.reads_vcc() {
|
||||
read_scalar(Source::Register(VCC_LO as u8))?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let mut outgoing = 0;
|
||||
for lane in (0..lanes).filter(|&lane| executes(lane)) {
|
||||
let s0 = match src0 {
|
||||
CompareSource::Vector(register) => read(lane, register)?,
|
||||
CompareSource::Scalar(register) => read_scalar(Source::Register(register))?,
|
||||
CompareSource::Immediate(bits) => bits,
|
||||
};
|
||||
results[lane] = Some((dst, kind.apply(s0, read(lane, src1)?)));
|
||||
let s1 = read(lane, src1)?;
|
||||
let value = if kind.reads_vcc() {
|
||||
let (value, carry) = kind.apply_vcc(s0, s1, (incoming >> lane) & 1);
|
||||
outgoing |= u32::from(carry) << lane;
|
||||
value
|
||||
} else {
|
||||
kind.apply(s0, s1)
|
||||
};
|
||||
results[lane] = Some((dst, value));
|
||||
}
|
||||
// Guide 3.9: only executing lanes can contribute a carry.
|
||||
if kind.writes_vcc() {
|
||||
scalars[VCC_LO] = Some(outgoing);
|
||||
scalars[VCC_HI] = None;
|
||||
lane_derived_vcc = exec != 0;
|
||||
}
|
||||
}
|
||||
Op::VectorUnary(kind, dst, src0) => {
|
||||
|
||||
+157
-27
@@ -10,7 +10,7 @@ pub use graphics::{PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics};
|
||||
pub use xenora_decoder::Architecture;
|
||||
use xenora_decoder::{
|
||||
DecodeError, DecodedInstruction, Instruction, ScalarSource, ScalarUnaryOp, VectorAluOp,
|
||||
VectorAluVop3Op, VectorBinary, VectorCompareOp, VectorSource,
|
||||
VectorAluVop3Op, VectorBinary, VectorCompareOp, VectorLowering, VectorSource, VectorVcc,
|
||||
};
|
||||
|
||||
/// SGPR index of `vcc_lo`.
|
||||
@@ -98,6 +98,17 @@ enum Op {
|
||||
inactive: Value,
|
||||
},
|
||||
Store(Value),
|
||||
VccArithmetic {
|
||||
primitive: VectorVcc,
|
||||
left: Value,
|
||||
right: Value,
|
||||
mask: Value,
|
||||
flag: bool,
|
||||
},
|
||||
CarryMask {
|
||||
flag: Value,
|
||||
exec: u32,
|
||||
},
|
||||
ScalarBranch {
|
||||
target: usize,
|
||||
taken: bool,
|
||||
@@ -135,6 +146,10 @@ impl Op {
|
||||
Self::Store(value) => vec![value],
|
||||
Self::LaneMask { src0, src1, .. } => vec![src0, src1],
|
||||
Self::RuntimeBranch { mask, .. } => vec![mask],
|
||||
Self::VccArithmetic {
|
||||
left, right, mask, ..
|
||||
} => vec![left, right, mask],
|
||||
Self::CarryMask { flag, .. } => vec![flag],
|
||||
Self::JoinVccz {
|
||||
mask,
|
||||
fallthrough,
|
||||
@@ -178,8 +193,32 @@ impl Op {
|
||||
name(fallthrough),
|
||||
name(taken)
|
||||
),
|
||||
Self::VccArithmetic {
|
||||
primitive,
|
||||
left,
|
||||
right,
|
||||
mask,
|
||||
flag,
|
||||
} => {
|
||||
let (left, right) = (name(left), name(right));
|
||||
let bit = format!("(({} >> {lane}) & 1u)", name(mask));
|
||||
// Guide 12.7: widen the carry/borrow check before adding the input bit.
|
||||
match (primitive, flag) {
|
||||
(VectorVcc::Select, false) => format!("{bit} != 0u ? {right} : {left}"),
|
||||
(VectorVcc::AddCarry, false) => format!("{left} + {right} + {bit}"),
|
||||
(VectorVcc::AddCarry, true) => {
|
||||
format!("uint((ulong({left}) + ulong({right}) + {bit}) >> 32u)")
|
||||
}
|
||||
(VectorVcc::SubtractBorrow, false) => format!("{left} - {right} - {bit}"),
|
||||
(VectorVcc::SubtractBorrow, true) => {
|
||||
format!("uint(ulong({right}) + {bit} > ulong({left}))")
|
||||
}
|
||||
_ => unreachable!("not a VCC arithmetic operation"),
|
||||
}
|
||||
}
|
||||
Self::Store(_)
|
||||
| Self::ScalarBranch { .. }
|
||||
| Self::CarryMask { .. }
|
||||
| Self::LaneMask { .. }
|
||||
| Self::RuntimeBranch { .. } => unreachable!("not a per-thread expression"),
|
||||
}
|
||||
@@ -401,7 +440,7 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
let mut ir = String::new();
|
||||
let has_mask = operations
|
||||
.iter()
|
||||
.any(|(_, operation)| matches!(operation, Op::LaneMask { .. }));
|
||||
.any(|(_, operation)| matches!(operation, Op::LaneMask { .. } | Op::CarryMask { .. }));
|
||||
let grid = if has_mask {
|
||||
",\n uint grid [[threads_per_grid]]"
|
||||
} else {
|
||||
@@ -423,8 +462,8 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
for (index, &(offset, operation)) in operations.iter().enumerate() {
|
||||
let dest = Value(index);
|
||||
uniform.push(match operation {
|
||||
Op::Constant(_) | Op::LaneMask { .. } => true,
|
||||
Op::Load | Op::MergeLanes { .. } => false,
|
||||
Op::Constant(_) | Op::LaneMask { .. } | Op::CarryMask { .. } => true,
|
||||
Op::Load | Op::MergeLanes { .. } | Op::VccArithmetic { .. } => false,
|
||||
_ => operation.operands().iter().all(|value| uniform[value.0]),
|
||||
});
|
||||
let thread = |value: Value| value.to_string();
|
||||
@@ -474,6 +513,38 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
format!("{dest} = join.vccz {mask}, {fallthrough}, {taken}"),
|
||||
format!("uint {dest} = {};", operation.expression(&thread, "", "")),
|
||||
),
|
||||
Op::VccArithmetic {
|
||||
primitive,
|
||||
left,
|
||||
right,
|
||||
mask,
|
||||
flag,
|
||||
} => (
|
||||
format!(
|
||||
"{dest} = vcc.{primitive:?}{suffix} {left}, {right}, {mask}",
|
||||
suffix = if flag { ".flag" } else { "" }
|
||||
),
|
||||
format!(
|
||||
"uint {dest} = {};",
|
||||
operation.expression(&thread, "", "(index & 31u)")
|
||||
),
|
||||
),
|
||||
Op::CarryMask { flag, exec } => {
|
||||
let _ = writeln!(
|
||||
ir,
|
||||
"{offset:04x}: {dest} = wave.carry {flag} exec=0x{exec:08x}"
|
||||
);
|
||||
emit_lane_mask(
|
||||
&mut msl,
|
||||
&operations,
|
||||
&uniform,
|
||||
index,
|
||||
exec,
|
||||
vec![flag],
|
||||
|name| name(flag),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
Op::LaneMask {
|
||||
op,
|
||||
src0,
|
||||
@@ -485,7 +556,28 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
"{offset:04x}: {dest} = wave.mask {} {src0}, {src1} exec=0x{exec:08x}",
|
||||
op.assembly_name()
|
||||
);
|
||||
emit_lane_mask(&mut msl, &operations, &uniform, index, op, src0, src1, exec);
|
||||
let inputs = if matches!(
|
||||
op.relation(),
|
||||
xenora_decoder::CompareRelation::False | xenora_decoder::CompareRelation::True
|
||||
) {
|
||||
Vec::new()
|
||||
} else {
|
||||
vec![src0, src1]
|
||||
};
|
||||
emit_lane_mask(
|
||||
&mut msl,
|
||||
&operations,
|
||||
&uniform,
|
||||
index,
|
||||
exec,
|
||||
inputs,
|
||||
|name| {
|
||||
format!(
|
||||
"({}) ? 1u : 0u",
|
||||
compare_expression(op, &name(src0), &name(src1))
|
||||
)
|
||||
},
|
||||
);
|
||||
continue;
|
||||
}
|
||||
Op::Store(value) => (
|
||||
@@ -515,21 +607,11 @@ fn emit_lane_mask(
|
||||
operations: &[(usize, Op)],
|
||||
uniform: &[bool],
|
||||
index: usize,
|
||||
op: VectorCompareOp,
|
||||
src0: Value,
|
||||
src1: Value,
|
||||
exec: u32,
|
||||
mut pending: Vec<Value>,
|
||||
predicate: impl FnOnce(&dyn Fn(Value) -> String) -> String,
|
||||
) {
|
||||
let mut cone = vec![false; index];
|
||||
// F and T do not depend on the operands, so their lanes compute none.
|
||||
let mut pending = if matches!(
|
||||
op.relation(),
|
||||
xenora_decoder::CompareRelation::False | xenora_decoder::CompareRelation::True
|
||||
) {
|
||||
Vec::new()
|
||||
} else {
|
||||
vec![src0, src1]
|
||||
};
|
||||
while let Some(value) = pending.pop() {
|
||||
if uniform[value.0] || cone[value.0] {
|
||||
continue;
|
||||
@@ -561,8 +643,8 @@ fn emit_lane_mask(
|
||||
}
|
||||
let _ = writeln!(
|
||||
msl,
|
||||
" uint pass = ({}) ? 1u : 0u;\n {dest} |= ((0x{exec:08x}u >> lane) & pass) << lane;\n }}",
|
||||
compare_expression(op, &name(src0), &name(src1))
|
||||
" uint pass = {};\n {dest} |= ((0x{exec:08x}u >> lane) & pass) << lane;\n }}",
|
||||
predicate(&name)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -729,6 +811,13 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
// Scalar instructions and waits still execute when all lanes are inactive.
|
||||
if exec == 0 {
|
||||
match instruction.instruction {
|
||||
Instruction::VectorAlu { op, .. } if op.writes_vcc() => {
|
||||
// Guide 3.9: inactive lanes contribute zero to carry-out.
|
||||
lane_vcc = None;
|
||||
scalars[VCC_LO] = Some(0);
|
||||
scalars[VCC_HI] = None;
|
||||
continue;
|
||||
}
|
||||
Instruction::MoveB32 { .. }
|
||||
| Instruction::VectorAluVop3 { .. }
|
||||
| Instruction::VectorAddF32 { .. }
|
||||
@@ -843,10 +932,10 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
} else {
|
||||
(read(src0)?, read(src1)?)
|
||||
};
|
||||
(
|
||||
Some(dst),
|
||||
Op::Binary(Binary::Vector(op.lowering()), left, right),
|
||||
)
|
||||
let VectorLowering::Binary(binary) = op.lowering() else {
|
||||
return Err(error("VOP3 with a lane condition is unsupported"));
|
||||
};
|
||||
(Some(dst), Op::Binary(Binary::Vector(binary), left, right))
|
||||
}
|
||||
Instruction::ScalarUnary {
|
||||
op: op @ ScalarUnaryOp::MovB32,
|
||||
@@ -1064,10 +1153,51 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
} else {
|
||||
(src0, src1)
|
||||
};
|
||||
(
|
||||
Some(dst),
|
||||
Op::Binary(Binary::Vector(op.lowering()), left, right),
|
||||
)
|
||||
match op.lowering() {
|
||||
VectorLowering::Binary(binary) => {
|
||||
(Some(dst), Op::Binary(Binary::Vector(binary), left, right))
|
||||
}
|
||||
VectorLowering::Vcc(primitive) => {
|
||||
let mask = match (lane_vcc, scalars[VCC_LO]) {
|
||||
(Some(mask), _) => mask,
|
||||
(None, Some(bits)) => {
|
||||
constant(&mut operations, &mut facts, offset, bits)
|
||||
}
|
||||
(None, None) => {
|
||||
return Err(error("vector ALU reads uninitialized VCC_LO"));
|
||||
}
|
||||
};
|
||||
if op.writes_vcc() {
|
||||
let flag = Value(operations.len());
|
||||
operations.push((
|
||||
offset,
|
||||
Op::VccArithmetic {
|
||||
primitive,
|
||||
left,
|
||||
right,
|
||||
mask,
|
||||
flag: true,
|
||||
},
|
||||
));
|
||||
facts.push(KnownBits::UNKNOWN);
|
||||
lane_vcc = Some(Value(operations.len()));
|
||||
operations.push((offset, Op::CarryMask { flag, exec }));
|
||||
facts.push(KnownBits::UNKNOWN);
|
||||
scalars[VCC_LO] = None;
|
||||
scalars[VCC_HI] = None;
|
||||
}
|
||||
(
|
||||
Some(dst),
|
||||
Op::VccArithmetic {
|
||||
primitive,
|
||||
left,
|
||||
right,
|
||||
mask,
|
||||
flag: false,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Instruction::VectorAddF32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
|
||||
@@ -391,3 +391,17 @@ fn vector_compares_lower_to_per_thread_wave_masks_and_selects() {
|
||||
include_str!("../../../fixtures/golden/vector-compare.metal")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_vcc_fixture_matches_ir_and_msl_goldens() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vector-vcc.bin");
|
||||
let result = compile(Architecture::Gfx1030, code).unwrap();
|
||||
assert_eq!(
|
||||
result.ir,
|
||||
include_str!("../../../fixtures/golden/vector-vcc.ir")
|
||||
);
|
||||
assert_eq!(
|
||||
result.msl,
|
||||
include_str!("../../../fixtures/golden/vector-vcc.metal")
|
||||
);
|
||||
}
|
||||
@@ -25,6 +25,7 @@ either path. The [changelog](../CHANGELOG.md) records notable changes.
|
||||
- [Semantic coverage](shaders/semantic-coverage.md) — Generated per-family counts of identified, declared, decoded, lowered and verified gfx1030 forms.
|
||||
- [SOP2 scalar ALU](shaders/scalar-alu.md) — Supported scalar add, subtract and bitwise forms, their SCC rules and sources.
|
||||
- [Semantic registry](shaders/semantic-registry.md) — How to add an instruction form: registry fields, validation, generation and the independence rule.
|
||||
- [VOP2 select and carry](shaders/vector-vcc.md) — Wave32 lane selection, carry and borrow through the vector condition code.
|
||||
- [VOPC integer compares](shaders/vector-compare.md) — Wave32 compare forms, the VCC/EXEC contract, runtime `s_cbranch_vccz` and the Metal mapping.
|
||||
- [Metal Shading Language generation](shaders/msl.md) and [independent CPU reference](shaders/reference-interpreter.md) — Translation rules and separate CPU execution models.
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="530" height="185" viewBox="0 0 530 185" role="img" aria-labelledby="title description">
|
||||
<title id="title">Xenora · recorded progress</title>
|
||||
<desc id="description">Decoded gfx1030 forms: 120 of 120. Accepted Metal forms · Apple M5: 18 of 120. Accepted guest milestones · X1–X4: 4 of 4</desc>
|
||||
<desc id="description">Decoded gfx1030 forms: 124 of 124. Accepted Metal forms · Apple M5: 18 of 124. Accepted guest milestones · X1–X4: 4 of 4</desc>
|
||||
<rect x="1" y="1" width="528" height="183" rx="10" fill="#18212a" stroke="#516171"/>
|
||||
<g font-family="system-ui,sans-serif" fill="#eaf0f5">
|
||||
<text x="20" y="29" font-size="13" font-weight="700">RECORDED FIXTURE PROGRESS</text>
|
||||
<text x="20" y="58" font-size="13">Decoded gfx1030 forms</text>
|
||||
<text x="510" y="58" font-size="13" text-anchor="end">120 / 120</text>
|
||||
<text x="510" y="58" font-size="13" text-anchor="end">124 / 124</text>
|
||||
<rect x="20" y="65" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
<rect x="20" y="65" width="490.00" height="4" rx="2" fill="#88c6bd"/>
|
||||
<text x="20" y="96" font-size="13">Accepted Metal forms · Apple M5</text>
|
||||
<text x="510" y="96" font-size="13" text-anchor="end">18 / 120</text>
|
||||
<text x="510" y="96" font-size="13" text-anchor="end">18 / 124</text>
|
||||
<rect x="20" y="103" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
<rect x="20" y="103" width="73.50" height="4" rx="2" fill="#88c6bd"/>
|
||||
<rect x="20" y="103" width="71.13" height="4" rx="2" fill="#88c6bd"/>
|
||||
<text x="20" y="134" font-size="13">Accepted guest milestones · X1–X4</text>
|
||||
<text x="510" y="134" font-size="13" text-anchor="end">4 / 4</text>
|
||||
<rect x="20" y="141" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -133,16 +133,20 @@ The wider LLVM operand matrix exercises decoding only. ABI means application bin
|
||||
| `v_add_nc_u32_e32` | VOP2, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1 and VDST; inactive lanes keep VDST; D = S0 + S1, no carry | `4A160F06` | yes | yes | three-way passed | per-thread typed integer template over the lane's own VGPRs; partial EXEC as a lane merge | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_sub_nc_u32_e32` | VOP2, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1 and VDST; inactive lanes keep VDST; D = S0 - S1, no carry | `4C181308` | yes | yes | three-way passed | per-thread typed integer template over the lane's own VGPRs; partial EXEC as a lane merge | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_subrev_nc_u32_e32` | VOP2, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1 and VDST; inactive lanes keep VDST; D = S1 - S0, no carry | `4E1A170A` | yes | yes | three-way passed | per-thread typed integer template over the lane's own VGPRs; partial EXEC as a lane merge | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cndmask_b32_e32` | VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; select S1 when the VCC_LO lane bit is set, otherwise S0 | `020402C1` | yes | yes | three-way passed | per-thread integer expression with EXEC masking | implemented | local known-answer test passed | acceptance pending |
|
||||
| `v_add_co_ci_u32_e32` | VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned addition with carry input and output | `50040481` | yes | yes | three-way passed | per-thread integer expression with EXEC masking | implemented | local known-answer test passed | acceptance pending |
|
||||
| `v_sub_co_ci_u32_e32` | VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned S0 minus S1 with borrow input and output | `52060480` | yes | yes | three-way passed | per-thread integer expression with EXEC masking | implemented | local known-answer test passed | acceptance pending |
|
||||
| `v_subrev_co_ci_u32_e32` | VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned S1 minus S0 with borrow input and output | `540606C2` | yes | yes | three-way passed | per-thread integer expression with EXEC masking | implemented | local known-answer test passed | acceptance pending |
|
||||
<!-- status:instructions:end -->
|
||||
|
||||
## 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,
|
||||
matched 1,088 instructions across 18 streams: 16 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.
|
||||
operation. It covers 124 instruction forms.
|
||||
|
||||
The matrix checks the 81 inline integer selectors in VOP1, SOP1, SOPC and
|
||||
SOP2, forced literals that could otherwise be inline, literal selection in
|
||||
@@ -152,7 +156,7 @@ 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
|
||||
Five malformed LLVM probes produced diagnostics, and 27 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.
|
||||
|
||||
@@ -31,12 +31,12 @@ acceptance remain outside the verified count. All results concern synthetic fixt
|
||||
| SOPP | 36 | 6 | 0 | 6 | 6 | 6 | 4 | 4 | 0 |
|
||||
| VINTRP | 3 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP1 | 81 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
|
||||
| VOP2 | 47 | 20 | 18 | 20 | 20 | 20 | 7 | 7 | 11 |
|
||||
| VOP2 | 47 | 24 | 22 | 24 | 24 | 24 | 7 | 7 | 11 |
|
||||
| VOP3 | 416 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 12 |
|
||||
| VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOPC | 190 | 16 | 16 | 16 | 16 | 16 | 0 | 0 | 7 |
|
||||
| **Total** | 1465 | 120 | 108 | 124 | 120 | 120 | 18 | 18 | 65 |
|
||||
| **Total** | 1465 | 124 | 112 | 128 | 124 | 124 | 18 | 18 | 65 |
|
||||
|
||||
## Unsupported operand variants
|
||||
|
||||
@@ -50,6 +50,7 @@ The table counts distinct variant names per family across registry operand rules
|
||||
| SOPC | `sopc_scalar` | `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` |
|
||||
| SOPK | `sopk_compare` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc` |
|
||||
| SOPK | `sopk_sgpr` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc` |
|
||||
| VOP2 | `vop2_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOP2 | `vop2_vgpr` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOP2 | `vop2_vgpr2` | `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOP3 | `vop3_vgpr2` | `modifiers`, `src2`, `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
|
||||
@@ -111,7 +111,7 @@ error.
|
||||
| `variant` | Rust enum variant of the typed operation | CamelCase, e.g. `AddU32` |
|
||||
| `operation` | The primitive the form uses | `add`, `sub`, `and`, `or`, `xor`, `andn2`, `orn2`, `nand`, `nor`, `xnor`, `lshl`, `lshr`, `ashr`, `min`, `max`, `cselect`, `bfm`, `mul`, `mul_hi`, `bfe`, `absdiff`, `lshl_add`, `mul24`, `mul_hi24` (vector only), `mov` (SOP1 and SOPK), `cmov` (SOPK only), `compare` and the SOP1 unaries |
|
||||
| `signedness` | How operands are read | `unsigned`, `signed`, `bitwise` (always `bitwise` for the logical operations, `cselect` and `bfm`; never for the arithmetic ones, `add`, `sub`, `min`, `max`, `mul`, `mul_hi`, `bfe`, `absdiff` and `lshl_add`; shifts take their primitive's signedness) |
|
||||
| `carry_in` | Whether the form reads SCC: carry-in, borrow-in or the select condition | `none`, `scc` (`scc` only for unsigned `add` and `sub`, and required for `cselect`) |
|
||||
| `carry_in` | Implicit carry, borrow or select input | `none`, `scc` for supported scalar forms, `vcc` for the Wave32 VOP2 select and carry forms |
|
||||
| `width` | Operand and result width in bits | `32` |
|
||||
| `source_bits` | Sign extension only: the low bits of S0 that are read. The XML must list S0 with that size and format (`FMT_NUM_I8` or `FMT_NUM_I16`) | `8`, `16`; required for `sext`, rejected elsewhere |
|
||||
| `relation` | Compares only: the relation tested with S0 on the left | `eq`, `lg` (not equal), `gt`, `ge`, `lt`, `le`; required for `compare`, rejected elsewhere |
|
||||
@@ -119,8 +119,8 @@ error.
|
||||
| `shift_amount` | `lshl_add` only: the fixed left shift of S0 before the add | `1` to `4`; required for `lshl_add`, rejected elsewhere |
|
||||
| `shift_count_bits` | Shifts only: the low bits of the count source used as the count: S1, or S0 for a vector form with `source_order = "reversed"`. Scalar forms mask it in the generated evaluation, vector forms in their MSL template; the XML must list the count source as unsigned | `5` (log2 of `width`); required for shifts, rejected elsewhere |
|
||||
| `scc` | What the form writes to SCC | `carry_out`, `borrow`, `signed_overflow`, `nonzero`, `relation` (SOPC and SOPK compares only), `selected_src0` (min and max: S0 won the strict compare, so a tie gives 0), `unchanged` |
|
||||
| `vcc`, `exec` | Implicit effect on VCC and EXEC | `unchanged`; `vcc` is `lane_mask` exactly for the VOPC compares (VCC_LO bit n = EXEC[n] & test, fully written; VCC_HI unknown afterwards, see [vector-compare.md](vector-compare.md)); `exec` must be `unchanged` (explicit destinations are covered by the operand rule) |
|
||||
| `wave` | Wave sizes the form is valid in | `wave32` exactly for the VOPC compares (their one entry point is the Wave32 compute fixture ABI, vector-compare.md section 2), `any` for everything else; the decoder has no wave-size input, so no other form may claim `wave32` |
|
||||
| `vcc`, `exec` | Implicit effect on VCC and EXEC | `unchanged`; `vcc` is `lane_mask` exactly for the VOPC compares and the three VOP2 carry forms (fully written VCC_LO, with inactive bits zero and VCC_HI unknown afterwards); `exec` must be `unchanged` (explicit destinations are covered by the operand rule) |
|
||||
| `wave` | Wave sizes the form is valid in | `wave32` for the VOPC compares and the VCC-reading VOP2 forms in the Wave32 compute fixture ABI, `any` for other forms |
|
||||
| `operands` | Name of an `[operand_rules]` entry for the same family | e.g. `sop2_sgpr` |
|
||||
| `spec` | References `{ document, section, page }` | at least one `guide` reference with a page above 0 |
|
||||
| `verify` | Evidence the form needs before it counts as verified | `reference`, `independent`, `metal`, `llvm_encoding` |
|
||||
@@ -162,11 +162,11 @@ and one literal dword. The move copies the source and leaves SCC unchanged.
|
||||
The destination vocabulary preserves the original decoder subset of the
|
||||
RDNA 2 guide sections 5.3 and 12.3.
|
||||
|
||||
Vector forms (operand rules `vop2_vgpr` and `vop2_vgpr2`, kind `vector`; both
|
||||
Binary vector forms (operand rules `vop2_vgpr` and `vop2_vgpr2`, kind `vector`; both
|
||||
generate the one `VectorAluOp` enum, whose `operand_rule()` tells the decoder
|
||||
which rule a form uses) use a separate table:
|
||||
the pair picks the per-lane `VectorBinary` the MSL lowering uses, and `scc`
|
||||
must be `unchanged` (VOP2 integer forms write no SCC, VCC or EXEC):
|
||||
must be `unchanged` (these binary forms write no SCC, VCC or EXEC):
|
||||
|
||||
| `operation` / `signedness` | `VectorBinary` |
|
||||
| --- | --- |
|
||||
@@ -177,6 +177,12 @@ must be `unchanged` (VOP2 integer forms write no SCC, VCC or EXEC):
|
||||
| `and`, `or`, `xor` / `bitwise` | `And`, `Or`, `Xor` |
|
||||
| `lshl`, `lshr` / `bitwise`, `ashr` / `signed` (with `shift_count_bits = 5`) | `ShiftLeft`, `ShiftRight`, `ArithmeticShiftRight` |
|
||||
|
||||
The [Wave32 VOP2 select and carry forms](vector-vcc.md) use `vop2_vcc` with
|
||||
the general SRC0 domain and an implicit VCC input. The generator checks the
|
||||
direction of each fieldless VCC operand in the pinned XML. The three arithmetic
|
||||
forms also declare a lane-mask output and use the same reverse-source mechanism
|
||||
as the no-carry subtraction.
|
||||
|
||||
`vop2_vgpr2` is the VGPR-only subset (SRC0 256-511) that the hand-written decoder
|
||||
accepted for `v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`
|
||||
and `v_ashrrev_i32` before they moved into the registry (#215 M27); widening them
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Wave32 vector select, carry and borrow
|
||||
|
||||
The gfx1030 compute fixture ABI supports four 32-bit vector two-operand
|
||||
instruction (VOP2) forms that read the vector condition code (VCC).
|
||||
In Wave32, bit `n` of `VCC_LO` supplies lane `n`'s input `c`.
|
||||
The AMD RDNA 2 guide describes the operations in section 12.7, the VOP2 word
|
||||
in section 13.3.1, and the execution and condition masks in sections 3.3 and 3.9.
|
||||
|
||||
| Instruction | Active lane destination | Active lane VCC output |
|
||||
| --- | --- | --- |
|
||||
| `v_cndmask_b32_e32` | S1 if c is set, S0 otherwise | Preserved |
|
||||
| `v_add_co_ci_u32_e32` | Low 32 bits of S0 + S1 + c | Exact sum reaches 2³² |
|
||||
| `v_sub_co_ci_u32_e32` | Low 32 bits of S0 − S1 − c | S1 + c exceeds S0 |
|
||||
| `v_subrev_co_ci_u32_e32` | Low 32 bits of S1 − S0 − c | S0 + c exceeds S1 |
|
||||
|
||||
Section 12.7 prints a reverse-subtract flag expression that conflicts with its
|
||||
prose and destination equation. Xenora uses unsigned borrow from the stated
|
||||
reverse subtraction, consistent with section 12.12's `v_subrev_co_u32` when
|
||||
the incoming borrow is zero.
|
||||
|
||||
Inactive lanes retain the old vector destination (VDST). Section 3.9
|
||||
describes a fully written VCC mask and defines carry-out in terms of executing
|
||||
lanes. Under that reading, inactive lanes contribute zero to a carry or borrow
|
||||
output. Section 3.3 says scalar-register-writing vector ALU instructions
|
||||
still execute under empty EXEC, so the carry output is a zero mask.
|
||||
The synthetic ABI also zeros
|
||||
absent lanes in a final short wave when it constructs a new mask.
|
||||
The scalar condition code (SCC) and EXEC are preserved by these forms.
|
||||
|
||||
The general SRC0 subset includes vector general-purpose registers (VGPRs),
|
||||
scalar registers s0–s105, `vcc_lo`, inline integers and one literal word.
|
||||
VSRC1 and VDST are VGPRs. Translated scalar sources must be known or supplied
|
||||
by a translated VCC result. The pinned XML lists the VCC input on all four
|
||||
forms and an additional VCC output on the three arithmetic forms. VOP3
|
||||
encodings with explicit scalar conditions and VOP3B carry-out-only forms
|
||||
are outside this subset.
|
||||
|
||||
The Metal lowering reuses the compare mask's replay of the current wave's
|
||||
input lanes to form carry and borrow masks. The original `vector-vcc.s`
|
||||
fixture chains all four operations. LLVM checks encoding, and the guide-derived
|
||||
oracle checks both CPU interpreters. Native Metal readback and independent
|
||||
acceptance are pending. The expectations are derived from the public AMD specification (class B).
|
||||
@@ -1478,6 +1478,54 @@ recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cndmask_b32_e32"
|
||||
encoding = "VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; select S1 when the VCC_LO lane bit is set, otherwise S0"
|
||||
representation = "`020402C1`"
|
||||
lowering = "per-thread integer expression with EXEC masking"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_add_co_ci_u32_e32"
|
||||
encoding = "VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned addition with carry input and output"
|
||||
representation = "`50040481`"
|
||||
lowering = "per-thread integer expression with EXEC masking"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_sub_co_ci_u32_e32"
|
||||
encoding = "VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned S0 minus S1 with borrow input and output"
|
||||
representation = "`52060480`"
|
||||
lowering = "per-thread integer expression with EXEC masking"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_subrev_co_ci_u32_e32"
|
||||
encoding = "VOP2, Wave32; VCC_LO lane input; general SRC0, VGPR VSRC1 and VDST; unsigned S1 minus S0 with borrow input and output"
|
||||
representation = "`540606C2`"
|
||||
lowering = "per-thread integer expression with EXEC masking"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[guest_milestones]
|
||||
X1 = "accepted"
|
||||
X2 = "accepted"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
0000: t0 = load.u32 input[index]
|
||||
000c: t1 = const.u32 0x00000000
|
||||
000c: t2 = wave.mask v_cmp_eq_u32_e32 t1, t0 exec=0xffffffff
|
||||
0010: t3 = const.u32 0xffffffff
|
||||
0010: t4 = vcc.Select t3, t0, t2
|
||||
0014: t5 = const.u32 0x00000001
|
||||
0014: t6 = vcc.AddCarry.flag t5, t4, t2
|
||||
0014: t7 = wave.carry t6 exec=0xffffffff
|
||||
0014: t8 = vcc.AddCarry t5, t4, t2
|
||||
0018: t9 = const.u32 0x00000000
|
||||
0018: t10 = vcc.SubtractBorrow.flag t9, t8, t7
|
||||
0018: t11 = wave.carry t10 exec=0xffffffff
|
||||
0018: t12 = vcc.SubtractBorrow t9, t8, t7
|
||||
001c: t13 = const.u32 0xfffffffe
|
||||
001c: t14 = vcc.SubtractBorrow.flag t12, t13, t11
|
||||
001c: t15 = wave.carry t14 exec=0xffffffff
|
||||
001c: t16 = vcc.SubtractBorrow t12, t13, t11
|
||||
0024: store.u32 output[index], t15
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
kernel void xenora_compute(
|
||||
device const uint* input [[buffer(0)]],
|
||||
device uint* output [[buffer(1)]],
|
||||
uint index [[thread_position_in_grid]],
|
||||
uint grid [[threads_per_grid]]) {
|
||||
uint t0 = input[index];
|
||||
uint t1 = 0x00000000u;
|
||||
uint t2 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (t1 == l0) ? 1u : 0u;
|
||||
t2 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t3 = 0xffffffffu;
|
||||
uint t4 = ((t2 >> (index & 31u)) & 1u) != 0u ? t0 : t3;
|
||||
uint t5 = 0x00000001u;
|
||||
uint t6 = uint((ulong(t5) + ulong(t4) + ((t2 >> (index & 31u)) & 1u)) >> 32u);
|
||||
uint t7 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint l4 = ((t2 >> lane) & 1u) != 0u ? l0 : t3;
|
||||
uint l6 = uint((ulong(t5) + ulong(l4) + ((t2 >> lane) & 1u)) >> 32u);
|
||||
uint pass = l6;
|
||||
t7 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t8 = t5 + t4 + ((t2 >> (index & 31u)) & 1u);
|
||||
uint t9 = 0x00000000u;
|
||||
uint t10 = uint(ulong(t8) + ((t7 >> (index & 31u)) & 1u) > ulong(t9));
|
||||
uint t11 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint l4 = ((t2 >> lane) & 1u) != 0u ? l0 : t3;
|
||||
uint l8 = t5 + l4 + ((t2 >> lane) & 1u);
|
||||
uint l10 = uint(ulong(l8) + ((t7 >> lane) & 1u) > ulong(t9));
|
||||
uint pass = l10;
|
||||
t11 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t12 = t9 - t8 - ((t7 >> (index & 31u)) & 1u);
|
||||
uint t13 = 0xfffffffeu;
|
||||
uint t14 = uint(ulong(t13) + ((t11 >> (index & 31u)) & 1u) > ulong(t12));
|
||||
uint t15 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint l4 = ((t2 >> lane) & 1u) != 0u ? l0 : t3;
|
||||
uint l8 = t5 + l4 + ((t2 >> lane) & 1u);
|
||||
uint l12 = t9 - l8 - ((t7 >> lane) & 1u);
|
||||
uint l14 = uint(ulong(t13) + ((t11 >> lane) & 1u) > ulong(l12));
|
||||
uint pass = l14;
|
||||
t15 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t16 = t12 - t13 - ((t11 >> (index & 31u)) & 1u);
|
||||
output[index] = t15;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Original Wave32 example. The compare derives VCC from the input, then each
|
||||
// carry/borrow feeds the next operation. Before reverse subtract, v3 is
|
||||
// 0xfffffffe for a zero input and 0xffffffff otherwise, with borrow-in 1.
|
||||
// Subtracting 0xfffffffe and the borrow-in sets the final VCC bit for zero inputs.
|
||||
.text
|
||||
buffer_load_dword v1, v0, s[0:3], 0 idxen
|
||||
s_waitcnt vmcnt(0)
|
||||
v_cmp_eq_u32_e32 vcc_lo, 0, v1
|
||||
v_cndmask_b32_e32 v2, -1, v1, vcc_lo
|
||||
v_add_co_ci_u32_e32 v2, vcc_lo, 1, v2, vcc_lo
|
||||
v_sub_co_ci_u32_e32 v3, vcc_lo, 0, v2, vcc_lo
|
||||
v_subrev_co_ci_u32_e32 v3, vcc_lo, -2, v3, vcc_lo
|
||||
v_mov_b32_e32 v4, vcc_lo
|
||||
buffer_store_dword v4, v0, s[4:7], 0 idxen
|
||||
s_waitcnt_vscnt null, 0
|
||||
s_endpgm
|
||||
@@ -12,7 +12,7 @@ case "${1:-}" in
|
||||
esac
|
||||
|
||||
for name in add bitwise-branch float-exact or shifts ashr \
|
||||
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft; do
|
||||
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft vector-vcc; do
|
||||
"$llvm_bin/llvm-mc" -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -mattr=+wavefrontsize32 \
|
||||
-filetype=obj "fixtures/rdna2/$name.s" -o "$scratch/$name.o"
|
||||
"$llvm_bin/llvm-objcopy" -O binary --only-section=.text "$scratch/$name.o" "$scratch/$name.bin"
|
||||
|
||||
@@ -771,12 +771,21 @@ class Validate(unittest.TestCase):
|
||||
text = gen.render(vectors(), snapshot())
|
||||
self.assertIn("pub enum VectorAluOp {", text)
|
||||
self.assertIn("if word & 0x8000_0000 != 0x0000_0000 {", text)
|
||||
self.assertIn("Self::MulI32I24 => VectorBinary::Mul24Signed,", text)
|
||||
self.assertIn("Self::SubrevNcU32 => VectorBinary::Sub,", text)
|
||||
self.assertIn("Self::MulI32I24 => VectorLowering::Binary(VectorBinary::Mul24Signed),", text)
|
||||
self.assertIn("Self::SubrevNcU32 => VectorLowering::Binary(VectorBinary::Sub),", text)
|
||||
self.assertIn("Self::SubrevNcU32 => true,", text.split("fn swaps_sources", 1)[1])
|
||||
self.assertIn('Self::AddU32 => "v_min_i32_e32",', text)
|
||||
self.assertIn("swap_sources: true,", text)
|
||||
|
||||
def test_vop2_vcc_requires_the_xml_input_and_output(self):
|
||||
reg = gen.load_registry()
|
||||
snap = gen.load_snapshot()
|
||||
operands = snap["variants"][("V_ADD_CO_CI_U32", "ENC_VOP2")]["operands"]
|
||||
operands[:] = [op for op in operands if not (op[2] == "OPR_VCC" and op[4])]
|
||||
self.rejects(reg, "V_ADD_CO_CI_U32: carry_in vcc requires one implicit XML VCC input", snap)
|
||||
form(reg, "V_CNDMASK_B32")["vcc"] = "lane_mask"
|
||||
self.rejects(reg, "V_CNDMASK_B32: vcc lane_mask contradicts rule vop2_vcc", snap)
|
||||
|
||||
def test_accepts_compares(self):
|
||||
self.assertEqual(self.errors(compares()), [])
|
||||
|
||||
@@ -1140,7 +1149,7 @@ class Validate(unittest.TestCase):
|
||||
|
||||
def test_rejects_unknown_signedness_carry_in_exec_and_wave(self):
|
||||
for key, value in (
|
||||
("signedness", "float"), ("carry_in", "vcc"), ("exec", "written"), ("wave", "wave64"),
|
||||
("signedness", "float"), ("carry_in", "exec"), ("exec", "written"), ("wave", "wave64"),
|
||||
):
|
||||
with self.subTest(key=key):
|
||||
reg = registry()
|
||||
|
||||
@@ -99,6 +99,7 @@ enum Insn {
|
||||
VXor(u8, u8, u8),
|
||||
/// VOP2 integer opcode 9-12, 17-20, 30 or 37-39: VDST, SRC0, VSRC1.
|
||||
VInt(u32, u8, CmpSrc, u8),
|
||||
VIntVcc(u32, u8, CmpSrc, u8),
|
||||
/// VOP1 integer opcode 55-59: VDST, SRC0.
|
||||
VUnary(u32, u8, CmpSrc),
|
||||
/// `v_swap_b32 vD, vS` (VOP1 opcode 101).
|
||||
@@ -232,6 +233,26 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
None
|
||||
})
|
||||
}
|
||||
Insn::VIntVcc(opcode, dst, src0, src1) => {
|
||||
if let Some(error) = first_error(&lanes) {
|
||||
return Err(error);
|
||||
}
|
||||
vector_vcc(
|
||||
&mut lanes,
|
||||
&sgpr,
|
||||
execution_mask,
|
||||
(opcode, dst, src0, src1),
|
||||
offset,
|
||||
)
|
||||
.map(|mask| {
|
||||
if opcode != 1 {
|
||||
sgpr[106] = Some(mask);
|
||||
sgpr[107] = None;
|
||||
vcc_lane_derived = execution_mask != 0;
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
Insn::SUnary(opcode, dst, src) => {
|
||||
if dst < 8 {
|
||||
Err(format!("{offset:#x}: write to a resource SGPR"))
|
||||
@@ -325,6 +346,60 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
Err(first_error(&lanes).unwrap_or_else(|| "stream ended without s_endpgm".to_string()))
|
||||
}
|
||||
|
||||
/// Guide 12.7 vector select and carry/borrow, with the Wave32 mask from 3.9.
|
||||
fn vector_vcc(
|
||||
lanes: &mut [Lane],
|
||||
sgpr: &[Option<u32>; 128],
|
||||
exec: u32,
|
||||
(opcode, dst, src0, src1): (u32, u8, CmpSrc, u8),
|
||||
offset: usize,
|
||||
) -> Result<u32, String> {
|
||||
if exec == 0 {
|
||||
return Ok(0);
|
||||
}
|
||||
let incoming = sgpr[106].ok_or_else(|| format!("{offset:#x}: uninitialized vcc_lo"))?;
|
||||
let mut mask = 0;
|
||||
for (index, lane) in lanes.iter_mut().enumerate() {
|
||||
if exec != u32::MAX && lane.vgpr[usize::from(dst)].is_none() {
|
||||
return Err(format!("{offset:#x}: partial EXEC on uninitialized VGPR"));
|
||||
}
|
||||
let a = match src0 {
|
||||
CmpSrc::Sgpr(reg) => sgpr[usize::from(reg)]
|
||||
.ok_or_else(|| format!("{offset:#x}: uninitialized s{reg}"))?,
|
||||
CmpSrc::Vcc => incoming,
|
||||
CmpSrc::Imm(value) => value,
|
||||
CmpSrc::Vgpr(reg) => read_vgpr(lane, reg, offset)?,
|
||||
};
|
||||
let b = read_vgpr(lane, src1, offset)?;
|
||||
let lane_bit = 2_u32.pow(index as u32);
|
||||
if exec & lane_bit == 0 {
|
||||
continue;
|
||||
}
|
||||
check_destination(dst, lane.pending_read, offset)?;
|
||||
let bit = incoming / lane_bit % 2;
|
||||
let (value, flag) = match opcode {
|
||||
1 => (if bit == 1 { b } else { a }, false),
|
||||
40 => {
|
||||
let (sum, overflow) = a.overflowing_add(b);
|
||||
let (value, carry) = sum.overflowing_add(bit);
|
||||
(value, overflow || carry)
|
||||
}
|
||||
41 | 42 => {
|
||||
let (lhs, rhs) = if opcode == 42 { (b, a) } else { (a, b) };
|
||||
let (difference, underflow) = lhs.overflowing_sub(rhs);
|
||||
let (value, borrow) = difference.overflowing_sub(bit);
|
||||
(value, underflow || borrow)
|
||||
}
|
||||
_ => unreachable!("not a VCC-reading VOP2 opcode"),
|
||||
};
|
||||
lane.vgpr[usize::from(dst)] = Some(value);
|
||||
if flag {
|
||||
mask |= lane_bit;
|
||||
}
|
||||
}
|
||||
Ok(mask)
|
||||
}
|
||||
|
||||
/// One SOPK instruction, per the operation text of guide 12.2. SDST names
|
||||
/// the destination and, for every form but the two moves, the first source.
|
||||
fn scalar_immediate(
|
||||
@@ -1250,6 +1325,13 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
|
||||
}
|
||||
// VOP2 integer forms: bit 31 = 0, OP 30:25, VDST 24:17, VSRC1 16:9, SRC0 8:0.
|
||||
let vop2_op = (first >> 25) & 0x3f;
|
||||
if first >> 31 == 0 && matches!(vop2_op, 1 | 40..=42) {
|
||||
let (src0, len) = vector_src0(code, offset, first, "VOP2")?;
|
||||
return Ok((
|
||||
Insn::VIntVcc(vop2_op, (first >> 17) as u8, src0, (first >> 9) as u8),
|
||||
len,
|
||||
));
|
||||
}
|
||||
if first >> 31 == 0 && matches!(vop2_op, 9..=12 | 17..=20 | 30 | 37..=39) {
|
||||
let (src0, len) = vector_src0(code, offset, first, "VOP2")?;
|
||||
let insn = Insn::VInt(vop2_op, (first >> 17) as u8, src0, (first >> 9) as u8);
|
||||
|
||||
@@ -784,6 +784,27 @@ mod review {
|
||||
const SCALAR_ARITH_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/scalar-arith.bin");
|
||||
// Hand-derived in fixtures/rdna2/scalar-arith.s from the guide's 12.1 pseudocode.
|
||||
const SCALAR_ARITH_KEY: u32 = 0x8115_7dfe;
|
||||
#[test]
|
||||
fn vector_vcc_chain_returns_the_zero_input_mask() {
|
||||
let code = include_bytes!("../../fixtures/rdna2/vector-vcc.bin");
|
||||
let input: Vec<_> = [0, 1, u32::MAX, 5, 0, 7]
|
||||
.into_iter()
|
||||
.cycle()
|
||||
.take(67)
|
||||
.collect();
|
||||
let expected: Vec<_> = input
|
||||
.chunks(32)
|
||||
.flat_map(|wave| {
|
||||
let mask = wave
|
||||
.iter()
|
||||
.enumerate()
|
||||
.fold(0, |mask, (lane, &x)| mask | (u32::from(x == 0) << lane));
|
||||
std::iter::repeat_n(mask, wave.len())
|
||||
})
|
||||
.collect();
|
||||
verify(code, &input, Some(&expected));
|
||||
}
|
||||
|
||||
const VECTOR_INTEGER_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/vector-integer.bin");
|
||||
|
||||
/// fixtures/rdna2/vector-integer.s for one lane input `x`, written from the
|
||||
|
||||
@@ -745,9 +745,9 @@ fn unsupported_vop2_integer_encodings_are_rejected() {
|
||||
fn other_vop2_opcodes_stay_unsupported() {
|
||||
// Every VOP2 opcode (0-61; 62 and 63 are the VOPC and VOP1 encodings)
|
||||
// except the forms supported before this set (V_ADD_F32 3, V_MUL_F32 8,
|
||||
// the shifts 22, 24, 26 and AND, OR, XOR 27-29) and these twelve. VDST is
|
||||
// the shifts 22, 24, 26 and AND, OR, XOR 27-29) and the registered integer forms. VDST is
|
||||
// initialized, so a form that also reads it fails only on the opcode.
|
||||
let earlier = [3, 8, 22, 24, 26, 27, 28, 29];
|
||||
let earlier = [1, 3, 8, 22, 24, 26, 27, 28, 29, 40, 41, 42];
|
||||
let supported: Vec<u32> = FORMS
|
||||
.iter()
|
||||
.map(|&(form, _)| form as u32)
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! Wave32 VOP2 select and carry/borrow oracle from AMD RDNA 2 ISA guide
|
||||
//! sections 3.3, 3.9, 12.7 and 13.3.1.
|
||||
|
||||
#[path = "../independent_ref.rs"]
|
||||
mod independent_ref;
|
||||
|
||||
use xenora_shader::{Architecture, CompileError, compile};
|
||||
|
||||
const FORMS: [u32; 4] = [1, 40, 41, 42];
|
||||
const EXEC_PATTERNS: [u32; 3] = [u32::MAX, 0xaaaa_aaab, 0];
|
||||
const INITIAL_DST: u32 = 0x1234_5678;
|
||||
const SCALAR_VCC: u32 = 0x8000_0005;
|
||||
|
||||
fn words(code: &[u32]) -> Vec<u8> {
|
||||
code.iter().flat_map(|word| word.to_le_bytes()).collect()
|
||||
}
|
||||
|
||||
fn vop2(op: u32, dst: u32, src0: u32, src1: u32) -> u32 {
|
||||
op << 25 | dst << 17 | src1 << 9 | src0
|
||||
}
|
||||
|
||||
fn program(body: &[u32], output: u32) -> Vec<u8> {
|
||||
let mut code = vec![0xe030_2000, 0x8000_0100, 0xbf8c_3f70];
|
||||
code.extend(body);
|
||||
code.extend([
|
||||
0xe070_2000,
|
||||
0x8001_0000 | output << 8,
|
||||
0xbbfd_0000,
|
||||
0xbf81_0000,
|
||||
]);
|
||||
words(&code)
|
||||
}
|
||||
|
||||
fn input() -> Vec<u32> {
|
||||
[0, 1, 2, u32::MAX, u32::MAX - 1, 0x8000_0000, 0, 31]
|
||||
.into_iter()
|
||||
.cycle()
|
||||
.take(67)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Guide 12.7 gives the unbounded result and the 32-bit destination.
|
||||
/// For SUBREV the prose and D equation reverse the operands. The printed
|
||||
/// borrow formula repeats SUB's order, inconsistent with that subtraction.
|
||||
fn expected(op: u32, a: u32, b: u32, bit: u32) -> (u32, bool) {
|
||||
let (a, b, bit) = (i128::from(a), i128::from(b), i128::from(bit));
|
||||
let exact = match op {
|
||||
1 => return (if bit == 0 { a } else { b } as u32, false),
|
||||
40 => a + b + bit,
|
||||
41 => a - b - bit,
|
||||
42 => b - a - bit,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let modulus = 1_i128 << 32;
|
||||
(
|
||||
exact.rem_euclid(modulus) as u32,
|
||||
!(0..modulus).contains(&exact),
|
||||
)
|
||||
}
|
||||
|
||||
fn cases() -> Vec<(Vec<u8>, Vec<u32>)> {
|
||||
let input = input();
|
||||
let mut cases = Vec::new();
|
||||
for op in FORMS {
|
||||
for exec in EXEC_PATTERNS {
|
||||
for (selector, extension, src0) in [
|
||||
(129, None, 1),
|
||||
(193, None, u32::MAX),
|
||||
(8, None, 0x8000_0000),
|
||||
(255, Some(u32::MAX - 1), u32::MAX - 1),
|
||||
(259, None, INITIAL_DST),
|
||||
(106, None, 0),
|
||||
] {
|
||||
for from_compare in [false, true] {
|
||||
let mut body = vec![0x7e06_02ff, INITIAL_DST, 0xbe88_03ff, 0x8000_0000];
|
||||
if from_compare {
|
||||
body.push(0x7d84_0280); // v_cmp_eq_u32_e32 vcc_lo, 0, v1
|
||||
} else {
|
||||
body.extend([0xbeea_03ff, SCALAR_VCC]); // s_mov_b32 vcc_lo, literal
|
||||
}
|
||||
body.extend([0xbefe_03ff, exec]);
|
||||
body.push(vop2(op, 3, selector, 1));
|
||||
body.extend(extension);
|
||||
body.push(0xbefe_03c1); // restore full EXEC for the store
|
||||
|
||||
let mut values = Vec::new();
|
||||
let mut masks = Vec::new();
|
||||
for wave in input.chunks(32) {
|
||||
let incoming = if from_compare {
|
||||
wave.iter()
|
||||
.enumerate()
|
||||
.fold(0, |mask, (lane, &x)| mask | (u32::from(x == 0) << lane))
|
||||
} else {
|
||||
SCALAR_VCC
|
||||
};
|
||||
let mut mask = if op == 1 { incoming } else { 0 };
|
||||
for (lane, &x) in wave.iter().enumerate() {
|
||||
if exec & (1 << lane) == 0 {
|
||||
values.push(INITIAL_DST);
|
||||
} else {
|
||||
let a = if selector == 106 { incoming } else { src0 };
|
||||
let (value, flag) = expected(op, a, x, (incoming >> lane) & 1);
|
||||
values.push(value);
|
||||
mask |= u32::from(flag) << lane;
|
||||
}
|
||||
}
|
||||
masks.extend(std::iter::repeat_n(mask, wave.len()));
|
||||
}
|
||||
cases.push((program(&body, 3), values));
|
||||
body.push(0x7e08_026a); // v_mov_b32_e32 v4, vcc_lo
|
||||
cases.push((program(&body, 4), masks));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cases
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop2_vcc_matches_guide_on_both_interpreters() {
|
||||
let input = input();
|
||||
for (index, (code, expected)) in cases().into_iter().enumerate() {
|
||||
compile(Architecture::Gfx1030, &code).unwrap();
|
||||
assert_eq!(
|
||||
xenora_ref::execute(&code, &input).unwrap(),
|
||||
expected,
|
||||
"reference case {index}"
|
||||
);
|
||||
assert_eq!(
|
||||
independent_ref::execute(&code, &input).unwrap(),
|
||||
expected,
|
||||
"independent case {index}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop2_vcc_rejects_unsupported_operands_and_uninitialized_state() {
|
||||
let mut cases = Vec::new();
|
||||
for op in FORMS {
|
||||
cases.push((program(&[vop2(op, 2, 129, 1)], 2), 12));
|
||||
for selector in [107, 124, 126, 128 + 112, 249, 250] {
|
||||
cases.push((program(&[vop2(op, 2, selector, 1), 0], 2), 12));
|
||||
}
|
||||
let fixture = words(&[vop2(op, 2, 255, 1)]);
|
||||
assert!(matches!(
|
||||
compile(Architecture::Gfx1030, &fixture),
|
||||
Err(CompileError::Decode(_))
|
||||
));
|
||||
assert!(xenora_ref::execute(&fixture, &[1]).is_err());
|
||||
assert!(independent_ref::execute(&fixture, &[1]).is_err());
|
||||
cases.push((
|
||||
program(&[0xbeea_03c1, 0xbefe_0381, vop2(op, 2, 129, 1)], 2),
|
||||
20,
|
||||
));
|
||||
}
|
||||
// LLVM-assembled e64 forms with an explicit scalar condition operand.
|
||||
for first in [0xd501_0002, 0xd528_0902, 0xd529_0902, 0xd52a_0902] {
|
||||
cases.push((program(&[first, 0x0022_0303], 2), 12));
|
||||
}
|
||||
for (code, offset) in cases {
|
||||
let result = compile(Architecture::Gfx1030, &code);
|
||||
let got = match result {
|
||||
Err(CompileError::Decode(error)) => error.offset,
|
||||
Err(CompileError::Verify { offset, .. }) => offset,
|
||||
other => panic!("expected rejection at {offset:#x}: {other:?}"),
|
||||
};
|
||||
assert_eq!(got, offset);
|
||||
assert_eq!(
|
||||
xenora_ref::execute(&code, &[1, 2]).unwrap_err().offset,
|
||||
offset
|
||||
);
|
||||
assert!(
|
||||
independent_ref::execute(&code, &[1, 2])
|
||||
.unwrap_err()
|
||||
.starts_with(&format!("{offset:#x}:"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires a native Metal device with API and shader validation"]
|
||||
fn vop2_vcc_matches_guide_on_native_metal() {
|
||||
assert_eq!(std::env::var("MTL_DEBUG_LAYER").as_deref(), Ok("1"));
|
||||
assert_eq!(std::env::var("MTL_SHADER_VALIDATION").as_deref(), Ok("1"));
|
||||
let metal = xenora_metal::NativeCompute::new().unwrap();
|
||||
let input = input();
|
||||
let fixture = include_bytes!("../../../fixtures/rdna2/vector-vcc.bin");
|
||||
let fixture_expected = input
|
||||
.chunks(32)
|
||||
.flat_map(|wave| {
|
||||
let mask = wave
|
||||
.iter()
|
||||
.enumerate()
|
||||
.fold(0, |mask, (lane, &x)| mask | (u32::from(x == 0) << lane));
|
||||
std::iter::repeat_n(mask, wave.len())
|
||||
})
|
||||
.collect();
|
||||
for (index, (code, expected)) in cases()
|
||||
.into_iter()
|
||||
.chain([(fixture.to_vec(), fixture_expected)])
|
||||
.enumerate()
|
||||
{
|
||||
let shader = compile(Architecture::Gfx1030, &code).unwrap();
|
||||
assert_eq!(
|
||||
metal
|
||||
.run_words(&shader.msl, xenora_shader::ENTRY_POINT, &input)
|
||||
.unwrap(),
|
||||
expected,
|
||||
"Metal case {index}",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user