recomp: f64 abs / neg modifiers on the sign bit

The f64 NEG source modifier was emitted as -x and ABS as abs(x). DXIL
has no fneg: DXC writes -x as fsub -0.0, x, and IEEE leaves the sign
of a NaN result open, so a negated NaN kept its sign on NVIDIA
(v_frexp_mant_f64 with NEG on 0x7FF8000000000001). The hardware
modifiers only flip or clear the sign bit; they are now that, on the
high dword.
This commit is contained in:
gefydev
2026-11-22 21:28:01 -03:00
parent a81bb28622
commit ec446ece4b
2 changed files with 12 additions and 10 deletions
+6 -4
View File
@@ -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();
+6 -6
View File
@@ -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(&[