Merge B2a (VOP3 VOP2 integer variants, 00cda8a) into task/215-vop3-int

Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
elforeign committed 2026-11-24 08:38:46 -06:00
commit d2999c9e35
10 files changed
+668 -7

No files matched your search

+118 -1
View File
@@ -375,13 +375,14 @@ fn reference_op(instruction: Instruction) -> Op {
reference_scalar(src0),
reference_scalar(src1),
),
// The reference's VOP3 add; it is the only VOP3 variant so far.
// The reference fixture exercises only the VOP3 add.
Instruction::VectorAluVop3 {
op: VectorAluVop3Op::AddNcU32,
dst,
src0,
src1,
} => Op::Add(dst, src0, src1),
Instruction::VectorAluVop3 { op, .. } => panic!("no reference VOP3 mapping for {op:?}"),
Instruction::ScalarMoveB32 { dst, src } => Op::ScalarMove(dst, reference_scalar(src)),
Instruction::ScalarUnary { op, dst, src } => Op::ScalarUnary(
match op {
@@ -1040,3 +1041,119 @@ fn decode_at_resolves_branch_targets_from_the_stream_offset() {
})
);
}
// llvm-mc -triple=amdgcn -mcpu=gfx1030 -show-encoding
const VOP3_INTEGER_ENCODINGS: [(VectorAluVop3Op, u32); 11] = [
// v_mul_i32_i24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x09,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MulI32I24, 0xd50900ff),
// v_mul_hi_i32_i24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0a,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MulHiI32I24, 0xd50a00ff),
// v_mul_u32_u24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0b,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MulU32U24, 0xd50b00ff),
// v_mul_hi_u32_u24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0c,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MulHiU32U24, 0xd50c00ff),
// v_min_i32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x11,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MinI32, 0xd51100ff),
// v_max_i32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x12,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MaxI32, 0xd51200ff),
// v_min_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x13,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MinU32, 0xd51300ff),
// v_max_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x14,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::MaxU32, 0xd51400ff),
// v_xnor_b32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x1e,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::XnorB32, 0xd51e00ff),
// v_sub_nc_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x26,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::SubNcU32, 0xd52600ff),
// v_subrev_nc_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x27,0xd5,0x00,0xff,0x02,0x02]
(VectorAluVop3Op::SubrevNcU32, 0xd52700ff),
];
const VOP3_INTEGER_SOURCE_WORD: u32 = 0x0202_ff00;
#[test]
fn decodes_registry_vop3_integer_encodings() {
for (op, first) in VOP3_INTEGER_ENCODINGS {
let bytes = [first.to_le_bytes(), VOP3_INTEGER_SOURCE_WORD.to_le_bytes()].concat();
let decoded = decode(Architecture::Gfx1030, &bytes).unwrap();
assert_eq!(decoded.len(), 1);
assert_eq!(decoded[0].byte_len, 8);
assert_eq!(
decoded[0].instruction,
Instruction::VectorAluVop3 {
op,
dst: 255,
src0: 0,
src1: 127,
}
);
}
}
#[test]
fn decodes_vop3_integer_fixture() {
use VectorAluVop3Op::*;
let code = include_bytes!("../../../fixtures/rdna2/vop3-integer.bin");
let decoded = decode(Architecture::Gfx1030, code).unwrap();
let expected = [
(MulI32I24, 2, 1, 1),
(MulHiI32I24, 3, 2, 1),
(MulU32U24, 4, 2, 1),
(MulHiU32U24, 255, 4, 1),
(MinI32, 6, 1, 2),
(MaxI32, 7, 1, 4),
(MinU32, 8, 3, 1),
(MaxU32, 9, 255, 2),
(XnorB32, 10, 1, 255),
(SubNcU32, 11, 6, 10),
(SubrevNcU32, 1, 1, 9),
];
let actual: Vec<_> = decoded
.iter()
.filter_map(|decoded| match decoded.instruction {
Instruction::VectorAluVop3 {
op,
dst,
src0,
src1,
} => Some((decoded.offset, decoded.byte_len, op, dst, src0, src1)),
_ => None,
})
.collect();
let expected: Vec<_> = expected
.into_iter()
.enumerate()
.map(|(index, (op, dst, src0, src1))| (12 + 8 * index, 8, op, dst, src0, src1))
.collect();
assert_eq!(actual, expected);
}
#[test]
fn rejects_registry_vop3_integer_modifiers_and_other_sources() {
for (op, first) in VOP3_INTEGER_ENCODINGS {
let second = VOP3_INTEGER_SOURCE_WORD;
let reject = |first: u32, second: u32| {
let bytes = [first.to_le_bytes(), second.to_le_bytes()].concat();
let error = decode(Architecture::Gfx1030, &bytes)
.expect_err(&format!("{op:?} accepted {first:#010x} {second:#010x}"));
assert_eq!(error.offset, 0);
assert!(matches!(
error.kind,
DecodeErrorKind::UnsupportedForm { mnemonic, .. }
if mnemonic == op.assembly_name()
));
};
// First word: ABS[10:8], OP_SEL[14:11], CLAMP[15].
for bit in 8..=15 {
reject(first | (1 << bit), second);
}
// Second word: OMOD[28:27], NEG[31:29].
for bit in 27..=31 {
reject(first, second | (1 << bit));
}
reject(first, second & !0x1ff); // SRC0 = s0
reject(first, (second & !(0x1ff << 9)) | (128 << 9)); // SRC1 = inline zero
reject(first, second | (1 << 18)); // SRC2 = inline one
}
}
+127
View File
@@ -37,3 +37,130 @@ spec = [
{ document = "guide", section = "12.7", page = 134 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
# ABS and NEG apply to floating-point inputs (guide 6.2.1) and OMOD
# applies to floating-point results (6.2.2). These integer forms use neither.
# OP_SEL selects 16-bit halves (13.3.4). CLAMP saturates integer results
# (6.5), which these registry forms do not declare. SGPR, inline and literal
# sources remain outside this operand rule.
[[encoding_variant]]
of = "V_MUL_I32_I24"
family = "VOP3"
opcode = 265
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 131 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MUL_HI_I32_I24"
family = "VOP3"
opcode = 266
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 132 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MUL_U32_U24"
family = "VOP3"
opcode = 267
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 132 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MUL_HI_U32_U24"
family = "VOP3"
opcode = 268
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 132 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MIN_I32"
family = "VOP3"
opcode = 273
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 133 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MAX_I32"
family = "VOP3"
opcode = 274
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 133 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MIN_U32"
family = "VOP3"
opcode = 275
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 133 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_MAX_U32"
family = "VOP3"
opcode = 276
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 133 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_XNOR_B32"
family = "VOP3"
opcode = 286
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 134 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_SUB_NC_U32"
family = "VOP3"
opcode = 294
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 134 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
[[encoding_variant]]
of = "V_SUBREV_NC_U32"
family = "VOP3"
opcode = 295
operands = "vop3_vgpr2"
spec = [
{ document = "guide", section = "12.12", page = 167 },
{ document = "guide", section = "12.7", page = 134 },
]
verify = ["reference", "independent", "metal", "llvm_encoding"]
+322 -3
View File
@@ -1877,12 +1877,45 @@ impl VectorCompareOp {
pub enum VectorAluVop3Op {
/// `v_add_nc_u32_e64` (VOP3 opcode 293).
AddNcU32,
/// `v_mul_i32_i24_e64` (VOP3 opcode 265).
MulI32I24,
/// `v_mul_hi_i32_i24_e64` (VOP3 opcode 266).
MulHiI32I24,
/// `v_mul_u32_u24_e64` (VOP3 opcode 267).
MulU32U24,
/// `v_mul_hi_u32_u24_e64` (VOP3 opcode 268).
MulHiU32U24,
/// `v_min_i32_e64` (VOP3 opcode 273).
MinI32,
/// `v_max_i32_e64` (VOP3 opcode 274).
MaxI32,
/// `v_min_u32_e64` (VOP3 opcode 275).
MinU32,
/// `v_max_u32_e64` (VOP3 opcode 276).
MaxU32,
/// `v_xnor_b32_e64` (VOP3 opcode 286).
XnorB32,
/// `v_sub_nc_u32_e64` (VOP3 opcode 294).
SubNcU32,
/// `v_subrev_nc_u32_e64` (VOP3 opcode 295).
SubrevNcU32,
}
impl VectorAluVop3Op {
/// Every variant, in registry order.
pub const ALL: [Self; 1] = [
pub const ALL: [Self; 12] = [
Self::AddNcU32,
Self::MulI32I24,
Self::MulHiI32I24,
Self::MulU32U24,
Self::MulHiU32U24,
Self::MinI32,
Self::MaxI32,
Self::MinU32,
Self::MaxU32,
Self::XnorB32,
Self::SubNcU32,
Self::SubrevNcU32,
];
/// Selects the variant from the first word of its VOP3 encoding: the
@@ -1893,7 +1926,18 @@ impl VectorAluVop3Op {
return None;
}
match (word >> 16) & 0x3ff {
265 => Some(Self::MulI32I24),
266 => Some(Self::MulHiI32I24),
267 => Some(Self::MulU32U24),
268 => Some(Self::MulHiU32U24),
273 => Some(Self::MinI32),
274 => Some(Self::MaxI32),
275 => Some(Self::MinU32),
276 => Some(Self::MaxU32),
286 => Some(Self::XnorB32),
293 => Some(Self::AddNcU32),
294 => Some(Self::SubNcU32),
295 => Some(Self::SubrevNcU32),
_ => None,
}
}
@@ -1902,6 +1946,17 @@ impl VectorAluVop3Op {
pub const fn base(self) -> VectorAluOp {
match self {
Self::AddNcU32 => VectorAluOp::AddNcU32,
Self::MulI32I24 => VectorAluOp::MulI32I24,
Self::MulHiI32I24 => VectorAluOp::MulHiI32I24,
Self::MulU32U24 => VectorAluOp::MulU32U24,
Self::MulHiU32U24 => VectorAluOp::MulHiU32U24,
Self::MinI32 => VectorAluOp::MinI32,
Self::MaxI32 => VectorAluOp::MaxI32,
Self::MinU32 => VectorAluOp::MinU32,
Self::MaxU32 => VectorAluOp::MaxU32,
Self::XnorB32 => VectorAluOp::XnorB32,
Self::SubNcU32 => VectorAluOp::SubNcU32,
Self::SubrevNcU32 => VectorAluOp::SubrevNcU32,
}
}
@@ -1909,6 +1964,17 @@ impl VectorAluVop3Op {
pub const fn assembly_name(self) -> &'static str {
match self {
Self::AddNcU32 => "v_add_nc_u32_e64",
Self::MulI32I24 => "v_mul_i32_i24_e64",
Self::MulHiI32I24 => "v_mul_hi_i32_i24_e64",
Self::MulU32U24 => "v_mul_u32_u24_e64",
Self::MulHiU32U24 => "v_mul_hi_u32_u24_e64",
Self::MinI32 => "v_min_i32_e64",
Self::MaxI32 => "v_max_i32_e64",
Self::MinU32 => "v_min_u32_e64",
Self::MaxU32 => "v_max_u32_e64",
Self::XnorB32 => "v_xnor_b32_e64",
Self::SubNcU32 => "v_sub_nc_u32_e64",
Self::SubrevNcU32 => "v_subrev_nc_u32_e64",
}
}
@@ -1916,12 +1982,23 @@ impl VectorAluVop3Op {
pub fn semantics(self) -> &'static FormSemantics {
&FORMS[match self {
Self::AddNcU32 => 84,
Self::MulI32I24 => 85,
Self::MulHiI32I24 => 86,
Self::MulU32U24 => 87,
Self::MulHiU32U24 => 88,
Self::MinI32 => 89,
Self::MaxI32 => 90,
Self::MinU32 => 91,
Self::MaxU32 => 92,
Self::XnorB32 => 93,
Self::SubNcU32 => 94,
Self::SubrevNcU32 => 95,
}]
}
}
/// Identity of every registry form and encoding variant, in registry order.
pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
pub const FORM_IDS: [(&str, EncodingFamily); 96] = [
("S_ADD_U32", EncodingFamily::Sop2),
("S_SUB_U32", EncodingFamily::Sop2),
("S_ADD_I32", EncodingFamily::Sop2),
@@ -2007,10 +2084,21 @@ pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
("V_CMP_F_U32", EncodingFamily::Vopc),
("V_CMP_T_U32", EncodingFamily::Vopc),
("V_ADD_NC_U32", EncodingFamily::Vop3),
("V_MUL_I32_I24", EncodingFamily::Vop3),
("V_MUL_HI_I32_I24", EncodingFamily::Vop3),
("V_MUL_U32_U24", EncodingFamily::Vop3),
("V_MUL_HI_U32_U24", EncodingFamily::Vop3),
("V_MIN_I32", EncodingFamily::Vop3),
("V_MAX_I32", EncodingFamily::Vop3),
("V_MIN_U32", EncodingFamily::Vop3),
("V_MAX_U32", EncodingFamily::Vop3),
("V_XNOR_B32", EncodingFamily::Vop3),
("V_SUB_NC_U32", EncodingFamily::Vop3),
("V_SUBREV_NC_U32", EncodingFamily::Vop3),
];
/// One validated row per registry form, in registry order.
pub static FORMS: [FormSemantics; 85] = [
pub static FORMS: [FormSemantics; 96] = [
FormSemantics {
name: "S_ADD_U32",
family: EncodingFamily::Sop2,
@@ -3796,4 +3884,235 @@ pub static FORMS: [FormSemantics; 85] = [
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MUL_I32_I24",
family: EncodingFamily::Vop3,
opcode: 265,
operation: Operation::Multiply24,
signedness: Signedness::Signed,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 131 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MUL_HI_I32_I24",
family: EncodingFamily::Vop3,
opcode: 266,
operation: Operation::MultiplyHigh24,
signedness: Signedness::Signed,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MUL_U32_U24",
family: EncodingFamily::Vop3,
opcode: 267,
operation: Operation::Multiply24,
signedness: Signedness::Unsigned,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MUL_HI_U32_U24",
family: EncodingFamily::Vop3,
opcode: 268,
operation: Operation::MultiplyHigh24,
signedness: Signedness::Unsigned,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MIN_I32",
family: EncodingFamily::Vop3,
opcode: 273,
operation: Operation::Minimum,
signedness: Signedness::Signed,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MAX_I32",
family: EncodingFamily::Vop3,
opcode: 274,
operation: Operation::Maximum,
signedness: Signedness::Signed,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MIN_U32",
family: EncodingFamily::Vop3,
opcode: 275,
operation: Operation::Minimum,
signedness: Signedness::Unsigned,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_MAX_U32",
family: EncodingFamily::Vop3,
opcode: 276,
operation: Operation::Maximum,
signedness: Signedness::Unsigned,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_XNOR_B32",
family: EncodingFamily::Vop3,
opcode: 286,
operation: Operation::Xnor,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_SUB_NC_U32",
family: EncodingFamily::Vop3,
opcode: 294,
operation: Operation::Sub,
signedness: Signedness::Unsigned,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
FormSemantics {
name: "V_SUBREV_NC_U32",
family: EncodingFamily::Vop3,
opcode: 295,
operation: Operation::Sub,
signedness: Signedness::Unsigned,
carry_in: CarryIn::None,
width: 32,
shift_count_bits: 0,
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::Vop3Vgpr2,
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
},
];
+14
View File
@@ -350,6 +350,20 @@ fn vector_integer_forms_lower_to_per_lane_templates() {
);
}
#[test]
fn vop3_integer_forms_lower_to_per_lane_templates() {
let code = include_bytes!("../../../fixtures/rdna2/vop3-integer.bin");
let compiled = compile(Architecture::Gfx1030, code).unwrap();
assert_eq!(
compiled.ir,
include_str!("../../../fixtures/golden/vop3-integer.ir")
);
assert_eq!(
compiled.msl,
include_str!("../../../fixtures/golden/vop3-integer.metal")
);
}
#[test]
fn vector_f_and_t_compares_lower_to_operand_free_wave_masks() {
let code = include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin");
+2 -2
View File
@@ -32,11 +32,11 @@ acceptance remain outside the verified count. All results concern synthetic fixt
| 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 |
| VOP3 | 416 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 12 |
| VOP3 | 416 | 1 | 12 | 12 | 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 | 96 | 119 | 104 | 104 | 18 | 18 | 56 |
## Unsupported operand variants
+23
View File
@@ -0,0 +1,23 @@
0000: t0 = load.u32 input[index]
000c: t1 = mul24.i32 t0, t0
0014: t2 = mulhi24.i32 t1, t0
001c: t3 = mul24.u32 t1, t0
0024: t4 = mulhi24.u32 t3, t0
002c: t5 = min.i32 t0, t1
0034: t6 = max.i32 t0, t3
003c: t7 = min.u32 t2, t0
0044: t8 = max.u32 t4, t1
004c: t9 = xnor.b32 t0, t4
0054: t10 = sub.u32 t5, t9
005c: t11 = sub.u32 t8, t0
0064: t12 = xor.b32 t1, t2
0068: t13 = xor.b32 t3, t12
006c: t14 = xor.b32 t4, t13
0070: t15 = xor.b32 t5, t14
0074: t16 = xor.b32 t6, t15
0078: t17 = xor.b32 t7, t16
007c: t18 = xor.b32 t8, t17
0080: t19 = xor.b32 t9, t18
0084: t20 = xor.b32 t10, t19
0088: t21 = xor.b32 t11, t20
008c: store.u32 output[index], t21
+30
View File
@@ -0,0 +1,30 @@
#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 t1 = as_type<uint>((as_type<int>(t0 << 8u) >> 8)) * as_type<uint>((as_type<int>(t0 << 8u) >> 8));
uint t2 = as_type<uint>(mulhi((as_type<int>(t1 << 8u) >> 8), (as_type<int>(t0 << 8u) >> 8)));
uint t3 = (t1 & 0x00ffffffu) * (t0 & 0x00ffffffu);
uint t4 = mulhi((t3 & 0x00ffffffu), (t0 & 0x00ffffffu));
uint t5 = as_type<uint>(min(as_type<int>(t0), as_type<int>(t1)));
uint t6 = as_type<uint>(max(as_type<int>(t0), as_type<int>(t3)));
uint t7 = min(t2, t0);
uint t8 = max(t4, t1);
uint t9 = ~(t0 ^ t4);
uint t10 = t5 - t9;
uint t11 = t8 - t0;
uint t12 = t1 ^ t2;
uint t13 = t3 ^ t12;
uint t14 = t4 ^ t13;
uint t15 = t5 ^ t14;
uint t16 = t6 ^ t15;
uint t17 = t7 ^ t16;
uint t18 = t8 ^ t17;
uint t19 = t9 ^ t18;
uint t20 = t10 ^ t19;
uint t21 = t11 ^ t20;
output[index] = t21;
}
Binary file not shown.
+31
View File
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Original VOP3A vectors for the eleven per-lane integer encoding variants.
// All arithmetic operands are vector general-purpose registers (VGPRs) and every result
// depends on the lane's own input word. XOR folds the results into one word.
.text
buffer_load_dword v1, v0, s[0:3], 0 idxen // Load the lane's input word.
s_waitcnt vmcnt(0) // Wait for the load.
v_mul_i32_i24_e64 v2, v1, v1 // Multiply signed 24-bit inputs and keep the low word.
v_mul_hi_i32_i24_e64 v3, v2, v1 // Multiply signed 24-bit inputs and keep the high word.
v_mul_u32_u24_e64 v4, v2, v1 // Multiply unsigned 24-bit inputs and keep the low word.
v_mul_hi_u32_u24_e64 v255, v4, v1 // Multiply unsigned 24-bit inputs and keep the high word.
v_min_i32_e64 v6, v1, v2 // Select the signed minimum.
v_max_i32_e64 v7, v1, v4 // Select the signed maximum.
v_min_u32_e64 v8, v3, v1 // Select the unsigned minimum.
v_max_u32_e64 v9, v255, v2 // Select the unsigned maximum.
v_xnor_b32_e64 v10, v1, v255 // Complement the XOR.
v_sub_nc_u32_e64 v11, v6, v10 // Subtract the second source from the first.
v_subrev_nc_u32_e64 v1, v1, v9 // Subtract the first source from the second, overwriting the first.
v_xor_b32_e32 v13, v2, v3 // Start the XOR fold.
v_xor_b32_e32 v13, v4, v13 // Fold the unsigned product low word.
v_xor_b32_e32 v13, v255, v13 // Fold the unsigned product high word.
v_xor_b32_e32 v13, v6, v13 // Fold the signed minimum.
v_xor_b32_e32 v13, v7, v13 // Fold the signed maximum.
v_xor_b32_e32 v13, v8, v13 // Fold the unsigned minimum.
v_xor_b32_e32 v13, v9, v13 // Fold the unsigned maximum.
v_xor_b32_e32 v13, v10, v13 // Fold the XNOR result.
v_xor_b32_e32 v13, v11, v13 // Fold the subtraction result.
v_xor_b32_e32 v13, v1, v13 // Fold the reverse subtraction result.
buffer_store_dword v13, v0, s[4:7], 0 idxen // Store the folded word.
s_waitcnt_vscnt null, 0 // Wait for the store.
s_endpgm // End the program.
+1 -1
View File
@@ -12,7 +12,7 @@ case "${1:-}" in
esac
for name in add bitwise-branch float-exact or shifts ashr \
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith vector-integer vector-compare-ft; do
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith vector-integer vector-compare-ft vop3-integer; 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"