mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
recomp: f64 abs / neg modifiers on the sign bit (#72)
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.
Cherry-picked from #72 (ec446ec) without #71, which #67 superseded; the
test gates on gpu_ready (#67: wave64 programs run split on 32-lane GPUs).
This commit is contained in:
@@ -2534,15 +2534,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();
|
||||
|
||||
@@ -468,8 +468,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);
|
||||
@@ -567,8 +567,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() {
|
||||
@@ -585,7 +585,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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user