Merge upstream main (42361b0) into shader/per-lane-phi

main moved under #307 and this branch. One conflict, in the test module of
emit/lower.rs: the imports take both sides' names (#117's `half_shift`
beside `Lowered`), and #117's `scalar_bit_tests_lower` sits after this
branch's waterfall tests. No code outside the test module was touched by
hand. A merge rather than a rebase so #307's commits keep their ids.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
r4.andClaude Fable 5.2 committed 2026-11-24 10:03:16 +02:00
commit 89639f014c
24 files changed
+1363 -191

No files matched your search

@@ -674,3 +674,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],
);
});
}