mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Merge pull request #304 from elforeign/task/215-m27
isa, decoder, shader: move the six VOP2 logical and shift forms into the registry (#215)
This commit is contained in:
13 files changed
+540
-192
No files matched your search
@@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game
|
||||
remains unsupported.
|
||||
|
||||
### Changed
|
||||
- Moved the six hand-written gfx1030 VOP2 logical and shift forms (`v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`, `v_ashrrev_i32`, AMD guide section 12.7) into the semantic registry under a new VGPR-only operand rule `vop2_vgpr2`, with no behaviour change: a sweep of 132,608 VOP2, VOP1 and SOP1 words decodes to the same text, length and error before and after, the MSL goldens are unchanged, and the runtime-region allowlist admits exactly the same six forms. The per-lane `VectorBinary` gained `And`, `Or`, `Xor` and the three shifts (count masked to S0[4:0]); 6 hand-written instruction variants and their decoder and lowering arms are gone (17 hand-written forms remain). Part of #215.
|
||||
- Added non-blocking Metal compute submission through `submit_words` and `wait`, with completion-aware resource retirement and a sixteen-dispatch in-flight limit. Synchronous calls keep their existing behavior. The benchmark reports the host submission split and compares synchronous and pipelined batches.
|
||||
- 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.
|
||||
|
||||
|
||||
+11
-53
@@ -10,13 +10,12 @@ pub use xenora_isa::{
|
||||
use xenora_isa::{
|
||||
BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, EXP, IMAGE_SAMPLE_LZ, S_BRANCH, S_CBRANCH_EXECZ,
|
||||
S_CBRANCH_SCC0, S_CBRANCH_VCCZ, S_ENDPGM, S_MOV_B32, S_WAITCNT, S_WAITCNT_VSCNT, V_ADD_F32,
|
||||
V_AND_B32, V_ASHRREV_I32, V_INTERP_P1_F32, V_INTERP_P2_F32, V_LSHLREV_B32, V_LSHRREV_B32,
|
||||
V_MOV_B32, V_MUL_F32, V_OR_B32, V_XOR_B32, VCC_LO,
|
||||
V_INTERP_P1_F32, V_INTERP_P2_F32, V_MOV_B32, V_MUL_F32, VCC_LO,
|
||||
};
|
||||
|
||||
use xenora_isa::meta::EncodingFamily;
|
||||
use xenora_isa::semantics::FORM_IDS;
|
||||
pub use xenora_isa::semantics::VectorBinary;
|
||||
use xenora_isa::semantics::{FORM_IDS, OperandRule};
|
||||
|
||||
/// Metadata forms that [`decode`] turns into an [`Instruction`] for at least one
|
||||
/// operand combination: the hand-written forms below followed by every form of
|
||||
@@ -41,7 +40,7 @@ const fn concat_forms<const N: usize>() -> [(&'static str, EncodingFamily); N] {
|
||||
}
|
||||
|
||||
/// Decoded forms not yet described by the semantic registry.
|
||||
const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 23] = [
|
||||
const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 17] = [
|
||||
("BUFFER_LOAD_DWORD", EncodingFamily::Mubuf),
|
||||
("BUFFER_STORE_DWORD", EncodingFamily::Mubuf),
|
||||
("EXP", EncodingFamily::Exp),
|
||||
@@ -55,16 +54,10 @@ const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 23] = [
|
||||
("S_WAITCNT", EncodingFamily::Sopp),
|
||||
("S_WAITCNT_VSCNT", EncodingFamily::Sopk),
|
||||
("V_ADD_F32", EncodingFamily::Vop2),
|
||||
("V_AND_B32", EncodingFamily::Vop2),
|
||||
("V_ASHRREV_I32", EncodingFamily::Vop2),
|
||||
("V_INTERP_P1_F32", EncodingFamily::Vintrp),
|
||||
("V_INTERP_P2_F32", EncodingFamily::Vintrp),
|
||||
("V_LSHLREV_B32", EncodingFamily::Vop2),
|
||||
("V_LSHRREV_B32", EncodingFamily::Vop2),
|
||||
("V_MOV_B32", EncodingFamily::Vop1),
|
||||
("V_MUL_F32", EncodingFamily::Vop2),
|
||||
("V_OR_B32", EncodingFamily::Vop2),
|
||||
("V_XOR_B32", EncodingFamily::Vop2),
|
||||
];
|
||||
|
||||
/// A successfully decoded instruction and its location in the input stream.
|
||||
@@ -401,7 +394,14 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
// VOP2: SRC0 in bits 0-8, VSRC1 in bits 9-16, VDST in bits 17-24.
|
||||
let dst = ((first >> 17) & 0xff) as u8;
|
||||
let src1 = ((first >> 9) & 0xff) as u8;
|
||||
let (src0, len) = vector_src0(first, bytes, op.assembly_name())?;
|
||||
let (src0, len) = match op.operand_rule() {
|
||||
// Operand rule `vop2_vgpr2`: SRC0 must select a VGPR (256-511).
|
||||
OperandRule::Vop2Vgpr2 => {
|
||||
let (_, src0, _) = vop2_registers(first, op.assembly_name())?;
|
||||
(VectorSource::Register(src0), 4)
|
||||
}
|
||||
_ => vector_src0(first, bytes, op.assembly_name())?,
|
||||
};
|
||||
return Ok((
|
||||
Instruction::VectorAlu {
|
||||
op,
|
||||
@@ -412,48 +412,6 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
len,
|
||||
));
|
||||
}
|
||||
if V_LSHLREV_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_lshlrev_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 },
|
||||
V_LSHLREV_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_ASHRREV_I32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_ashrrev_i32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 },
|
||||
V_ASHRREV_I32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_LSHRREV_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_lshrrev_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 },
|
||||
V_LSHRREV_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_AND_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_and_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorAndB32 { dst, src0, src1 },
|
||||
V_AND_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_OR_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_or_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorOrB32 { dst, src0, src1 },
|
||||
V_OR_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_XOR_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_xor_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorXorB32 { dst, src0, src1 },
|
||||
V_XOR_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_ADD_F32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_add_f32_e32")?;
|
||||
return Ok((
|
||||
|
||||
@@ -432,22 +432,32 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
target,
|
||||
condition: BranchCondition::Always,
|
||||
},
|
||||
Instruction::VectorAndB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::And, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ShiftLeft, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ArithmeticShiftRight, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ShiftRight, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorOrB32 { dst, src0, src1 } => Op::Vector(VectorAlu::Or, dst, src0, src1),
|
||||
Instruction::VectorXorB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::Xor, dst, src0, src1)
|
||||
}
|
||||
// The six logical and shift forms migrated from hand-written code
|
||||
// (#215 M27) keep the reference's VGPR-only VectorAlu ops.
|
||||
Instruction::VectorAlu {
|
||||
op:
|
||||
op @ (VectorAluOp::AndB32
|
||||
| VectorAluOp::OrB32
|
||||
| VectorAluOp::XorB32
|
||||
| VectorAluOp::LshlrevB32
|
||||
| VectorAluOp::LshrrevB32
|
||||
| VectorAluOp::AshrrevI32),
|
||||
dst,
|
||||
src0: VectorSource::Register(src0),
|
||||
src1,
|
||||
} => Op::Vector(
|
||||
match op {
|
||||
VectorAluOp::AndB32 => VectorAlu::And,
|
||||
VectorAluOp::OrB32 => VectorAlu::Or,
|
||||
VectorAluOp::XorB32 => VectorAlu::Xor,
|
||||
VectorAluOp::LshlrevB32 => VectorAlu::ShiftLeft,
|
||||
VectorAluOp::LshrrevB32 => VectorAlu::ShiftRight,
|
||||
_ => VectorAlu::ArithmeticShiftRight,
|
||||
},
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
),
|
||||
Instruction::VectorAddF32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::FloatAdd, dst, src0, src1)
|
||||
}
|
||||
@@ -500,6 +510,7 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
VectorAluOp::AddNcU32 => VectorInteger::Add,
|
||||
VectorAluOp::SubNcU32 => VectorInteger::Subtract,
|
||||
VectorAluOp::SubrevNcU32 => VectorInteger::SubtractReverse,
|
||||
_ => panic!("{op:?} decodes only with a VGPR SRC0 (operand rule vop2_vgpr2)"),
|
||||
},
|
||||
dst,
|
||||
match src0 {
|
||||
|
||||
@@ -222,6 +222,12 @@ VECTOR_PRIMITIVES = {
|
||||
("mul24", "unsigned"): "Mul24Unsigned",
|
||||
("mul_hi24", "signed"): "MulHi24Signed",
|
||||
("mul_hi24", "unsigned"): "MulHi24Unsigned",
|
||||
("and", "bitwise"): "And",
|
||||
("or", "bitwise"): "Or",
|
||||
("xor", "bitwise"): "Xor",
|
||||
("lshl", "bitwise"): "ShiftLeft",
|
||||
("lshr", "bitwise"): "ShiftRight",
|
||||
("ashr", "signed"): "ArithmeticShiftRight",
|
||||
}
|
||||
|
||||
# Operand rules the decoder implements, each exactly once. A registry rule must
|
||||
@@ -346,6 +352,26 @@ OPERAND_RULES = {
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
"vop2_vgpr2": {
|
||||
"rust": "Vop2Vgpr2",
|
||||
"enum": "VectorAluOp",
|
||||
"shape": {
|
||||
"family": "VOP2",
|
||||
"dst": {"field": "VDST", "class": "vgpr", "min": 0, "max": 255},
|
||||
"src": [
|
||||
{"field": "SRC0", "class": "vgpr"},
|
||||
{"field": "VSRC1", "class": "vgpr"},
|
||||
],
|
||||
"max_literals": 0,
|
||||
},
|
||||
# The subset the hand-written decoder accepted before the registry (#215
|
||||
# M27): SRC0 must select a VGPR (256-511); the decoder rejects the rest.
|
||||
"unsupported": {
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal",
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
}
|
||||
|
||||
VARIANT = re.compile(r"^[A-Z][A-Za-z0-9]*$")
|
||||
@@ -546,7 +572,8 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
fields = [(rule["dst"]["field"], False)] if "dst" in rule else []
|
||||
fields += [(src["field"], True) for src in rule["src"]]
|
||||
shift = form["operation"] in CONTROL_S1 and len(rule["src"]) > 1
|
||||
count_field = rule["src"][1]["field"] if shift else None
|
||||
# The shift count is S1, or S0 for a form that reads its sources reversed.
|
||||
count_field = rule["src"][0 if SOURCE_ORDER_KEY in form else 1]["field"] if shift else None
|
||||
for field, is_source in fields:
|
||||
if field not in operands:
|
||||
errors.append(f"{label}: XML has no operand {field}")
|
||||
@@ -942,8 +969,15 @@ def render(registry, snapshot):
|
||||
"/// Registry schema of the generated tables.",
|
||||
f"pub const GENERATED_SCHEMA: u32 = {registry['schema']};",
|
||||
]
|
||||
# Rules that share a generated enum (VOP2 `vop2_vgpr` and `vop2_vgpr2`) render
|
||||
# it once, with the forms of all of them in registry order.
|
||||
rendered = set()
|
||||
for rule_name in rule_names:
|
||||
selected = [form for form in forms if form["operands"] == rule_name]
|
||||
enum = OPERAND_RULES[rule_name]["enum"]
|
||||
if enum in rendered:
|
||||
continue
|
||||
rendered.add(enum)
|
||||
selected = [form for form in forms if OPERAND_RULES[form["operands"]]["enum"] == enum]
|
||||
out += _render_enum(rule_name, selected, snapshot, positions)
|
||||
variants = registry.get("encoding_variant", [])
|
||||
variant_positions = {
|
||||
@@ -1093,6 +1127,9 @@ def _render_variants(rule_name, variants, registry, snapshot, positions):
|
||||
def _render_enum(rule_name, forms, snapshot, positions):
|
||||
enum = OPERAND_RULES[rule_name]["enum"]
|
||||
kind = OPERAND_RULES[rule_name]["kind"]
|
||||
rules = sorted({form["operands"] for form in forms})
|
||||
if any(OPERAND_RULES[name]["kind"] != kind for name in rules):
|
||||
raise ValueError(f"{enum}: operand rules {rules} of one enum differ in kind")
|
||||
table = re.sub(r"(?<!^)(?=[A-Z])", "_", enum).upper() + "_BY_OPCODE"
|
||||
family = forms[0]["family"]
|
||||
encoding = snapshot["encodings"][_family_encoding(family)]
|
||||
@@ -1109,7 +1146,8 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
raise ValueError(f"{family}: identifiers do not split into fixed bits and OP")
|
||||
out = [
|
||||
"",
|
||||
f"/// {family} operations declared in the semantic registry (operand rule `{rule_name}`).",
|
||||
f"/// {family} operations declared in the semantic registry (operand rule"
|
||||
f"{'s' if len(rules) > 1 else ''} {', '.join(f'`{name}`' for name in rules)}).",
|
||||
"#[derive(Clone, Copy, Debug, Eq, PartialEq)]",
|
||||
f"pub enum {enum} {{",
|
||||
]
|
||||
@@ -1241,6 +1279,18 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
f" Self::{form['variant']} => {'true' if SOURCE_ORDER_KEY in form else 'false'},"
|
||||
for form in forms
|
||||
]
|
||||
out += [
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /// The operand rule the decoder applies to the 32-bit encoding.",
|
||||
" pub const fn operand_rule(self) -> OperandRule {",
|
||||
" match self {",
|
||||
]
|
||||
out += [
|
||||
f" Self::{form['variant']} => OperandRule::{OPERAND_RULES[form['operands']]['rust']},"
|
||||
for form in forms
|
||||
]
|
||||
out += [" }", " }", "}"]
|
||||
return out
|
||||
if kind == "vector_compare":
|
||||
|
||||
@@ -223,3 +223,128 @@ wave = "any"
|
||||
operands = "vop2_vgpr"
|
||||
spec = [{ document = "guide", section = "12.7", page = 134 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
# ---- VOP2 logical and shift forms migrated from hand-written code (#215 M27) ----
|
||||
# Per lane under EXEC; no SCC, VCC or EXEC write (guide 12.7). The shifts read
|
||||
# their sources reversed: D = S1 shifted by S0[4:0]; ASHRREV fills with S1's sign.
|
||||
# These keep the subset the hand-written decoder accepted: both sources VGPRs.
|
||||
[operand_rules.vop2_vgpr2]
|
||||
family = "VOP2"
|
||||
dst = { field = "VDST", class = "vgpr", min = 0, max = 255 }
|
||||
src = [
|
||||
{ field = "SRC0", class = "vgpr" },
|
||||
{ field = "VSRC1", class = "vgpr" },
|
||||
]
|
||||
max_literals = 0
|
||||
unsupported = [
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal",
|
||||
]
|
||||
|
||||
[[form]]
|
||||
name = "V_LSHRREV_B32"
|
||||
family = "VOP2"
|
||||
opcode = 22
|
||||
variant = "LshrrevB32"
|
||||
operation = "lshr"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_ASHRREV_I32"
|
||||
family = "VOP2"
|
||||
opcode = 24
|
||||
variant = "AshrrevI32"
|
||||
operation = "ashr"
|
||||
signedness = "signed"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_LSHLREV_B32"
|
||||
family = "VOP2"
|
||||
opcode = 26
|
||||
variant = "LshlrevB32"
|
||||
operation = "lshl"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_AND_B32"
|
||||
family = "VOP2"
|
||||
opcode = 27
|
||||
variant = "AndB32"
|
||||
operation = "and"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_OR_B32"
|
||||
family = "VOP2"
|
||||
opcode = 28
|
||||
variant = "OrB32"
|
||||
operation = "or"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_XOR_B32"
|
||||
family = "VOP2"
|
||||
opcode = 29
|
||||
variant = "XorB32"
|
||||
operation = "xor"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
@@ -209,18 +209,6 @@ pub enum Instruction {
|
||||
BranchVccZero { target: usize },
|
||||
/// SOPP unconditional jump to a stream byte offset.
|
||||
Branch { target: usize },
|
||||
/// VOP2 logical left shift with the count in src0.
|
||||
VectorLshlrevB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 logical right shift with the count in src0.
|
||||
VectorLshrrevB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 arithmetic right shift with the count in src0.
|
||||
VectorAshrrevI32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise AND.
|
||||
VectorAndB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise OR.
|
||||
VectorOrB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise XOR.
|
||||
VectorXorB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 single-precision addition. Execution requires an explicit FP mode.
|
||||
VectorAddF32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 single-precision multiplication. Execution requires an explicit FP mode.
|
||||
@@ -288,12 +276,6 @@ impl Instruction {
|
||||
Self::BranchExecZero { .. } => "s_cbranch_execz",
|
||||
Self::BranchVccZero { .. } => "s_cbranch_vccz",
|
||||
Self::Branch { .. } => "s_branch",
|
||||
Self::VectorLshlrevB32 { .. } => "v_lshlrev_b32_e32",
|
||||
Self::VectorLshrrevB32 { .. } => "v_lshrrev_b32_e32",
|
||||
Self::VectorAshrrevI32 { .. } => "v_ashrrev_i32_e32",
|
||||
Self::VectorAndB32 { .. } => "v_and_b32_e32",
|
||||
Self::VectorOrB32 { .. } => "v_or_b32_e32",
|
||||
Self::VectorXorB32 { .. } => "v_xor_b32_e32",
|
||||
Self::VectorAddF32 { .. } => "v_add_f32_e32",
|
||||
Self::VectorMulF32 { .. } => "v_mul_f32_e32",
|
||||
Self::Export { .. } => "exp",
|
||||
@@ -337,12 +319,6 @@ impl fmt::Display for Instruction {
|
||||
Self::VectorAluVop3 {
|
||||
dst, src0, src1, ..
|
||||
}
|
||||
| Self::VectorLshlrevB32 { dst, src0, src1 }
|
||||
| Self::VectorLshrrevB32 { dst, src0, src1 }
|
||||
| Self::VectorAshrrevI32 { dst, src0, src1 }
|
||||
| Self::VectorAndB32 { dst, src0, src1 }
|
||||
| Self::VectorOrB32 { dst, src0, src1 }
|
||||
| Self::VectorXorB32 { dst, src0, src1 }
|
||||
| Self::VectorAddF32 { dst, src0, src1 }
|
||||
| Self::VectorMulF32 { dst, src0, src1 } => {
|
||||
write!(formatter, " v{dst}, v{src0}, v{src1}")
|
||||
|
||||
@@ -119,6 +119,18 @@ pub enum VectorBinary {
|
||||
MulHi24Signed,
|
||||
/// Bits 63:32 of `a[23:0] * b[23:0]`.
|
||||
MulHi24Unsigned,
|
||||
/// `a & b`.
|
||||
And,
|
||||
/// `a | b`.
|
||||
Or,
|
||||
/// `a ^ b`.
|
||||
Xor,
|
||||
/// `a << (b & 31)`.
|
||||
ShiftLeft,
|
||||
/// Logical `a >> (b & 31)`.
|
||||
ShiftRight,
|
||||
/// Arithmetic (sign-filling) `a >> (b & 31)`.
|
||||
ArithmeticShiftRight,
|
||||
}
|
||||
|
||||
/// How the operands are interpreted. `Bitwise` exactly when the operation is logical.
|
||||
@@ -204,6 +216,9 @@ pub enum OperandRule {
|
||||
/// integer -16..64 or a literal word; VSRC1 is a VGPR. Everything else is
|
||||
/// rejected as unsupported.
|
||||
Vop2Vgpr,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// Evidence a form needs before it counts as verified.
|
||||
|
||||
+231
-27
@@ -1198,7 +1198,7 @@ impl ScalarCompareOp {
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP2 operations declared in the semantic registry (operand rule `vop2_vgpr`).
|
||||
/// VOP2 operations declared in the semantic registry (operand rules `vop2_vgpr`, `vop2_vgpr2`).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorAluOp {
|
||||
/// `v_mul_i32_i24` (VOP2 opcode 9): signed mul24, SCC = unchanged.
|
||||
@@ -1225,6 +1225,18 @@ pub enum VectorAluOp {
|
||||
SubNcU32,
|
||||
/// `v_subrev_nc_u32` (VOP2 opcode 39): unsigned sub, SCC = unchanged.
|
||||
SubrevNcU32,
|
||||
/// `v_lshrrev_b32` (VOP2 opcode 22): bitwise lshr, SCC = unchanged.
|
||||
LshrrevB32,
|
||||
/// `v_ashrrev_i32` (VOP2 opcode 24): signed ashr, SCC = unchanged.
|
||||
AshrrevI32,
|
||||
/// `v_lshlrev_b32` (VOP2 opcode 26): bitwise lshl, SCC = unchanged.
|
||||
LshlrevB32,
|
||||
/// `v_and_b32` (VOP2 opcode 27): bitwise and, SCC = unchanged.
|
||||
AndB32,
|
||||
/// `v_or_b32` (VOP2 opcode 28): bitwise or, SCC = unchanged.
|
||||
OrB32,
|
||||
/// `v_xor_b32` (VOP2 opcode 29): bitwise xor, SCC = unchanged.
|
||||
XorB32,
|
||||
}
|
||||
|
||||
/// VectorAluOp by VOP2 OP field value; `None` for undeclared opcodes.
|
||||
@@ -1251,14 +1263,14 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
Some(VectorAluOp::MinU32),
|
||||
Some(VectorAluOp::MaxU32),
|
||||
None,
|
||||
Some(VectorAluOp::LshrrevB32),
|
||||
None,
|
||||
Some(VectorAluOp::AshrrevI32),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(VectorAluOp::LshlrevB32),
|
||||
Some(VectorAluOp::AndB32),
|
||||
Some(VectorAluOp::OrB32),
|
||||
Some(VectorAluOp::XorB32),
|
||||
Some(VectorAluOp::XnorB32),
|
||||
None,
|
||||
None,
|
||||
@@ -1297,7 +1309,7 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
|
||||
impl VectorAluOp {
|
||||
/// Every operation, in registry order.
|
||||
pub const ALL: [Self; 12] = [
|
||||
pub const ALL: [Self; 18] = [
|
||||
Self::MulI32I24,
|
||||
Self::MulHiI32I24,
|
||||
Self::MulU32U24,
|
||||
@@ -1310,6 +1322,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32,
|
||||
Self::SubNcU32,
|
||||
Self::SubrevNcU32,
|
||||
Self::LshrrevB32,
|
||||
Self::AshrrevI32,
|
||||
Self::LshlrevB32,
|
||||
Self::AndB32,
|
||||
Self::OrB32,
|
||||
Self::XorB32,
|
||||
];
|
||||
|
||||
/// Selects the operation from a first instruction word: the VOP2 encoding
|
||||
@@ -1336,6 +1354,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => "v_add_nc_u32",
|
||||
Self::SubNcU32 => "v_sub_nc_u32",
|
||||
Self::SubrevNcU32 => "v_subrev_nc_u32",
|
||||
Self::LshrrevB32 => "v_lshrrev_b32",
|
||||
Self::AshrrevI32 => "v_ashrrev_i32",
|
||||
Self::LshlrevB32 => "v_lshlrev_b32",
|
||||
Self::AndB32 => "v_and_b32",
|
||||
Self::OrB32 => "v_or_b32",
|
||||
Self::XorB32 => "v_xor_b32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1354,6 +1378,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => 65,
|
||||
Self::SubNcU32 => 66,
|
||||
Self::SubrevNcU32 => 67,
|
||||
Self::LshrrevB32 => 68,
|
||||
Self::AshrrevI32 => 69,
|
||||
Self::LshlrevB32 => 70,
|
||||
Self::AndB32 => 71,
|
||||
Self::OrB32 => 72,
|
||||
Self::XorB32 => 73,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1372,6 +1402,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => "v_add_nc_u32_e32",
|
||||
Self::SubNcU32 => "v_sub_nc_u32_e32",
|
||||
Self::SubrevNcU32 => "v_subrev_nc_u32_e32",
|
||||
Self::LshrrevB32 => "v_lshrrev_b32_e32",
|
||||
Self::AshrrevI32 => "v_ashrrev_i32_e32",
|
||||
Self::LshlrevB32 => "v_lshlrev_b32_e32",
|
||||
Self::AndB32 => "v_and_b32_e32",
|
||||
Self::OrB32 => "v_or_b32_e32",
|
||||
Self::XorB32 => "v_xor_b32_e32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1390,6 +1426,12 @@ impl VectorAluOp {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1408,6 +1450,36 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => false,
|
||||
Self::SubNcU32 => false,
|
||||
Self::SubrevNcU32 => true,
|
||||
Self::LshrrevB32 => true,
|
||||
Self::AshrrevI32 => true,
|
||||
Self::LshlrevB32 => true,
|
||||
Self::AndB32 => false,
|
||||
Self::OrB32 => false,
|
||||
Self::XorB32 => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The operand rule the decoder applies to the 32-bit encoding.
|
||||
pub const fn operand_rule(self) -> OperandRule {
|
||||
match self {
|
||||
Self::MulI32I24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulHiI32I24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulU32U24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulHiU32U24 => OperandRule::Vop2Vgpr,
|
||||
Self::MinI32 => OperandRule::Vop2Vgpr,
|
||||
Self::MaxI32 => OperandRule::Vop2Vgpr,
|
||||
Self::MinU32 => OperandRule::Vop2Vgpr,
|
||||
Self::MaxU32 => OperandRule::Vop2Vgpr,
|
||||
Self::XnorB32 => OperandRule::Vop2Vgpr,
|
||||
Self::AddNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::SubNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::SubrevNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::LshrrevB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::AshrrevI32 => OperandRule::Vop2Vgpr2,
|
||||
Self::LshlrevB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::AndB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::OrB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::XorB32 => OperandRule::Vop2Vgpr2,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1764,22 +1836,22 @@ impl VectorCompareOp {
|
||||
/// The validated registry row.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::CmpLtI32 => 68,
|
||||
Self::CmpEqI32 => 69,
|
||||
Self::CmpLeI32 => 70,
|
||||
Self::CmpGtI32 => 71,
|
||||
Self::CmpNeI32 => 72,
|
||||
Self::CmpGeI32 => 73,
|
||||
Self::CmpLtU32 => 74,
|
||||
Self::CmpEqU32 => 75,
|
||||
Self::CmpLeU32 => 76,
|
||||
Self::CmpGtU32 => 77,
|
||||
Self::CmpNeU32 => 78,
|
||||
Self::CmpGeU32 => 79,
|
||||
Self::CmpFI32 => 80,
|
||||
Self::CmpTI32 => 81,
|
||||
Self::CmpFU32 => 82,
|
||||
Self::CmpTU32 => 83,
|
||||
Self::CmpLtI32 => 74,
|
||||
Self::CmpEqI32 => 75,
|
||||
Self::CmpLeI32 => 76,
|
||||
Self::CmpGtI32 => 77,
|
||||
Self::CmpNeI32 => 78,
|
||||
Self::CmpGeI32 => 79,
|
||||
Self::CmpLtU32 => 80,
|
||||
Self::CmpEqU32 => 81,
|
||||
Self::CmpLeU32 => 82,
|
||||
Self::CmpGtU32 => 83,
|
||||
Self::CmpNeU32 => 84,
|
||||
Self::CmpGeU32 => 85,
|
||||
Self::CmpFI32 => 86,
|
||||
Self::CmpTI32 => 87,
|
||||
Self::CmpFU32 => 88,
|
||||
Self::CmpTU32 => 89,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1915,13 +1987,13 @@ impl VectorAluVop3Op {
|
||||
/// The validated registry row of this encoding.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::AddNcU32 => 84,
|
||||
Self::AddNcU32 => 90,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity of every registry form and encoding variant, in registry order.
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 91] = [
|
||||
("S_ADD_U32", EncodingFamily::Sop2),
|
||||
("S_SUB_U32", EncodingFamily::Sop2),
|
||||
("S_ADD_I32", EncodingFamily::Sop2),
|
||||
@@ -1990,6 +2062,12 @@ pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
("V_ADD_NC_U32", EncodingFamily::Vop2),
|
||||
("V_SUB_NC_U32", EncodingFamily::Vop2),
|
||||
("V_SUBREV_NC_U32", EncodingFamily::Vop2),
|
||||
("V_LSHRREV_B32", EncodingFamily::Vop2),
|
||||
("V_ASHRREV_I32", EncodingFamily::Vop2),
|
||||
("V_LSHLREV_B32", EncodingFamily::Vop2),
|
||||
("V_AND_B32", EncodingFamily::Vop2),
|
||||
("V_OR_B32", EncodingFamily::Vop2),
|
||||
("V_XOR_B32", EncodingFamily::Vop2),
|
||||
("V_CMP_LT_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_EQ_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_LE_I32", EncodingFamily::Vopc),
|
||||
@@ -2010,7 +2088,7 @@ pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
];
|
||||
|
||||
/// One validated row per registry form, in registry order.
|
||||
pub static FORMS: [FormSemantics; 85] = [
|
||||
pub static FORMS: [FormSemantics; 91] = [
|
||||
FormSemantics {
|
||||
name: "S_ADD_U32",
|
||||
family: EncodingFamily::Sop2,
|
||||
@@ -3439,6 +3517,132 @@ pub static FORMS: [FormSemantics; 85] = [
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_LSHRREV_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 22,
|
||||
operation: Operation::LogicalShiftRight,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_ASHRREV_I32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 24,
|
||||
operation: Operation::ArithmeticShiftRight,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_LSHLREV_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 26,
|
||||
operation: Operation::ShiftLeft,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_AND_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 27,
|
||||
operation: Operation::And,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
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::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_OR_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 28,
|
||||
operation: Operation::Or,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
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::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_XOR_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 29,
|
||||
operation: Operation::Xor,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
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::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LT_I32",
|
||||
family: EncodingFamily::Vopc,
|
||||
|
||||
@@ -102,8 +102,8 @@ fn vector_alu_dispatch_selects_exactly_the_registry_vop2_forms() {
|
||||
assert_eq!(op.swaps_sources(), row.swap_sources);
|
||||
assert_eq!(row.scc, SccEffect::Unchanged);
|
||||
}
|
||||
// The hand-written VOP2 forms (v_and_b32, v_add_f32, ...) must not be
|
||||
// dispatched here.
|
||||
// Exactly the registry VOP2 forms are dispatched here; the hand-written
|
||||
// ones (v_add_f32, v_mul_f32) must not be.
|
||||
dispatch_selects_exactly(EncodingFamily::Vop2, |word| {
|
||||
VectorAluOp::from_word(word).map(|op| op.semantics().name)
|
||||
});
|
||||
|
||||
+34
-58
@@ -9,8 +9,8 @@ pub use graphics::{PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics};
|
||||
|
||||
pub use xenora_decoder::Architecture;
|
||||
use xenora_decoder::{
|
||||
DecodeError, DecodedInstruction, Instruction, ScalarSource, VectorAluVop3Op, VectorBinary,
|
||||
VectorCompareOp, VectorSource,
|
||||
DecodeError, DecodedInstruction, Instruction, ScalarSource, VectorAluOp, VectorAluVop3Op,
|
||||
VectorBinary, VectorCompareOp, VectorSource,
|
||||
};
|
||||
|
||||
/// SGPR index of `vcc_lo`.
|
||||
@@ -156,14 +156,7 @@ impl Op {
|
||||
Binary::FloatAdd | Binary::FloatMul => format!(
|
||||
"as_type<uint>(as_type<float>({left}) {symbol} as_type<float>({right}))"
|
||||
),
|
||||
Binary::ArithmeticShiftRight => {
|
||||
format!("as_type<uint>(as_type<int>({left}) {symbol} ({right} & 31u))")
|
||||
}
|
||||
Binary::ShiftLeft | Binary::ShiftRight => {
|
||||
format!("{left} {symbol} ({right} & 31u)")
|
||||
}
|
||||
Binary::Vector(operation) => vector_expression(operation, &left, &right),
|
||||
_ => format!("{left} {symbol} {right}"),
|
||||
}
|
||||
}
|
||||
Self::MergeLanes {
|
||||
@@ -215,12 +208,6 @@ fn compare_expression(op: VectorCompareOp, left: &str, right: &str) -> String {
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Binary {
|
||||
ShiftLeft,
|
||||
ShiftRight,
|
||||
ArithmeticShiftRight,
|
||||
And,
|
||||
Or,
|
||||
Xor,
|
||||
FloatAdd,
|
||||
FloatMul,
|
||||
/// A registry VOP2 integer operation (or its VOP3 encoding), lowered by its
|
||||
@@ -231,12 +218,6 @@ enum Binary {
|
||||
impl Binary {
|
||||
fn operator(self) -> (&'static str, &'static str) {
|
||||
match self {
|
||||
Self::ShiftLeft => ("lshl.b32", "<<"),
|
||||
Self::ShiftRight => ("lshr.b32", ">>"),
|
||||
Self::ArithmeticShiftRight => ("ashr.i32", ">>"),
|
||||
Self::And => ("and.b32", "&"),
|
||||
Self::Or => ("or.b32", "|"),
|
||||
Self::Xor => ("xor.b32", "^"),
|
||||
Self::FloatAdd => ("add.f32", "+"),
|
||||
Self::FloatMul => ("mul.f32", "*"),
|
||||
Self::Vector(operation) => (
|
||||
@@ -252,6 +233,12 @@ impl Binary {
|
||||
VectorBinary::Mul24Unsigned => "mul24.u32",
|
||||
VectorBinary::MulHi24Signed => "mulhi24.i32",
|
||||
VectorBinary::MulHi24Unsigned => "mulhi24.u32",
|
||||
VectorBinary::And => "and.b32",
|
||||
VectorBinary::Or => "or.b32",
|
||||
VectorBinary::Xor => "xor.b32",
|
||||
VectorBinary::ShiftLeft => "lshl.b32",
|
||||
VectorBinary::ShiftRight => "lshr.b32",
|
||||
VectorBinary::ArithmeticShiftRight => "ashr.i32",
|
||||
},
|
||||
"",
|
||||
),
|
||||
@@ -286,6 +273,15 @@ fn vector_expression(operation: VectorBinary, left: &str, right: &str) -> String
|
||||
format!("as_type<uint>(mulhi({}, {}))", i24(left), i24(right))
|
||||
}
|
||||
VectorBinary::MulHi24Unsigned => format!("mulhi({}, {})", u24(left), u24(right)),
|
||||
VectorBinary::And => format!("{left} & {right}"),
|
||||
VectorBinary::Or => format!("{left} | {right}"),
|
||||
VectorBinary::Xor => format!("{left} ^ {right}"),
|
||||
// MSL leaves shifts by 32 or more undefined; the guide reads S0[4:0].
|
||||
VectorBinary::ShiftLeft => format!("{left} << ({right} & 31u)"),
|
||||
VectorBinary::ShiftRight => format!("{left} >> ({right} & 31u)"),
|
||||
VectorBinary::ArithmeticShiftRight => {
|
||||
format!("as_type<uint>(as_type<int>({left}) >> ({right} & 31u))")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,15 +685,22 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
dst,
|
||||
..
|
||||
}
|
||||
| Instruction::VectorLshlrevB32 { dst, .. }
|
||||
| Instruction::VectorLshrrevB32 { dst, .. }
|
||||
| Instruction::VectorAshrrevI32 { dst, .. }
|
||||
| Instruction::VectorAndB32 { dst, .. }
|
||||
| Instruction::VectorOrB32 { dst, .. }
|
||||
| Instruction::VectorXorB32 { dst, .. } => dst,
|
||||
// Of the registry VOP2 forms, the contract admits only the six
|
||||
// logical and shift forms that were hand-written before (#215 M27).
|
||||
| Instruction::VectorAlu {
|
||||
op:
|
||||
VectorAluOp::LshlrevB32
|
||||
| VectorAluOp::LshrrevB32
|
||||
| VectorAluOp::AshrrevI32
|
||||
| VectorAluOp::AndB32
|
||||
| VectorAluOp::OrB32
|
||||
| VectorAluOp::XorB32,
|
||||
dst,
|
||||
..
|
||||
} => dst,
|
||||
_ => {
|
||||
return Err(error(
|
||||
"code skipped by a runtime s_cbranch_vccz may contain only v_mov_b32, v_add_nc_u32_e64 and the hand-written integer VOP2 forms",
|
||||
"code skipped by a runtime s_cbranch_vccz may contain only v_mov_b32, v_add_nc_u32_e64 and the VOP2 logical and shift forms",
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -728,12 +731,6 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
match instruction.instruction {
|
||||
Instruction::MoveB32 { .. }
|
||||
| Instruction::VectorAluVop3 { .. }
|
||||
| Instruction::VectorLshlrevB32 { .. }
|
||||
| Instruction::VectorLshrrevB32 { .. }
|
||||
| Instruction::VectorAshrrevI32 { .. }
|
||||
| Instruction::VectorAndB32 { .. }
|
||||
| Instruction::VectorOrB32 { .. }
|
||||
| Instruction::VectorXorB32 { .. }
|
||||
| Instruction::VectorAddF32 { .. }
|
||||
| Instruction::VectorMulF32 { .. }
|
||||
| Instruction::VectorAlu { .. } => continue,
|
||||
@@ -851,27 +848,6 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
Op::Binary(Binary::Vector(op.lowering()), left, right),
|
||||
)
|
||||
}
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ShiftLeft, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ArithmeticShiftRight, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ShiftRight, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorAndB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::And, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::VectorOrB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::Or, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::VectorXorB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::Xor, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::ScalarMoveB32 { dst, src } => {
|
||||
let value = read_scalar(src)?;
|
||||
if dst < 8 {
|
||||
@@ -1084,9 +1060,9 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
};
|
||||
let value_bits = match operation {
|
||||
Op::Constant(bits) => KnownBits::constant(bits),
|
||||
Op::Binary(Binary::And, left, right) => facts[left.0].and(facts[right.0]),
|
||||
Op::Binary(Binary::Or, left, right) => facts[left.0].or(facts[right.0]),
|
||||
Op::Binary(Binary::Xor, left, right) => facts[left.0].xor(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::And), left, right) => facts[left.0].and(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::Or), left, right) => facts[left.0].or(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::Xor), left, right) => facts[left.0].xor(facts[right.0]),
|
||||
Op::Binary(operator @ (Binary::FloatAdd | Binary::FloatMul), left, right) => {
|
||||
exact_float_result(operator, facts[left.0], facts[right.0])
|
||||
.ok_or_else(|| error("FP32 operation is not proven exact for positive normal operands and results"))?
|
||||
|
||||
@@ -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 | 12 | 20 | 20 | 20 | 7 | 7 | 7 |
|
||||
| VOP2 | 47 | 20 | 18 | 20 | 20 | 20 | 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 | 104 | 85 | 108 | 104 | 104 | 18 | 18 | 56 |
|
||||
| **Total** | 1465 | 104 | 91 | 108 | 104 | 104 | 18 | 18 | 60 |
|
||||
|
||||
## Unsupported operand variants
|
||||
|
||||
@@ -48,5 +48,6 @@ The table counts distinct variant names per family across registry operand rules
|
||||
| SOP2 | `sop2_sgpr` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc`, `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` |
|
||||
| SOPC | `sopc_scalar` | `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` |
|
||||
| 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` |
|
||||
| VOPC | `vopc_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
@@ -90,12 +90,13 @@ The root file holds:
|
||||
`guide` (the AMD RDNA 2 ISA reference guide) and `xml` (the AMD
|
||||
machine-readable ISA) are allowed, and each must match the title and file
|
||||
pinned in the generator, so a citation cannot point at another file.
|
||||
- `[operand_rules.<name>]`: an operand rule shared by a whole family. The
|
||||
decoder implements each rule once, and the generator only accepts a rule
|
||||
whose declaration matches the decoder's implementation exactly. Today there
|
||||
is one rule, `sop2_sgpr`: an SGPR destination `s0`-`s105`, two scalar sources
|
||||
- `[operand_rules.<name>]`: an operand rule of one family, shared by its forms.
|
||||
The decoder implements each rule once, and the generator only accepts a rule
|
||||
whose declaration matches the decoder's implementation exactly. A family may
|
||||
have several rules (VOP2 has `vop2_vgpr` and the VGPR-only `vop2_vgpr2`). For
|
||||
example `sop2_sgpr` is an SGPR destination `s0`-`s105`, two scalar sources
|
||||
(an SGPR, an inline integer -16 to 64, or a literal word) and at most one
|
||||
literal. Its `unsupported` list names the encodings the rule rejects, which
|
||||
literal. A rule's `unsupported` list names the encodings it rejects, which
|
||||
stay unsupported instead of being guessed. The list must name exactly the
|
||||
encodings the decoder rejects.
|
||||
|
||||
@@ -116,7 +117,7 @@ error.
|
||||
| `relation` | Compares only: the relation tested with S0 on the left | `eq`, `lg` (not equal), `gt`, `ge`, `lt`, `le`; required for `compare`, rejected elsewhere |
|
||||
| `source_order` | Vector forms only: `reversed` when the guide computes `op(S1, S0)` (the XML records no operand order); absent otherwise | `reversed` |
|
||||
| `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 S1 used as the count. The generator masks S1 with it, and the XML must list S1 as unsigned | `5` (log2 of `width`); required for shifts, 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 compares only), `selected_src0` (min and max: S0 won the strict compare, so a tie gives 0), `unchanged` |
|
||||
| `vcc`, `exec` | Effect on VCC and EXEC, stated rather than implied | `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` (no EXEC-writing contract yet) |
|
||||
| `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` |
|
||||
@@ -151,7 +152,9 @@ fixes the `scc` value:
|
||||
| `lshl_add` / `unsigned` | `carry_out` | `lshl_add_carry_u32` (with `shift_amount`) | no |
|
||||
| `compare` / `signed` or `unsigned` | `relation` | `eq_b32`, `ne_b32` (for both signednesses), `gt_i32`/`gt_u32`, `ge_*`, `lt_*`, `le_*` | no |
|
||||
|
||||
Vector forms (operand rule `vop2_vgpr`, kind `vector`) use a separate table:
|
||||
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):
|
||||
|
||||
@@ -161,6 +164,15 @@ must be `unchanged` (VOP2 integer forms write no SCC, VCC or EXEC):
|
||||
| `xnor` / `bitwise` | `Xnor` |
|
||||
| `min`, `max` / `signed` or `unsigned` | `MinSigned`, `MinUnsigned`, `MaxSigned`, `MaxUnsigned` |
|
||||
| `mul24`, `mul_hi24` / `signed` or `unsigned` | `Mul24Signed`, `Mul24Unsigned`, `MulHi24Signed`, `MulHi24Unsigned` |
|
||||
| `and`, `or`, `xor` / `bitwise` | `And`, `Or`, `Xor` |
|
||||
| `lshl`, `lshr` / `bitwise`, `ashr` / `signed` (with `shift_count_bits = 5`) | `ShiftLeft`, `ShiftRight`, `ArithmeticShiftRight` |
|
||||
|
||||
`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
|
||||
to `vop2_vgpr` would be a behaviour change and needs its own oracle. The three
|
||||
shifts declare `source_order = "reversed"` (D = S1 shifted by S0[4:0]), so the
|
||||
generator checks the XML's unsigned count format on SRC0, not VSRC1.
|
||||
|
||||
VOPC compares (operand rule `vopc_vcc`, kind `vector_compare`: SRC0 a
|
||||
`vector_source` as for VOP2, VSRC1 a VGPR, destination implicitly `vcc_lo`)
|
||||
|
||||
@@ -371,6 +371,25 @@ class Validate(unittest.TestCase):
|
||||
def test_accepts_the_real_registry(self):
|
||||
self.assertEqual(gen.validate(gen.load_registry(), gen.load_snapshot()), [])
|
||||
|
||||
def test_a_reversed_shift_takes_its_count_from_src0(self):
|
||||
# V_ASHRREV_I32: D = S1 >> S0[4:0]; the XML gives SRC0 FMT_NUM_U32 (the
|
||||
# count) and VSRC1 FMT_NUM_I32. Without the declared reversed order the
|
||||
# count check lands on VSRC1 and must fail.
|
||||
reg = gen.load_registry()
|
||||
form = next(f for f in reg["form"] if f["name"] == "V_ASHRREV_I32")
|
||||
del form["source_order"]
|
||||
errors = gen.validate(reg, gen.load_snapshot())
|
||||
self.assertIn(
|
||||
"V_ASHRREV_I32: control operand VSRC1 has XML format FMT_NUM_I32, not FMT_NUM_U32",
|
||||
errors,
|
||||
)
|
||||
|
||||
def test_rules_sharing_an_enum_render_it_once_with_each_forms_rule(self):
|
||||
text = gen.render(gen.load_registry(), gen.load_snapshot())
|
||||
self.assertEqual(text.count("pub enum VectorAluOp {"), 1)
|
||||
self.assertIn("Self::AndB32 => OperandRule::Vop2Vgpr2,", text)
|
||||
self.assertIn("Self::MinI32 => OperandRule::Vop2Vgpr,", text)
|
||||
|
||||
# ---- top level ----
|
||||
|
||||
def test_rejects_wrong_schema(self):
|
||||
|
||||
Reference in new issue
Block a user