Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,9 @@ impl Em {
return Err("VOPC");
}
let (mut ua, mut ub) = (u[0].clone(), u[1].clone());
let half = |i: u64, s: &str| if m.opsel >> i & 1 == 1 { format!("(({s}) >> 16)") } else { format!("(({s}) & 0xFFFFu)") };
// RDNA2's 16-bit compares read both sources from the low halves whatever op_sel says
// (measured on gfx1036, #1293); class was not measured and keeps op_sel
let half = |i: u64, s: &str| if op == "class" && m.opsel >> i & 1 == 1 { format!("(({s}) >> 16)") } else { format!("(({s}) & 0xFFFFu)") };
let ty = match ty {
"f16" => {
// compare in f32: exact for every f16 value (class keeps the f16 view)
Expand Down
31 changes: 31 additions & 0 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7168,6 +7168,37 @@ fn gpu_cmp_class_f16_preserves_snan() {
}
}

/// 16-bit compares take both sources from the low halves: RDNA2 ignores op_sel on them (#1293).
#[test]
fn gpu_cmp_16_ignores_op_sel() {
for wave64 in gpu_waves() {
let p = prog(&[
// low halves 1.0 < 1.5 (the high ones, 2.0 < 1.0, would be false)
("V_CMP_LT_F16", "ENC_VOP3", &[("VDST", 0), ("SRC0", V + 0), ("SRC1", V + 1), ("OP_SEL", 0b01)], None),
("V_CMP_LT_F16", "ENC_VOP3", &[("VDST", 2), ("SRC0", V + 0), ("SRC1", V + 1), ("OP_SEL", 0b10)], None),
// low halves 5 > 2 (high: 1 > 9)
("V_CMP_GT_U16", "ENC_VOP3", &[("VDST", 4), ("SRC0", V + 2), ("SRC1", V + 3), ("OP_SEL", 0b11)], None),
// low halves -1 < 0 (high: 32767 < -32768)
("V_CMP_LT_I16", "ENC_VOP3", &[("VDST", 6), ("SRC0", V + 4), ("SRC1", V + 5), ("OP_SEL", 0b01)], None),
]);
let mut st = KernelState::default();
for r in st.vgpr.iter_mut() {
r[0] = 0x4000_3C00; // f16 2.0 : 1.0
r[1] = 0x3C00_3E00; // f16 1.0 : 1.5
r[2] = 0x0001_0005;
r[3] = 0x0009_0002;
r[4] = 0x7FFF_FFFF;
r[5] = 0x8000_0000;
}
let (r, lanes) = run_wave(&p, &st, wave64);
let all = (u32::MAX, if wave64 { u32::MAX } else { 0 });
assert_eq!((r.sgpr[0], r.sgpr[1]), all, "wave{lanes} v_cmp_lt_f16 op_sel:[1,0]");
assert_eq!((r.sgpr[2], r.sgpr[3]), all, "wave{lanes} v_cmp_lt_f16 op_sel:[0,1]");
assert_eq!((r.sgpr[4], r.sgpr[5]), all, "wave{lanes} v_cmp_gt_u16 op_sel:[1,1]");
assert_eq!((r.sgpr[6], r.sgpr[7]), all, "wave{lanes} v_cmp_lt_i16 op_sel:[1,0]");
}
}

#[test]
fn wave32_src_vccz_execz_and_saveexec_b32_hlsl() {
let w32_code = prog(&[
Expand Down
Loading