diff --git a/crates/xcl/src/gpu/dxil/lower_valu.rs b/crates/xcl/src/gpu/dxil/lower_valu.rs index d98e6a369c..4e457019ed 100644 --- a/crates/xcl/src/gpu/dxil/lower_valu.rs +++ b/crates/xcl/src/gpu/dxil/lower_valu.rs @@ -1421,31 +1421,12 @@ impl Lw { }) } - /// Float compare: single-instruction IEEE-754 ordered/unordered `fcmp` for `f32`, - /// explicit `isnan_d` for `f64`. + /// The recompiler's `float_compare`: NaN tested explicitly, so the result does not depend on + /// what a driver makes of an `fcmp` of a NaN. AMD's (RX 6700 XT, 32.0.21045.29003) takes + /// `fcmp one` for `une`, and gives the second of two compares of the same operands that differ + /// only in ordered / unordered (`olt` and `ult`) the first one's result; WARP runs the same + /// DXIL right. pub fn float_compare(&mut self, opn: &str, a: Value, b: Value) -> Option { - let is_f32 = self.s.m.type_of(a) == self.s.m.f32(); - if is_f32 { - return Some(match opn { - "f" => self.b(false), - "t" | "tru" => self.b(true), - "lt" => self.fcmp(Pred::FOLt, a, b), - "eq" => self.fcmp(Pred::FOEq, a, b), - "le" => self.fcmp(Pred::FOLe, a, b), - "gt" => self.fcmp(Pred::FOGt, a, b), - "ge" => self.fcmp(Pred::FOGe, a, b), - "lg" => self.fcmp(Pred::FONe, a, b), - "o" => self.fcmp(Pred::FOrd, a, b), - "u" => self.fcmp(Pred::FUno, a, b), - "nlt" => self.fcmp(Pred::FUGe, a, b), - "neq" => self.fcmp(Pred::FUNe, a, b), - "nle" => self.fcmp(Pred::FUGt, a, b), - "ngt" => self.fcmp(Pred::FULe, a, b), - "nge" => self.fcmp(Pred::FULt, a, b), - "nlg" => self.fcmp(Pred::FUEq, a, b), - _ => return None, - }); - } let rel = |s: &mut Self, r: &str| -> Option { Some(match r { "lt" => s.fcmp(Pred::FOLt, a, b), @@ -1549,6 +1530,37 @@ impl Lw { } } +#[cfg(test)] +mod float_compare_tests { + use super::super::kernel::{translate, KernelOptions}; + use super::super::validate; + use crate::gpu::rdna2::encode; + use crate::gpu::recomp::{dxc, runner}; + + /// The predicates `float_compare` must leave out (its comment says why), without a GPU: + /// the GPU tests (`gpu_f32_compares_with_nan`) only fail on an AMD driver. + #[test] + fn f32_compares_use_no_predicate_that_amd_merges() { + if dxc::location().is_err() { + return runner::skip_test("no DXC"); + } + let mut code = Vec::new(); + for (i, op) in ["LT", "EQ", "LE", "GT", "LG", "GE", "O", "U", "NGE", "NLG", "NGT", "NLE", "NEQ", "NLT"].into_iter().enumerate() { + code.extend(encode(&format!("V_CMP_{op}_F32"), "ENC_VOP3", &[("VDST", 20 + 2 * i as u64), ("SRC0", 256), ("SRC1", 257)], None).unwrap()); + } + code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap()); + for wave64 in [false, true] { + let dxil = translate(&code, KernelOptions { wave64, split: false, mem_windows: 1, sampler_base: 0 }).expect("translate f32 compares"); + validate::validate(&dxil).expect("validate f32 compares"); + let dis = validate::disassemble(&dxil).expect("disassemble f32 compares"); + assert!(dis.contains("fcmp olt float"), "{dis}"); + for p in ["one", "ueq", "ugt", "uge", "ult", "ule"] { + assert!(!dis.contains(&format!("fcmp {p} float")), "wave64 {wave64}: fcmp {p}\n{dis}"); + } + } + } +} + #[cfg(test)] mod valu_carry_tests { use super::super::kernel::{self, KernelOptions};