Shaders: lower v_cmp_class_f16 and v_cmpx_class_f16
This commit is contained in:
1 parent
4c0bb89788
commit
1823079f6c
2 files changed
+108
-16
No files matched your search
@@ -673,3 +673,73 @@ fn bfe_signed_and_unsigned_match_rdna2() {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v_cmp_class_f16_matches_rdna2() {
|
||||
// v_cmp_class_f16_e64 s6, v1, v2 (VOP3 opcode 0x08f); v_cndmask_b32_e64 v0, 0, 1, s6
|
||||
let cmp_lo = build_valu_cs(&[
|
||||
vop3(0x08f, 6, vgpr(1), vgpr(2), 0)[0],
|
||||
vop3(0x08f, 6, vgpr(1), vgpr(2), 0)[1],
|
||||
vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0],
|
||||
vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1],
|
||||
]);
|
||||
// Same with op_sel:[1,0] (high half of v1) + neg on src0 (bit 29 of w1).
|
||||
let [mut w0, mut w1] = vop3(0x08f, 6, vgpr(1), vgpr(2), 0);
|
||||
w0 |= 1 << 11; // opsel[0] = 1 (high half)
|
||||
w1 |= 1 << 29; // neg[0] = 1
|
||||
let cmp_hi_neg = build_valu_cs(&[
|
||||
w0,
|
||||
w1,
|
||||
vop3(0x101, 0, 0x80, 0x81, sgpr(6))[0],
|
||||
vop3(0x101, 0, 0x80, 0x81, sgpr(6))[1],
|
||||
]);
|
||||
|
||||
// All 10 IEEE-754 binary16 classes: bit k corresponds to class k.
|
||||
let classes: &[(u32, u32)] = &[
|
||||
(0x7C01, 0), // sNaN (+sNaN, quiet bit 0x0200 clear)
|
||||
(0xFDFF, 0), // -sNaN (sign ignored for NaNs)
|
||||
(0x7E00, 1), // +qNaN
|
||||
(0xFE01, 1), // -qNaN
|
||||
(0xFC00, 2), // -inf
|
||||
(0xBC00, 3), // -normal (-1.0)
|
||||
(0x8001, 4), // -denormal
|
||||
(0x8000, 5), // -0.0
|
||||
(0x0000, 6), // +0.0
|
||||
(0x0001, 7), // +denormal
|
||||
(0x3C00, 8), // +normal (+1.0)
|
||||
(0x7C00, 9), // +inf
|
||||
];
|
||||
let mut cases = Vec::new();
|
||||
for &(bits, cls) in classes {
|
||||
// Exact class bit -> true; complement of class bit across all 10 bits -> false.
|
||||
cases.push(([bits, 1u32 << cls, 0, 0], 1u32));
|
||||
cases.push(([bits, 0x3FF & !(1u32 << cls), 0, 0], 0u32));
|
||||
}
|
||||
let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect();
|
||||
run_cases(&cmp_lo, &inputs, |backend, i, inp, got| {
|
||||
let want = cases[i].1;
|
||||
assert_eq!(
|
||||
got, want,
|
||||
"{backend}: v_cmp_class_f16({:#06x}, {:#05x}) = {got}, want {want}",
|
||||
inp[0], inp[1],
|
||||
);
|
||||
});
|
||||
|
||||
// High half with neg: high half 0x3C00 (+1.0) negated -> -normal (class 3);
|
||||
// high half 0x7C01 (+sNaN) negated -> still sNaN (class 0, not quieted).
|
||||
let hi_cases: &[([u32; 4], u32)] = &[
|
||||
([0x3C00_0000, 1 << 3, 0, 0], 1),
|
||||
([0x3C00_0000, 1 << 8, 0, 0], 0),
|
||||
([0x7C01_FFFF, 1 << 0, 0, 0], 1),
|
||||
([0x7C01_FFFF, 1 << 1, 0, 0], 0),
|
||||
];
|
||||
let hi_in: Vec<[u32; 4]> = hi_cases.iter().map(|c| c.0).collect();
|
||||
run_cases(&cmp_hi_neg, &hi_in, |backend, i, inp, got| {
|
||||
let want = hi_cases[i].1;
|
||||
assert_eq!(
|
||||
got, want,
|
||||
"{backend}: v_cmp_class_f16(-hi({:#010x}), {:#05x}) = {got}, want {want}",
|
||||
inp[0], inp[1],
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user