From 9a4550c0fcf71e04a667583af650c53b18c84031 Mon Sep 17 00:00:00 2001 From: b3IKK <278540256+b3IKK@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:16:39 +0000 Subject: [PATCH 1/2] Recompiler: honour OP_SEL[1] for SRC1 in v_cmp_class_f16 In V_CMP_CLASS_F16 (rdna2_spec.rs), SRC1 is a 16-bit operand so OP_SEL[1] == 1 selects its upper 16-bit half as the class mask. The emitter applied half(0, &ua) to SRC0 but passed ub unchanged, ignoring OP_SEL[1]. Select SRC1 via half(1, &ub), with a GPU test covering OP_SEL[1]=0/1 and OP_SEL=3 across wave32 and split wave64. Assisted-by: OpenCode (Gemini 4 Neon) --- crates/xcl/src/gpu/recomp/emit.rs | 2 +- crates/xcl/src/gpu/recomp/tests.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 96966005b..96b44b64c 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -3603,7 +3603,7 @@ impl Em { "f16" => { // compare in f32: exact for every f16 value (class keeps the f16 view) if op == "class" { - let (mut h, c) = (half(0, &ua), ub.clone()); + let (mut h, c) = (half(0, &ua), half(1, &ub)); if m.abs[0] { h = format!("({h} & 0x7FFFu)"); } diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index e1f73ef48..5971b41b7 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -7460,6 +7460,31 @@ fn gpu_sdwa_f16_inline_constants() { } } +#[test] +fn gpu_cmp_class_f16_honours_opsel1() { + for wave64 in gpu_waves() { + let p = prog(&[ + // v0 = +1.0h (class bit 8 = 0x0100), v1 = 0x0100_0000 (class mask in high 16 bits), OP_SEL=2 (op_sel[1]=1) -> true + ("V_CMP_CLASS_F16", "ENC_VOP3", &[("VDST", 0), ("SRC0", V + 0), ("SRC1", V + 1), ("OP_SEL", 2)], None), + // same v0, v1 with OP_SEL=0 (low 16 bits = 0) -> false + ("V_CMP_CLASS_F16", "ENC_VOP3", &[("VDST", 2), ("SRC0", V + 0), ("SRC1", V + 1), ("OP_SEL", 0)], None), + // both OP_SEL=3: high half of v2 (+1.0h) tested against high half of v1 (1 << 8) -> true + ("V_CMP_CLASS_F16", "ENC_VOP3", &[("VDST", 4), ("SRC0", V + 2), ("SRC1", V + 1), ("OP_SEL", 3)], None), + ]); + let mut st = KernelState::default(); + for r in st.vgpr.iter_mut() { + r[0] = 0x0000_3C00; // lo = +1.0h + r[1] = 0x0100_0000; // hi = 1 << 8 (+normal), lo = 0 + r[2] = 0x3C00_0000; // hi = +1.0h, lo = +0.0h + } + 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_class_f16 OP_SEL[1]=1 reads high half of SRC1"); + assert_eq!((r.sgpr[2], r.sgpr[3]), (0, 0), "wave{lanes} v_cmp_class_f16 OP_SEL[1]=0 reads low half of SRC1"); + assert_eq!((r.sgpr[4], r.sgpr[5]), all, "wave{lanes} v_cmp_class_f16 OP_SEL=3 reads high halves of SRC0 and SRC1"); + } +} + #[test] fn fspx_compute_user_sgprs_from_rsrc2() { use crate::gpu::xbox::tests::container; From 8b5aea71c9e39d89b515c782b15a59e5031c69bf Mon Sep 17 00:00:00 2001 From: regiumlepidi <62513852+regiumlepidi@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:09:13 +0100 Subject: [PATCH 2/2] Recompiler: direct DXIL v_cmp_class_f16 reads the mask half OP_SEL[1] picks The direct DXIL translator (XCL_DIRECT_DXIL=1) shifted the whole 32-bit SRC1 by the class index in v_cmp_class_f16, so OP_SEL[1] never selected the mask's high half, as the HLSL path did before #1214. Take the half OP_SEL[1] picks, as #1214 does in the HLSL path. #1214's GPU test failed with XCL_DIRECT_DXIL=1 on an RTX 5070 Ti and passes with this change. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/dxil/lower_valu.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/gpu/dxil/lower_valu.rs b/crates/xcl/src/gpu/dxil/lower_valu.rs index beafdcd68..430969a8b 100644 --- a/crates/xcl/src/gpu/dxil/lower_valu.rs +++ b/crates/xcl/src/gpu/dxil/lower_valu.rs @@ -1200,7 +1200,9 @@ impl Lw { h = self.xor(h, k); } let cls = self.fclass16(h); - let s = self.bin(BinOp::LShr, ub, cls); + // the class mask is a 16-bit operand too: OP_SEL[1] picks its half + let mask = half(self, 1, ub); + let s = self.bin(BinOp::LShr, mask, cls); let s = self.andc(s, 1); let cond = self.nz(s); return self.vopc_write(d, cmpx, outs, cond);