|
@@ -1337,6 +1337,25 @@ impl<'a> Lower<'a> {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// The hardware's maximum (`max`) or minimum of two floats: as DXIL's
|
|
|
|
|
+ /// FMax/FMin, but -0 orders below +0 (RDNA2 ISA, `v_max_f32`), where
|
|
|
|
|
+ /// the compare and select DXIL specifies gives either zero.
|
|
|
|
|
+ fn max_min(&mut self, max: bool, a: V, b: V) -> V {
|
|
|
|
|
+ let c = self.cur;
|
|
|
|
|
+ let r = self.binary(if max { 35 } else { 36 }, a, b);
|
|
|
|
|
+ let (ia, ib) = (self.as_int(a), self.as_int(b));
|
|
|
|
|
+ let either = self.s.m.bin(c, Bin::Or, ia, ib);
|
|
|
|
|
+ let magnitude = self.s.m.i32(0x7FFF_FFFF);
|
|
|
|
|
+ let either = self.s.m.bin(c, Bin::And, either, magnitude);
|
|
|
|
|
+ let zero = self.s.m.i32(0);
|
|
|
|
|
+ let zeros = self.s.m.cmp(c, pred::EQ, either, zero);
|
|
|
|
|
+ // Of two zeros, +0 unless both are -0 (max), -0 unless neither (min).
|
|
|
|
|
+ let op = if max { Bin::And } else { Bin::Or };
|
|
|
|
|
+ let sign = self.s.m.bin(c, op, ia, ib);
|
|
|
|
|
+ let signed = self.as_float(sign);
|
|
|
|
|
+ self.s.m.select(c, zeros, signed, r)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fn fmad(&mut self, a: V, b: V, c: V) -> V {
|
|
fn fmad(&mut self, a: V, b: V, c: V) -> V {
|
|
|
self.s.op(
|
|
self.s.op(
|
|
|
self.cur,
|
|
self.cur,
|
|
@@ -3673,8 +3692,8 @@ impl<'a> Lower<'a> {
|
|
|
"v_subrev_f32" => self.s.m.bin(c, Bin::Sub, bb, a),
|
|
"v_subrev_f32" => self.s.m.bin(c, Bin::Sub, bb, a),
|
|
|
"v_mul_f32" => self.s.m.bin(c, Bin::Mul, a, bb),
|
|
"v_mul_f32" => self.s.m.bin(c, Bin::Mul, a, bb),
|
|
|
"v_mul_legacy_f32" => self.legacy_mul(a, bb),
|
|
"v_mul_legacy_f32" => self.legacy_mul(a, bb),
|
|
|
- "v_max_f32" => self.binary(35, a, bb),
|
|
|
|
|
- _ => self.binary(36, a, bb),
|
|
|
|
|
|
|
+ "v_max_f32" => self.max_min(true, a, bb),
|
|
|
|
|
+ _ => self.max_min(false, a, bb),
|
|
|
};
|
|
};
|
|
|
float(self, r)
|
|
float(self, r)
|
|
|
}
|
|
}
|
|
@@ -3724,12 +3743,12 @@ impl<'a> Lower<'a> {
|
|
|
let (a, bb, cc) = (f(self, 0)?, f(self, 1)?, f(self, 2)?);
|
|
let (a, bb, cc) = (f(self, 0)?, f(self, 1)?, f(self, 2)?);
|
|
|
let r = match name {
|
|
let r = match name {
|
|
|
"v_max3_f32" => {
|
|
"v_max3_f32" => {
|
|
|
- let t = self.binary(35, a, bb);
|
|
|
|
|
- self.binary(35, t, cc)
|
|
|
|
|
|
|
+ let t = self.max_min(true, a, bb);
|
|
|
|
|
+ self.max_min(true, t, cc)
|
|
|
}
|
|
}
|
|
|
"v_min3_f32" => {
|
|
"v_min3_f32" => {
|
|
|
- let t = self.binary(36, a, bb);
|
|
|
|
|
- self.binary(36, t, cc)
|
|
|
|
|
|
|
+ let t = self.max_min(false, a, bb);
|
|
|
|
|
+ self.max_min(false, t, cc)
|
|
|
}
|
|
}
|
|
|
_ => self.med3(a, bb, cc),
|
|
_ => self.med3(a, bb, cc),
|
|
|
};
|
|
};
|
|
@@ -4265,8 +4284,8 @@ impl<'a> Lower<'a> {
|
|
|
"v_sub_f16" => self.s.m.bin(c, Bin::Sub, a, b),
|
|
"v_sub_f16" => self.s.m.bin(c, Bin::Sub, a, b),
|
|
|
"v_subrev_f16" => self.s.m.bin(c, Bin::Sub, b, a),
|
|
"v_subrev_f16" => self.s.m.bin(c, Bin::Sub, b, a),
|
|
|
"v_mul_f16" => self.s.m.bin(c, Bin::Mul, a, b),
|
|
"v_mul_f16" => self.s.m.bin(c, Bin::Mul, a, b),
|
|
|
- "v_max_f16" => self.binary(35, a, b),
|
|
|
|
|
- _ => self.binary(36, a, b),
|
|
|
|
|
|
|
+ "v_max_f16" => self.max_min(true, a, b),
|
|
|
|
|
+ _ => self.max_min(false, a, b),
|
|
|
};
|
|
};
|
|
|
return float_result(self, r);
|
|
return float_result(self, r);
|
|
|
}
|
|
}
|
|
@@ -4296,12 +4315,12 @@ impl<'a> Lower<'a> {
|
|
|
// product is exact; the sum rounds twice).
|
|
// product is exact; the sum rounds twice).
|
|
|
"v_fma_f16" | "v_fmac_f16" | "v_mad_f16" | "v_mac_f16" => self.fmad(a, b, acc),
|
|
"v_fma_f16" | "v_fmac_f16" | "v_mad_f16" | "v_mac_f16" => self.fmad(a, b, acc),
|
|
|
"v_max3_f16" => {
|
|
"v_max3_f16" => {
|
|
|
- let t = self.binary(35, a, b);
|
|
|
|
|
- self.binary(35, t, acc)
|
|
|
|
|
|
|
+ let t = self.max_min(true, a, b);
|
|
|
|
|
+ self.max_min(true, t, acc)
|
|
|
}
|
|
}
|
|
|
"v_min3_f16" => {
|
|
"v_min3_f16" => {
|
|
|
- let t = self.binary(36, a, b);
|
|
|
|
|
- self.binary(36, t, acc)
|
|
|
|
|
|
|
+ let t = self.max_min(false, a, b);
|
|
|
|
|
+ self.max_min(false, t, acc)
|
|
|
}
|
|
}
|
|
|
_ => self.med3(a, b, acc),
|
|
_ => self.med3(a, b, acc),
|
|
|
};
|
|
};
|
|
@@ -4487,8 +4506,8 @@ impl<'a> Lower<'a> {
|
|
|
let mut f = match op {
|
|
let mut f = match op {
|
|
|
"add_f16" => self.s.m.bin(c, Bin::Add, xs[0], xs[1]),
|
|
"add_f16" => self.s.m.bin(c, Bin::Add, xs[0], xs[1]),
|
|
|
"mul_f16" => self.s.m.bin(c, Bin::Mul, xs[0], xs[1]),
|
|
"mul_f16" => self.s.m.bin(c, Bin::Mul, xs[0], xs[1]),
|
|
|
- "min_f16" => self.binary(36, xs[0], xs[1]),
|
|
|
|
|
- "max_f16" => self.binary(35, xs[0], xs[1]),
|
|
|
|
|
|
|
+ "min_f16" => self.max_min(false, xs[0], xs[1]),
|
|
|
|
|
+ "max_f16" => self.max_min(true, xs[0], xs[1]),
|
|
|
// shortcut: FMad in f32, as v_fma_f16.
|
|
// shortcut: FMad in f32, as v_fma_f16.
|
|
|
_ => self.fmad(xs[0], xs[1], xs[2]),
|
|
_ => self.fmad(xs[0], xs[1], xs[2]),
|
|
|
};
|
|
};
|