fixtures, decoder, shader: LLVM-assembled fixture and goldens for the eleven VOP3 VOP2 variants (#215)

Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
elforeign committed 2026-11-24 08:26:44 -06:00
1 parent 9bdf747bd4
commit 00cda8ad7b
7 files changed
+138 -1

No files matched your search

+39
View File
@@ -1088,6 +1088,45 @@ fn decodes_registry_vop3_integer_encodings() {
}
}
#[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 {
+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");
+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"