mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
isa: declare eight more SOP2 logical and shift forms in the registry (#215 stage C, WIP)
Adds andn2, orn2, nand, nor, xnor, lshl, lshr and ashr as registry primitives with a declared shift-count width that the generator applies as a mask and checks against the XML's unsigned count operand. The forms reach the decoder and translator through the generated dispatch with no per-form Rust. The independent oracle side lands separately. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
1 parent
f856671b6d
commit
ff191d89bd
20 files changed
+754
-26
No files matched your search
@@ -434,13 +434,14 @@ fn compares_fixture_instructions_against_llvm() {
|
||||
SHIFT_FIXTURE,
|
||||
include_bytes!("../../../fixtures/rdna2/ashr.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/scalar-alu.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/scalar-logic.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-compare.bin"),
|
||||
high_registers,
|
||||
&matrix,
|
||||
] {
|
||||
count += compare_against_llvm(fixture, &mut forms);
|
||||
}
|
||||
assert_eq!(forms.len(), 42, "forms compared: {forms:?}");
|
||||
assert_eq!(forms.len(), 50, "forms compared: {forms:?}");
|
||||
eprintln!(
|
||||
"{count} three-way instruction comparisons across {} forms",
|
||||
forms.len()
|
||||
|
||||
@@ -38,8 +38,18 @@ FORM_KEYS = {
|
||||
}
|
||||
TOP_KEYS = {"schema", "architecture", "source_sha256", "documents", "operand_rules", "form"}
|
||||
|
||||
OPERATIONS = {"add": "Add", "sub": "Sub", "and": "And", "or": "Or", "xor": "Xor"}
|
||||
LOGICAL = {"and", "or", "xor"}
|
||||
OPERATIONS = {
|
||||
"add": "Add", "sub": "Sub", "and": "And", "or": "Or", "xor": "Xor",
|
||||
"andn2": "AndNot", "orn2": "OrNot", "nand": "Nand", "nor": "Nor", "xnor": "Xnor",
|
||||
"lshl": "ShiftLeft", "lshr": "LogicalShiftRight", "ashr": "ArithmeticShiftRight",
|
||||
}
|
||||
# Logical operations take untyped bits; arithmetic ones never do. Shifts take
|
||||
# the signedness their primitive names, and their S1 is an unsigned count.
|
||||
LOGICAL = {"and", "or", "xor", "andn2", "orn2", "nand", "nor", "xnor"}
|
||||
ARITHMETIC = {"add", "sub"}
|
||||
SHIFTS = {"lshl", "lshr", "ashr"}
|
||||
# Optional keys: required exactly when the condition holds.
|
||||
SHIFT_KEY = "shift_count_bits"
|
||||
SIGNEDNESS = {"unsigned": "Unsigned", "signed": "Signed", "bitwise": "Bitwise"}
|
||||
CARRY_IN = {"none": "None", "scc": "Scc"}
|
||||
SCC = {
|
||||
@@ -86,6 +96,14 @@ PRIMITIVES = {
|
||||
("and", "bitwise"): ("nonzero", "and_nonzero_b32", False),
|
||||
("or", "bitwise"): ("nonzero", "or_nonzero_b32", False),
|
||||
("xor", "bitwise"): ("nonzero", "xor_nonzero_b32", False),
|
||||
("andn2", "bitwise"): ("nonzero", "andn2_nonzero_b32", False),
|
||||
("orn2", "bitwise"): ("nonzero", "orn2_nonzero_b32", False),
|
||||
("nand", "bitwise"): ("nonzero", "nand_nonzero_b32", False),
|
||||
("nor", "bitwise"): ("nonzero", "nor_nonzero_b32", False),
|
||||
("xnor", "bitwise"): ("nonzero", "xnor_nonzero_b32", False),
|
||||
("lshl", "bitwise"): ("nonzero", "lshl_nonzero_b32", False),
|
||||
("lshr", "unsigned"): ("nonzero", "lshr_nonzero_b32", False),
|
||||
("ashr", "signed"): ("nonzero", "ashr_nonzero_i32", False),
|
||||
}
|
||||
|
||||
# Operand rules the decoder implements, each exactly once. A registry rule must
|
||||
@@ -205,6 +223,7 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
if rule is None:
|
||||
return
|
||||
fields = [(rule["dst"]["field"], False)] + [(src["field"], True) for src in rule["src"]]
|
||||
count_field = rule["src"][1]["field"] if form["operation"] in SHIFTS else None
|
||||
for field, is_source in fields:
|
||||
if field not in operands:
|
||||
errors.append(f"{label}: XML has no operand {field}")
|
||||
@@ -215,7 +234,10 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
if (is_input, is_output) != (is_source, not is_source):
|
||||
errors.append(f"{label}: {field} direction disagrees with the XML")
|
||||
signed_format = data_format.startswith("FMT_NUM_I")
|
||||
if is_source and signed_format != (form["signedness"] == "signed"):
|
||||
if field == count_field:
|
||||
if signed_format:
|
||||
errors.append(f"{label}: shift count {field} has signed XML format {data_format}")
|
||||
elif is_source and signed_format != (form["signedness"] == "signed"):
|
||||
errors.append(
|
||||
f"{label}: signedness {form['signedness']} contradicts XML format {data_format}"
|
||||
)
|
||||
@@ -261,7 +283,7 @@ def validate(registry, snapshot):
|
||||
for index, form in enumerate(forms):
|
||||
label = form.get("name", f"form #{index}")
|
||||
missing = sorted(FORM_KEYS - set(form))
|
||||
extra = sorted(set(form) - FORM_KEYS)
|
||||
extra = sorted(set(form) - FORM_KEYS - {SHIFT_KEY})
|
||||
if missing:
|
||||
errors.append(f"{label}: incomplete, missing {missing}")
|
||||
if extra:
|
||||
@@ -294,10 +316,20 @@ def validate(registry, snapshot):
|
||||
if value in seen[key]:
|
||||
errors.append(f"{label}: duplicate {key} {value}")
|
||||
seen[key].add(value)
|
||||
if (form["signedness"] == "bitwise") != (form["operation"] in LOGICAL):
|
||||
if (form["operation"] in LOGICAL and form["signedness"] != "bitwise") or (
|
||||
form["operation"] in ARITHMETIC and form["signedness"] == "bitwise"
|
||||
):
|
||||
errors.append(
|
||||
f"{label}: signedness {form['signedness']} contradicts operation {form['operation']}"
|
||||
)
|
||||
if form["operation"] in SHIFTS:
|
||||
bits = form.get(SHIFT_KEY)
|
||||
if type(bits) is not int or (1 << bits) != form["width"]:
|
||||
errors.append(
|
||||
f"{label}: {SHIFT_KEY} must be log2 of the width ({form['width']}), got {bits!r}"
|
||||
)
|
||||
elif SHIFT_KEY in form:
|
||||
errors.append(f"{label}: {SHIFT_KEY} on a non-shift operation")
|
||||
primitive = PRIMITIVES.get((form["operation"], form["signedness"]))
|
||||
if primitive is None:
|
||||
errors.append(f"{label}: no primitive implements {form['operation']}/{form['signedness']}")
|
||||
@@ -396,6 +428,7 @@ def render(registry, snapshot):
|
||||
f" signedness: Signedness::{SIGNEDNESS[form['signedness']]},",
|
||||
f" carry_in: CarryIn::{CARRY_IN[form['carry_in']]},",
|
||||
f" width: {form['width']},",
|
||||
f" shift_count_bits: {form.get(SHIFT_KEY, 0)},",
|
||||
f" scc: SccEffect::{SCC[form['scc']]},",
|
||||
f" vcc: MaskEffect::{MASK[form['vcc']]},",
|
||||
f" exec: MaskEffect::{MASK[form['exec']]},",
|
||||
@@ -489,6 +522,9 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
if takes_carry:
|
||||
argument = "carry_in" if form["carry_in"] == "scc" else "false"
|
||||
call = f"primitive::{function}(src0, src1, {argument})"
|
||||
elif form["operation"] in SHIFTS:
|
||||
mask = (1 << form[SHIFT_KEY]) - 1
|
||||
call = f"primitive::{function}(src0, src1 & 0x{mask:x})"
|
||||
else:
|
||||
call = f"primitive::{function}(src0, src1)"
|
||||
out.append(f" Self::{form['variant']} => {call},")
|
||||
|
||||
@@ -230,3 +230,145 @@ wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
# ---- Stage C: further SOP2 logical and shift forms (#215) ----
|
||||
# Shifts use the low shift_count_bits of S1 as the count (guide 12.1 pseudocode).
|
||||
|
||||
[[form]]
|
||||
name = "S_ANDN2_B32"
|
||||
family = "SOP2"
|
||||
opcode = 20
|
||||
variant = "Andn2B32"
|
||||
operation = "andn2"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_ORN2_B32"
|
||||
family = "SOP2"
|
||||
opcode = 22
|
||||
variant = "Orn2B32"
|
||||
operation = "orn2"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_NAND_B32"
|
||||
family = "SOP2"
|
||||
opcode = 24
|
||||
variant = "NandB32"
|
||||
operation = "nand"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_NOR_B32"
|
||||
family = "SOP2"
|
||||
opcode = 26
|
||||
variant = "NorB32"
|
||||
operation = "nor"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_XNOR_B32"
|
||||
family = "SOP2"
|
||||
opcode = 28
|
||||
variant = "XnorB32"
|
||||
operation = "xnor"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_LSHL_B32"
|
||||
family = "SOP2"
|
||||
opcode = 30
|
||||
variant = "LshlB32"
|
||||
operation = "lshl"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_LSHR_B32"
|
||||
family = "SOP2"
|
||||
opcode = 32
|
||||
variant = "LshrB32"
|
||||
operation = "lshr"
|
||||
signedness = "unsigned"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "S_ASHR_I32"
|
||||
family = "SOP2"
|
||||
opcode = 34
|
||||
variant = "AshrI32"
|
||||
operation = "ashr"
|
||||
signedness = "signed"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
scc = "nonzero"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "sop2_sgpr"
|
||||
spec = [{ document = "guide", section = "12.1", page = 102 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
@@ -49,3 +49,52 @@ pub const fn xor_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = a ^ b;
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Bitwise `a & !b` and whether the result is nonzero.
|
||||
pub const fn andn2_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = a & !b;
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Bitwise `a | !b` and whether the result is nonzero.
|
||||
pub const fn orn2_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = a | !b;
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Bitwise `!(a & b)` and whether the result is nonzero.
|
||||
pub const fn nand_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = !(a & b);
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Bitwise `!(a | b)` and whether the result is nonzero.
|
||||
pub const fn nor_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = !(a | b);
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Bitwise `!(a ^ b)` and whether the result is nonzero.
|
||||
pub const fn xnor_nonzero_b32(a: u32, b: u32) -> (u32, bool) {
|
||||
let value = !(a ^ b);
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// `a << count` and whether the result is nonzero. The caller masks the count
|
||||
/// to the declared count width, so `count` is below 32.
|
||||
pub const fn lshl_nonzero_b32(a: u32, count: u32) -> (u32, bool) {
|
||||
let value = a << count;
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Logical `a >> count` (zero fill) and whether the result is nonzero; `count` is below 32.
|
||||
pub const fn lshr_nonzero_b32(a: u32, count: u32) -> (u32, bool) {
|
||||
let value = a >> count;
|
||||
(value, value != 0)
|
||||
}
|
||||
|
||||
/// Arithmetic `a >> count` (sign fill) and whether the result is nonzero; `count` is below 32.
|
||||
pub const fn ashr_nonzero_i32(a: u32, count: u32) -> (u32, bool) {
|
||||
let value = ((a as i32) >> count) as u32;
|
||||
(value, value != 0)
|
||||
}
|
||||
@@ -30,6 +30,22 @@ pub enum Operation {
|
||||
Or,
|
||||
/// Bitwise exclusive OR.
|
||||
Xor,
|
||||
/// Bitwise AND with the complement of S1.
|
||||
AndNot,
|
||||
/// Bitwise OR with the complement of S1.
|
||||
OrNot,
|
||||
/// Complement of bitwise AND.
|
||||
Nand,
|
||||
/// Complement of bitwise OR.
|
||||
Nor,
|
||||
/// Complement of bitwise exclusive OR.
|
||||
Xnor,
|
||||
/// Shift S0 left by the masked count in S1, filling with zeros.
|
||||
ShiftLeft,
|
||||
/// Shift S0 right by the masked count in S1, filling with zeros.
|
||||
LogicalShiftRight,
|
||||
/// Shift S0 right by the masked count in S1, filling with its sign bit.
|
||||
ArithmeticShiftRight,
|
||||
}
|
||||
|
||||
/// How the operands are interpreted. `Bitwise` exactly when the operation is logical.
|
||||
@@ -141,6 +157,8 @@ pub struct FormSemantics {
|
||||
pub carry_in: CarryIn,
|
||||
/// Operand and result width in bits.
|
||||
pub width: u8,
|
||||
/// Low bits of S1 used as the shift count by shift operations; 0 otherwise.
|
||||
pub shift_count_bits: u8,
|
||||
/// SCC write.
|
||||
pub scc: SccEffect,
|
||||
/// VCC write.
|
||||
|
||||
@@ -32,11 +32,27 @@ pub enum ScalarAluOp {
|
||||
OrB32,
|
||||
/// `s_xor_b32` (SOP2 opcode 18): bitwise xor, SCC = nonzero.
|
||||
XorB32,
|
||||
/// `s_andn2_b32` (SOP2 opcode 20): bitwise andn2, SCC = nonzero.
|
||||
Andn2B32,
|
||||
/// `s_orn2_b32` (SOP2 opcode 22): bitwise orn2, SCC = nonzero.
|
||||
Orn2B32,
|
||||
/// `s_nand_b32` (SOP2 opcode 24): bitwise nand, SCC = nonzero.
|
||||
NandB32,
|
||||
/// `s_nor_b32` (SOP2 opcode 26): bitwise nor, SCC = nonzero.
|
||||
NorB32,
|
||||
/// `s_xnor_b32` (SOP2 opcode 28): bitwise xnor, SCC = nonzero.
|
||||
XnorB32,
|
||||
/// `s_lshl_b32` (SOP2 opcode 30): bitwise lshl, SCC = nonzero.
|
||||
LshlB32,
|
||||
/// `s_lshr_b32` (SOP2 opcode 32): unsigned lshr, SCC = nonzero.
|
||||
LshrB32,
|
||||
/// `s_ashr_i32` (SOP2 opcode 34): signed ashr, SCC = nonzero.
|
||||
AshrI32,
|
||||
}
|
||||
|
||||
impl ScalarAluOp {
|
||||
/// Every operation, in registry order.
|
||||
pub const ALL: [Self; 9] = [
|
||||
pub const ALL: [Self; 17] = [
|
||||
Self::AddU32,
|
||||
Self::SubU32,
|
||||
Self::AddI32,
|
||||
@@ -46,6 +62,14 @@ impl ScalarAluOp {
|
||||
Self::AndB32,
|
||||
Self::OrB32,
|
||||
Self::XorB32,
|
||||
Self::Andn2B32,
|
||||
Self::Orn2B32,
|
||||
Self::NandB32,
|
||||
Self::NorB32,
|
||||
Self::XnorB32,
|
||||
Self::LshlB32,
|
||||
Self::LshrB32,
|
||||
Self::AshrI32,
|
||||
];
|
||||
|
||||
/// Selects the operation from a first instruction word (mask 0xff80_0000).
|
||||
@@ -60,6 +84,14 @@ impl ScalarAluOp {
|
||||
0x8700_0000 => Some(Self::AndB32),
|
||||
0x8800_0000 => Some(Self::OrB32),
|
||||
0x8900_0000 => Some(Self::XorB32),
|
||||
0x8a00_0000 => Some(Self::Andn2B32),
|
||||
0x8b00_0000 => Some(Self::Orn2B32),
|
||||
0x8c00_0000 => Some(Self::NandB32),
|
||||
0x8d00_0000 => Some(Self::NorB32),
|
||||
0x8e00_0000 => Some(Self::XnorB32),
|
||||
0x8f00_0000 => Some(Self::LshlB32),
|
||||
0x9000_0000 => Some(Self::LshrB32),
|
||||
0x9100_0000 => Some(Self::AshrI32),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -76,6 +108,14 @@ impl ScalarAluOp {
|
||||
Self::AndB32 => "s_and_b32",
|
||||
Self::OrB32 => "s_or_b32",
|
||||
Self::XorB32 => "s_xor_b32",
|
||||
Self::Andn2B32 => "s_andn2_b32",
|
||||
Self::Orn2B32 => "s_orn2_b32",
|
||||
Self::NandB32 => "s_nand_b32",
|
||||
Self::NorB32 => "s_nor_b32",
|
||||
Self::XnorB32 => "s_xnor_b32",
|
||||
Self::LshlB32 => "s_lshl_b32",
|
||||
Self::LshrB32 => "s_lshr_b32",
|
||||
Self::AshrI32 => "s_ashr_i32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +131,14 @@ impl ScalarAluOp {
|
||||
Self::AndB32 => false,
|
||||
Self::OrB32 => false,
|
||||
Self::XorB32 => false,
|
||||
Self::Andn2B32 => false,
|
||||
Self::Orn2B32 => false,
|
||||
Self::NandB32 => false,
|
||||
Self::NorB32 => false,
|
||||
Self::XnorB32 => false,
|
||||
Self::LshlB32 => false,
|
||||
Self::LshrB32 => false,
|
||||
Self::AshrI32 => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +154,14 @@ impl ScalarAluOp {
|
||||
Self::AndB32 => 6,
|
||||
Self::OrB32 => 7,
|
||||
Self::XorB32 => 8,
|
||||
Self::Andn2B32 => 9,
|
||||
Self::Orn2B32 => 10,
|
||||
Self::NandB32 => 11,
|
||||
Self::NorB32 => 12,
|
||||
Self::XnorB32 => 13,
|
||||
Self::LshlB32 => 14,
|
||||
Self::LshrB32 => 15,
|
||||
Self::AshrI32 => 16,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -122,12 +178,20 @@ impl ScalarAluOp {
|
||||
Self::AndB32 => primitive::and_nonzero_b32(src0, src1),
|
||||
Self::OrB32 => primitive::or_nonzero_b32(src0, src1),
|
||||
Self::XorB32 => primitive::xor_nonzero_b32(src0, src1),
|
||||
Self::Andn2B32 => primitive::andn2_nonzero_b32(src0, src1),
|
||||
Self::Orn2B32 => primitive::orn2_nonzero_b32(src0, src1),
|
||||
Self::NandB32 => primitive::nand_nonzero_b32(src0, src1),
|
||||
Self::NorB32 => primitive::nor_nonzero_b32(src0, src1),
|
||||
Self::XnorB32 => primitive::xnor_nonzero_b32(src0, src1),
|
||||
Self::LshlB32 => primitive::lshl_nonzero_b32(src0, src1 & 0x1f),
|
||||
Self::LshrB32 => primitive::lshr_nonzero_b32(src0, src1 & 0x1f),
|
||||
Self::AshrI32 => primitive::ashr_nonzero_i32(src0, src1 & 0x1f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity of every registry form, in registry order.
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 9] = [
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 17] = [
|
||||
("S_ADD_U32", EncodingFamily::Sop2),
|
||||
("S_SUB_U32", EncodingFamily::Sop2),
|
||||
("S_ADD_I32", EncodingFamily::Sop2),
|
||||
@@ -137,10 +201,18 @@ pub const FORM_IDS: [(&str, EncodingFamily); 9] = [
|
||||
("S_AND_B32", EncodingFamily::Sop2),
|
||||
("S_OR_B32", EncodingFamily::Sop2),
|
||||
("S_XOR_B32", EncodingFamily::Sop2),
|
||||
("S_ANDN2_B32", EncodingFamily::Sop2),
|
||||
("S_ORN2_B32", EncodingFamily::Sop2),
|
||||
("S_NAND_B32", EncodingFamily::Sop2),
|
||||
("S_NOR_B32", EncodingFamily::Sop2),
|
||||
("S_XNOR_B32", EncodingFamily::Sop2),
|
||||
("S_LSHL_B32", EncodingFamily::Sop2),
|
||||
("S_LSHR_B32", EncodingFamily::Sop2),
|
||||
("S_ASHR_I32", EncodingFamily::Sop2),
|
||||
];
|
||||
|
||||
/// One validated row per registry form, in registry order.
|
||||
pub static FORMS: [FormSemantics; 9] = [
|
||||
pub static FORMS: [FormSemantics; 17] = [
|
||||
FormSemantics {
|
||||
name: "S_ADD_U32",
|
||||
family: EncodingFamily::Sop2,
|
||||
@@ -149,6 +221,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::CarryOut,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -165,6 +238,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Borrow,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -181,6 +255,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::SignedOverflow,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -197,6 +272,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::SignedOverflow,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -213,6 +289,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::Scc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::CarryOut,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -229,6 +306,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::Scc,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Borrow,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -245,6 +323,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -261,6 +340,7 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
@@ -277,6 +357,143 @@ pub static FORMS: [FormSemantics; 9] = [
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_ANDN2_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 20,
|
||||
operation: Operation::AndNot,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_ORN2_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 22,
|
||||
operation: Operation::OrNot,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_NAND_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 24,
|
||||
operation: Operation::Nand,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_NOR_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 26,
|
||||
operation: Operation::Nor,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_XNOR_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 28,
|
||||
operation: Operation::Xnor,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_LSHL_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 30,
|
||||
operation: Operation::ShiftLeft,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_LSHR_B32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 32,
|
||||
operation: Operation::LogicalShiftRight,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Sop2Sgpr,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.1", page: 102 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "S_ASHR_I32",
|
||||
family: EncodingFamily::Sop2,
|
||||
opcode: 34,
|
||||
operation: Operation::ArithmeticShiftRight,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
scc: SccEffect::Nonzero,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
|
||||
@@ -280,6 +280,20 @@ fn scalar_alu_results_reach_the_kernel_as_constants() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_logic_results_reach_the_kernel_as_constants() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/scalar-logic.bin");
|
||||
let compiled = compile(Architecture::Gfx1030, code).unwrap();
|
||||
assert_eq!(
|
||||
compiled.ir,
|
||||
include_str!("../../../fixtures/golden/scalar-logic.ir")
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.msl,
|
||||
include_str!("../../../fixtures/golden/scalar-logic.metal")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_compares_lower_to_per_thread_wave_masks_and_selects() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vector-compare.bin");
|
||||
|
||||
@@ -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: 42 of 42. Accepted Metal forms · Apple M5: 18 of 42. Accepted guest milestones · X1–X4: 4 of 4</desc>
|
||||
<desc id="description">Decoded gfx1030 forms: 50 of 50. Accepted Metal forms · Apple M5: 18 of 50. 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">42 / 42</text>
|
||||
<text x="510" y="58" font-size="13" text-anchor="end">50 / 50</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 / 42</text>
|
||||
<text x="510" y="96" font-size="13" text-anchor="end">18 / 50</text>
|
||||
<rect x="20" y="103" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
<rect x="20" y="103" width="210.00" height="4" rx="2" fill="#88c6bd"/>
|
||||
<rect x="20" y="103" width="176.40" 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 |
@@ -31,6 +31,14 @@ The wider LLVM operand matrix exercises decoding only. ABI means application bin
|
||||
| `s_and_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 | `870D090C` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_or_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 | `880ED00D` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_xor_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; SCC = result != 0 | `890C0A0B` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_andn2_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 & ~S1; SCC = result != 0 | `8A09FF08 FF00FF00` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_orn2_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 \| ~S1; SCC = result != 0 | `8B0AC109` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_nand_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 & S1); SCC = result != 0 | `8C0B0808` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_nor_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 \| S1); SCC = result != 0 | `8D0C090B` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_xnor_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 ^ S1); SCC = result != 0 | `8E0D080C` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_lshl_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 << S1[4:0]; SCC = result != 0 | `8F0EA40D` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_lshr_b32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 >> S1[4:0], zero fill; SCC = result != 0 | `900FFF0E FFFFFFE1` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `s_ashr_i32` | SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 >> S1[4:0], sign fill; SCC = result != 0 | `91109F0E` | yes | yes | three-way passed | resolved scalar state and SCC | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_lt_i32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 < S1), fully written | `7D020701` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_eq_i32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 == S1), fully written | `7D040280` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_le_i32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 <= S1), fully written | `7D060208` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SOP2 scalar ALU subset
|
||||
|
||||
Xenora decodes and executes nine gfx1030 SOP2 forms. Each takes 32-bit
|
||||
Xenora decodes and executes seventeen gfx1030 SOP2 forms. Each takes 32-bit
|
||||
operands, writes a normal SGPR (s0-s105) and sets SCC.
|
||||
|
||||
| Form | D | SCC |
|
||||
@@ -14,10 +14,23 @@ operands, writes a normal SGPR (s0-s105) and sets SCC.
|
||||
| `s_and_b32` | S0 & S1 | D != 0 |
|
||||
| `s_or_b32` | S0 \| S1 | D != 0 |
|
||||
| `s_xor_b32` | S0 ^ S1 | D != 0 |
|
||||
| `s_andn2_b32` | S0 & ~S1 | D != 0 |
|
||||
| `s_orn2_b32` | S0 \| ~S1 | D != 0 |
|
||||
| `s_nand_b32` | ~(S0 & S1) | D != 0 |
|
||||
| `s_nor_b32` | ~(S0 \| S1) | D != 0 |
|
||||
| `s_xnor_b32` | ~(S0 ^ S1) | D != 0 |
|
||||
| `s_lshl_b32` | S0 << S1[4:0] | D != 0 |
|
||||
| `s_lshr_b32` | S0 >> S1[4:0], zero fill | D != 0 |
|
||||
| `s_ashr_i32` | S0 >> S1[4:0], sign fill | D != 0 |
|
||||
|
||||
The last eight were added through the semantic registry alone: one TOML entry
|
||||
each, with no hand-written Rust per form. Shifts use only the low five bits of
|
||||
S1 as the count, as the guide's pseudocode states (section 12.1); higher bits are
|
||||
ignored.
|
||||
|
||||
Sources are normal SGPRs, inline integers (-16 to 64) or one literal word.
|
||||
|
||||
These nine forms are declared as data in the semantic registry,
|
||||
These forms are declared as data in the semantic registry,
|
||||
`crates/isa/semantics/rdna2.toml`: opcode, operation, signedness, carry-in,
|
||||
SCC effect, operand rule and guide references. `crates/isa/generate_semantics.py`
|
||||
checks each declaration against the pinned AMD XML snapshot and rejects
|
||||
|
||||
@@ -25,7 +25,7 @@ acceptance remain outside the verified count. All results concern synthetic fixt
|
||||
| SCRATCH | 22 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| SMEM | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| SOP1 | 65 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
|
||||
| SOP2 | 51 | 9 | 9 | 9 | 9 | 9 | 0 | 0 | 12 |
|
||||
| SOP2 | 51 | 17 | 17 | 17 | 17 | 17 | 0 | 0 | 12 |
|
||||
| SOPC | 18 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
|
||||
| SOPK | 27 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
|
||||
| SOPP | 36 | 6 | 0 | 6 | 6 | 6 | 4 | 4 | 0 |
|
||||
@@ -36,7 +36,7 @@ acceptance remain outside the verified count. All results concern synthetic fixt
|
||||
| VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOPC | 190 | 12 | 0 | 12 | 12 | 12 | 0 | 0 | 0 |
|
||||
| **Total** | 1465 | 42 | 9 | 46 | 42 | 42 | 18 | 18 | 12 |
|
||||
| **Total** | 1465 | 50 | 17 | 54 | 50 | 50 | 18 | 18 | 12 |
|
||||
|
||||
## Unsupported operand variants
|
||||
|
||||
|
||||
@@ -51,10 +51,11 @@ error.
|
||||
| `family` | Encoding family; must match the XML base encoding | e.g. `SOP2` |
|
||||
| `opcode` | Opcode; must match the XML | non-negative integer |
|
||||
| `variant` | Rust enum variant of the typed operation | CamelCase, e.g. `AddU32` |
|
||||
| `operation` | The primitive the form uses | `add`, `sub`, `and`, `or`, `xor` |
|
||||
| `signedness` | How operands are read | `unsigned`, `signed`, `bitwise` (`bitwise` exactly for `and`, `or`, `xor`) |
|
||||
| `operation` | The primitive the form uses | `add`, `sub`, `and`, `or`, `xor`, `andn2`, `orn2`, `nand`, `nor`, `xnor`, `lshl`, `lshr`, `ashr` |
|
||||
| `signedness` | How operands are read | `unsigned`, `signed`, `bitwise` (always `bitwise` for the logical operations, never for `add` and `sub`; shifts take their primitive's signedness) |
|
||||
| `carry_in` | Whether the form reads SCC as carry-in or borrow-in | `none`, `scc` (`scc` only for unsigned `add` and `sub`) |
|
||||
| `width` | Operand and result width in bits | `32` |
|
||||
| `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 |
|
||||
| `scc` | What the form writes to SCC | `carry_out`, `borrow`, `signed_overflow`, `nonzero`, `unchanged` |
|
||||
| `vcc`, `exec` | Effect on VCC and EXEC, stated rather than implied | `unchanged` |
|
||||
| `wave` | Wave sizes the form is valid in | `any` (`wave32` is in the vocabulary but rejected until the decoder can enforce it) |
|
||||
@@ -71,7 +72,10 @@ fixes the `scc` value:
|
||||
| `sub` / `unsigned` | `borrow` | `sub_borrow_u32` | allowed |
|
||||
| `add` / `signed` | `signed_overflow` | `add_overflow_i32` | no |
|
||||
| `sub` / `signed` | `signed_overflow` | `sub_overflow_i32` | no |
|
||||
| `and`, `or`, `xor` / `bitwise` | `nonzero` | `and_nonzero_b32`, `or_nonzero_b32`, `xor_nonzero_b32` | no |
|
||||
| `and`, `or`, `xor`, `andn2`, `orn2`, `nand`, `nor`, `xnor` / `bitwise` | `nonzero` | `and_nonzero_b32`, `or_nonzero_b32`, `xor_nonzero_b32`, `andn2_nonzero_b32`, `orn2_nonzero_b32`, `nand_nonzero_b32`, `nor_nonzero_b32`, `xnor_nonzero_b32` | no |
|
||||
| `lshl` / `bitwise` | `nonzero` | `lshl_nonzero_b32` | no |
|
||||
| `lshr` / `unsigned` | `nonzero` | `lshr_nonzero_b32` | no |
|
||||
| `ashr` / `signed` | `nonzero` | `ashr_nonzero_i32` | no |
|
||||
|
||||
Behaviour is chosen only from these declared fields, never from the mnemonic.
|
||||
|
||||
|
||||
@@ -255,6 +255,102 @@ recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_andn2_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 & ~S1; SCC = result != 0"
|
||||
representation = "`8A09FF08 FF00FF00`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_orn2_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 | ~S1; SCC = result != 0"
|
||||
representation = "`8B0AC109`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_nand_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 & S1); SCC = result != 0"
|
||||
representation = "`8C0B0808`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_nor_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 | S1); SCC = result != 0"
|
||||
representation = "`8D0C090B`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_xnor_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = ~(S0 ^ S1); SCC = result != 0"
|
||||
representation = "`8E0D080C`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_lshl_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 << S1[4:0]; SCC = result != 0"
|
||||
representation = "`8F0EA40D`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_lshr_b32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 >> S1[4:0], zero fill; SCC = result != 0"
|
||||
representation = "`900FFF0E FFFFFFE1`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "s_ashr_i32"
|
||||
encoding = "SOP2, normal SGPR destination; normal SGPR, inline integer or literal sources with at most one literal; D = S0 >> S1[4:0], sign fill; SCC = result != 0"
|
||||
representation = "`91109F0E`"
|
||||
lowering = "resolved scalar state and SCC"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_lt_i32_e32"
|
||||
encoding = "VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (signed S0 < S1), fully written"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
0000: t0 = load.u32 input[index]
|
||||
0040: branch.uniform 0x004c taken=true
|
||||
004c: t2 = const.u32 0xff0fffff
|
||||
0050: t3 = const.u32 0x787ffff8
|
||||
0054: t4 = xor.b32 t2, t3
|
||||
0058: t5 = const.u32 0xffffffff
|
||||
005c: t6 = xor.b32 t4, t5
|
||||
0060: t7 = const.u32 0x00f00000
|
||||
0064: t8 = xor.b32 t6, t7
|
||||
0068: t9 = const.u32 0xf000ff00
|
||||
006c: t10 = xor.b32 t8, t9
|
||||
0070: t11 = xor.b32 t0, t10
|
||||
0074: store.u32 output[index], t11
|
||||
@@ -0,0 +1,19 @@
|
||||
#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 t0 = input[index];
|
||||
uint t2 = 0xff0fffffu;
|
||||
uint t3 = 0x787ffff8u;
|
||||
uint t4 = t2 ^ t3;
|
||||
uint t5 = 0xffffffffu;
|
||||
uint t6 = t4 ^ t5;
|
||||
uint t7 = 0x00f00000u;
|
||||
uint t8 = t6 ^ t7;
|
||||
uint t9 = 0xf000ff00u;
|
||||
uint t10 = t8 ^ t9;
|
||||
uint t11 = t0 ^ t10;
|
||||
output[index] = t11;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Original SOP2 vectors for the registry-declared logical and shift forms:
|
||||
// ANDN2/ORN2 with a literal and an inline -1, NAND with aliased sources,
|
||||
// NOR/XNOR chains, shift counts that use only S1[4:0] (36 -> 4, a literal
|
||||
// 0xffffffe1 -> 1, 31), an arithmetic shift of a negative and a positive value,
|
||||
// and an SCC branch on a zero shift result. SGPR results are moved into VGPRs.
|
||||
// Expected: input ^ 0x887f00f8 (worked out by hand below).
|
||||
.text
|
||||
buffer_load_dword v1, v0, s[0:3], 0 idxen
|
||||
s_waitcnt vmcnt(0)
|
||||
s_mov_b32 s8, 0xf0f0ff00
|
||||
s_andn2_b32 s9, s8, 0xff00ff00 // s9 = 0x00f00000, SCC = 1
|
||||
s_orn2_b32 s10, s9, -1 // s10 = 0x00f00000, SCC = 1
|
||||
s_nand_b32 s11, s8, s8 // s11 = 0x0f0f00ff, SCC = 1
|
||||
s_nor_b32 s12, s11, s9 // s12 = 0xf000ff00, SCC = 1
|
||||
s_xnor_b32 s13, s12, s8 // s13 = 0xff0fffff, SCC = 1
|
||||
s_lshl_b32 s14, s13, 36 // s14 = 0xf0fffff0 (count 4), SCC = 1
|
||||
s_lshr_b32 s15, s14, 0xffffffe1 // s15 = 0x787ffff8 (count 1), SCC = 1
|
||||
s_ashr_i32 s16, s14, 31 // s16 = 0xffffffff, SCC = 1
|
||||
s_ashr_i32 s17, s15, 31 // s17 = 0, SCC = 0
|
||||
s_cbranch_scc0 .Lzero
|
||||
v_mov_b32_e32 v2, 0
|
||||
s_branch .Ldone
|
||||
.Lzero:
|
||||
v_mov_b32_e32 v2, s13
|
||||
v_mov_b32_e32 v3, s15
|
||||
v_xor_b32_e32 v2, v2, v3
|
||||
v_mov_b32_e32 v4, s16
|
||||
v_xor_b32_e32 v2, v2, v4
|
||||
v_mov_b32_e32 v5, s10
|
||||
v_xor_b32_e32 v2, v2, v5
|
||||
v_mov_b32_e32 v6, s12
|
||||
v_xor_b32_e32 v2, v2, v6 // 0xff0fffff ^ 0x787ffff8 ^ 0xffffffff ^ 0x00f00000 ^ 0xf000ff00
|
||||
v_xor_b32_e32 v2, v1, v2
|
||||
.Ldone:
|
||||
buffer_store_dword v2, 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; do
|
||||
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic; 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"
|
||||
|
||||
@@ -32,11 +32,11 @@ U32 = "FMT_NUM_U32"
|
||||
I32 = "FMT_NUM_I32"
|
||||
|
||||
|
||||
def _operands(data_format, scc_in=False):
|
||||
def _operands(data_format, scc_in=False, src1_format=None):
|
||||
rows = [
|
||||
["SDST", data_format, "OPR_SDST", 32, False, True, False, True],
|
||||
["SSRC0", data_format, "OPR_SSRC_NOLDS", 32, True, False, False, True],
|
||||
["SSRC1", data_format, "OPR_SSRC_NOLDS", 32, True, False, False, True],
|
||||
["SSRC1", src1_format or data_format, "OPR_SSRC_NOLDS", 32, True, False, False, True],
|
||||
["", "FMT_NUM_B1", "OPR_SSRC_SPECIAL_SCC", 1, False, True, True, True],
|
||||
]
|
||||
if scc_in:
|
||||
@@ -54,7 +54,7 @@ def snapshot():
|
||||
["OP", [[23, 7]]], ["ENCODING", [[30, 2]]],
|
||||
],
|
||||
"identifier_mask": 0xFF800000,
|
||||
"identifiers": [sop2_base | (op << 23) for op in (0, 2, 4, 14)],
|
||||
"identifiers": [sop2_base | (op << 23) for op in (0, 2, 4, 14, 34)],
|
||||
}
|
||||
variants = {}
|
||||
for name, opcode, operands in (
|
||||
@@ -62,6 +62,8 @@ def snapshot():
|
||||
("S_ADD_I32", 2, _operands(I32)),
|
||||
("S_ADDC_U32", 4, _operands(U32, scc_in=True)),
|
||||
("S_AND_B32", 14, _operands(U32)),
|
||||
# The XML gives S_ASHR_I32 a signed S0 and an unsigned shift count.
|
||||
("S_ASHR_I32", 34, _operands(I32, src1_format=U32)),
|
||||
):
|
||||
variants[(name, "ENC_SOP2")] = {
|
||||
"instruction": name, "encoding": "ENC_SOP2", "opcode": opcode, "operands": operands,
|
||||
@@ -94,6 +96,10 @@ def registry():
|
||||
_form("S_ADD_I32", 2, "AddI32", "add", "signed", "signed_overflow"),
|
||||
_form("S_ADDC_U32", 4, "AddcU32", "add", "unsigned", "carry_out", carry_in="scc"),
|
||||
_form("S_AND_B32", 14, "AndB32", "and", "bitwise", "nonzero"),
|
||||
dict(
|
||||
_form("S_ASHR_I32", 34, "AshrI32", "ashr", "signed", "nonzero"),
|
||||
shift_count_bits=5,
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -288,6 +294,37 @@ class Validate(unittest.TestCase):
|
||||
reg["operand_rules"]["sop2_sgpr"]["max_literals"] = 2
|
||||
self.rejects(reg, "operand rule sop2_sgpr: declaration differs")
|
||||
|
||||
def test_rejects_a_shift_without_a_count_width(self):
|
||||
reg = registry()
|
||||
del reg["form"][-1]["shift_count_bits"]
|
||||
self.rejects(reg, "S_ASHR_I32: shift_count_bits must be log2 of the width (32), got None")
|
||||
|
||||
def test_rejects_a_wrong_count_width(self):
|
||||
reg = registry()
|
||||
reg["form"][-1]["shift_count_bits"] = 6
|
||||
self.rejects(reg, "S_ASHR_I32: shift_count_bits must be log2 of the width (32), got 6")
|
||||
|
||||
def test_rejects_a_count_width_on_a_non_shift(self):
|
||||
reg = registry()
|
||||
reg["form"][0]["shift_count_bits"] = 5
|
||||
self.rejects(reg, "S_ADD_U32: shift_count_bits on a non-shift operation")
|
||||
|
||||
def test_rejects_a_signed_shift_count_in_the_xml(self):
|
||||
snap = snapshot()
|
||||
snap["variants"][("S_ASHR_I32", "ENC_SOP2")]["operands"] = _operands(I32)
|
||||
self.rejects(registry(), "S_ASHR_I32: shift count SSRC1 has signed XML format", snap)
|
||||
|
||||
def test_rejects_an_unsigned_arithmetic_shift(self):
|
||||
reg = registry()
|
||||
reg["form"][-1]["signedness"] = "unsigned"
|
||||
self.rejects(reg, "S_ASHR_I32: no primitive implements ashr/unsigned")
|
||||
|
||||
def test_renders_the_declared_count_mask(self):
|
||||
self.assertIn(
|
||||
"Self::AshrI32 => primitive::ashr_nonzero_i32(src0, src1 & 0x1f),",
|
||||
gen.render(registry(), snapshot()),
|
||||
)
|
||||
|
||||
def test_rejects_an_incomplete_unsupported_list(self):
|
||||
reg = registry()
|
||||
reg["operand_rules"]["sop2_sgpr"]["unsupported"].remove("two_literals")
|
||||
@@ -431,7 +468,7 @@ class Render(unittest.TestCase):
|
||||
body = text.split("match word & ", 1)[1].split("_ => None", 1)[0]
|
||||
words = [line.split(" => ")[0].strip() for line in body.splitlines()[1:] if "=>" in line]
|
||||
self.assertEqual(words, sorted(words))
|
||||
self.assertEqual(len(words), 4)
|
||||
self.assertEqual(len(words), 5)
|
||||
|
||||
def test_real_registry_renders_the_committed_file(self):
|
||||
text = gen.render(gen.load_registry(), gen.load_snapshot())
|
||||
|
||||
@@ -768,6 +768,9 @@ mod review {
|
||||
}
|
||||
|
||||
const SCALAR_ALU_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/scalar-alu.bin");
|
||||
const SCALAR_LOGIC_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/scalar-logic.bin");
|
||||
// Hand-derived in fixtures/rdna2/scalar-logic.s from the guide's 12.1 pseudocode.
|
||||
const SCALAR_LOGIC_KEY: u32 = 0x887f_00f8;
|
||||
// SOP2 opcodes of the supported subset (RDNA 2 XML opcode table).
|
||||
const SOP2_OPCODES: [u32; 9] = [0, 1, 2, 3, 4, 5, 14, 16, 18];
|
||||
const SCALAR_VALUES: [u32; 10] = [
|
||||
@@ -869,6 +872,24 @@ mod review {
|
||||
verify(&nonzero, &input, Some(&[0; 5]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_logic_fixture_chains_registry_logical_and_shift_forms() {
|
||||
let input = [0, 1, u32::MAX, SCALAR_LOGIC_KEY, 0x1234_5678];
|
||||
let expected: Vec<_> = input.iter().map(|word| word ^ SCALAR_LOGIC_KEY).collect();
|
||||
verify(SCALAR_LOGIC_FIXTURE, &input, Some(&expected));
|
||||
let compiled = compile(Architecture::Gfx1030, SCALAR_LOGIC_FIXTURE).unwrap();
|
||||
assert!(compiled.disassembly.contains("s_ashr_i32 s17, s15, 31"));
|
||||
// The SCC-zero edge is observable: with a shift count of 30 instead of
|
||||
// 31, s17 = 0x787ffff8 >> 30 = 1, SCC = 1, and v2 = 0.
|
||||
let mut nonzero = SCALAR_LOGIC_FIXTURE.to_vec();
|
||||
let at = nonzero
|
||||
.windows(4)
|
||||
.position(|word| word == [0x0f, 0x9f, 0x11, 0x91])
|
||||
.unwrap();
|
||||
nonzero[at + 1] = 0x9e;
|
||||
verify(&nonzero, &input, Some(&[0; 5]));
|
||||
}
|
||||
|
||||
/// The translator's own folding: v2 = D as a constant, and the SCC-zero edge
|
||||
/// is taken exactly when SCC is clear.
|
||||
fn assert_translated(code: &[u8], expected: &[u32; 2]) {
|
||||
@@ -1089,6 +1110,8 @@ mod review {
|
||||
let input: Vec<u32> = (0..64).map(|lane| lane * 0x0101_0101).collect();
|
||||
let expected: Vec<_> = input.iter().map(|word| word ^ 0x0000_000e).collect();
|
||||
assert_eq!(run(SCALAR_ALU_FIXTURE, &input), expected);
|
||||
let logic: Vec<_> = input.iter().map(|word| word ^ SCALAR_LOGIC_KEY).collect();
|
||||
assert_eq!(run(SCALAR_LOGIC_FIXTURE, &input), logic);
|
||||
let mut vectors = sop2_vectors();
|
||||
vectors.extend(sop2_operand_cases());
|
||||
vectors.extend(signed_immediate_overflows());
|
||||
@@ -1097,7 +1120,7 @@ mod review {
|
||||
}
|
||||
eprintln!(
|
||||
"{} SOP2 programs matched on native Metal",
|
||||
vectors.len() + 1
|
||||
vectors.len() + 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user