diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 6a33802..fe8450f 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -2443,15 +2443,17 @@ impl Em { } } let u64v = |i: usize| format!("(((uint64_t){} << 32) | (uint64_t){})", lo_hi[i].1, lo_hi[i].0); + // abs / neg on the sign bit, as the hardware applies them: `-x` is `fsub -0.0, x` in + // DXIL, which leaves the sign of a NaN to the driver let f64v = |i: usize| { - let mut s = format!("asdouble({}, {})", lo_hi[i].0, lo_hi[i].1); + let mut hi = lo_hi[i].1.clone(); if m.abs[i.min(2)] { - s = format!("abs({s})"); + hi = format!("({hi} & 0x7FFFFFFFu)"); } if m.neg[i.min(2)] { - s = format!("(-{s})"); + hi = format!("({hi} ^ 0x80000000u)"); } - s + format!("asdouble({}, {hi})", lo_hi[i].0) }; let dst = outs.first().map(|o| Self::dst_of(d, o)).unwrap_or(Dst::Null); let t = self.t(); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 5a1757f..075cc8f 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -437,8 +437,8 @@ fn f64_class_compare_vopc_and_vop3() { // SRC0 is the 64-bit f64 operand (VGPR/SGPR pair), SRC1 stays a plain 32-bit mask; // abs/neg act on the double operand only assert!(t.hlsl.contains("(v12) >> fclass64(asdouble(v10, v11))"), "{}", t.hlsl); - assert!(t.hlsl.contains("(v12) >> fclass64(abs(asdouble(v10, v11)))"), "{}", t.hlsl); - assert!(t.hlsl.contains("(v13) >> fclass64((-asdouble(v10, v11)))"), "{}", t.hlsl); + assert!(t.hlsl.contains("(v12) >> fclass64(asdouble(v10, (v11 & 0x7FFFFFFFu)))"), "{}", t.hlsl); + assert!(t.hlsl.contains("(v13) >> fclass64(asdouble(v10, (v11 ^ 0x80000000u)))"), "{}", t.hlsl); // mask destinations go through the shared compare/write-mask path: vcc, an SGPR pair, exec assert!(t.hlsl.contains("vcc_lo = t") && t.hlsl.contains("vcc_hi = t"), "{}", t.hlsl); assert!(t.hlsl.contains("s20 = t") && t.hlsl.contains("s21 = t"), "{}", t.hlsl); @@ -536,8 +536,8 @@ fn frexp_f64_instructions() { // the source pair becomes a double; the mantissa stays f64, the exponent is one dword assert!(t.hlsl.contains("frexp_mant_d(asdouble(v10, v11))"), "{}", t.hlsl); assert!(t.hlsl.contains("(uint)frexp_exp_d(asdouble(v10, v11))"), "{}", t.hlsl); - assert!(t.hlsl.contains("frexp_mant_d((-asdouble(v10, v11)))"), "{}", t.hlsl); - assert!(t.hlsl.contains("frexp_exp_d(abs(asdouble(v10, v11)))"), "{}", t.hlsl); + assert!(t.hlsl.contains("frexp_mant_d(asdouble(v10, (v11 ^ 0x80000000u)))"), "{}", t.hlsl); + assert!(t.hlsl.contains("frexp_exp_d(asdouble(v10, (v11 & 0x7FFFFFFFu)))"), "{}", t.hlsl); // the f64 pair of inline −1.0 = 0xBFF0000000000000 assert!(t.hlsl.contains("frexp_mant_d(asdouble(0x00000000u, 0xBFF00000u))"), "{}", t.hlsl); if super::dxc::location().is_ok() { @@ -554,7 +554,7 @@ fn rndne_f64_instructions() { let t = translate(&code, &Options::default()).unwrap(); assert!(t.complete(), "{:?}\n{}", t.unsupported_why, t.hlsl); assert!(t.hlsl.contains("round_ne_d(asdouble(v10, v11))"), "{}", t.hlsl); - assert!(t.hlsl.contains("round_ne_d((-asdouble(v10, v11)))"), "{}", t.hlsl); + assert!(t.hlsl.contains("round_ne_d(asdouble(v10, (v11 ^ 0x80000000u)))"), "{}", t.hlsl); if super::dxc::location().is_ok() { super::dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl)); } @@ -587,7 +587,7 @@ fn gpu_rndne_f64() { #[test] fn gpu_frexp_f64_exp_and_mant() { - if !gpu_ready() { + if !gpu_ready_wave32() { return; } let p = prog(&[