|
|
@@ -7077,6 +7077,50 @@ impl<'a> Lower<'a> {
|
|
|
let r = self.s.m.cast(c, op, a, self.s.t.i32);
|
|
|
int(self, r)
|
|
|
}
|
|
|
+ "v_permlane16_b32" | "v_permlanex16_b32" => {
|
|
|
+ // Each lane reads src0 of a lane of its own 32-lane half,
|
|
|
+ // picked by nibble (lane & 15) of {src2, src1}: within its
|
|
|
+ // own row of 16 (`v_permlane16`) or the other row of its
|
|
|
+ // half (`v_permlanex16`). The pick stays inside a half, so a
|
|
|
+ // console wave of 64 run as two host waves of 32 needs no
|
|
|
+ // exchange.
|
|
|
+ // shortcut: a source lane with EXEC clear is read as the host
|
|
|
+ // gives it (the console keeps vdst unless op_sel's fetch
|
|
|
+ // inactive bit is set).
|
|
|
+ self.cross_lane(false)?;
|
|
|
+ let x = s(self, 0)?;
|
|
|
+ let (s1, s2) = (s(self, 1)?, s(self, 2)?);
|
|
|
+ let i32t = self.s.t.i32;
|
|
|
+ let lane = self.s.op(c, "waveGetLaneIndex", Attr::ReadOnly, i32t, 111, &[]);
|
|
|
+ let [k15, k8, k7, k2, k16, not31, not15] =
|
|
|
+ [15, 8, 7, 2, 16, !31, !15].map(|x| self.s.m.i32(x));
|
|
|
+ let low = self.s.m.bin(c, Bin::And, lane, k15);
|
|
|
+ // nibble `low` of the 64-bit selector: src1 holds lanes 0-7
|
|
|
+ let hi_word = self.s.m.cmp(c, pred::IUGE, low, k8);
|
|
|
+ let word = self.s.m.select(c, hi_word, s2, s1);
|
|
|
+ let n = self.s.m.bin(c, Bin::And, low, k7);
|
|
|
+ let sh = self.s.m.bin(c, Bin::Shl, n, k2);
|
|
|
+ let pick = self.s.m.bin(c, Bin::LShr, word, sh);
|
|
|
+ let pick = self.s.m.bin(c, Bin::And, pick, k15);
|
|
|
+ let row = if name == "v_permlanex16_b32" {
|
|
|
+ // the other row of this half
|
|
|
+ let half = self.s.m.bin(c, Bin::And, lane, not31);
|
|
|
+ let other = self.s.m.bin(c, Bin::And, lane, k16);
|
|
|
+ let other = self.s.m.bin(c, Bin::Xor, other, k16);
|
|
|
+ self.s.m.bin(c, Bin::Or, half, other)
|
|
|
+ } else {
|
|
|
+ self.s.m.bin(c, Bin::And, lane, not15)
|
|
|
+ };
|
|
|
+ let from = self.s.m.bin(c, Bin::Or, row, pick);
|
|
|
+ let r = self.read_lane(x, from);
|
|
|
+ int(self, r)
|
|
|
+ }
|
|
|
+ "v_cvt_f32_f64" => {
|
|
|
+ let (lo, hi) = self.f64_pair(inst, 0)?;
|
|
|
+ let bits = self.f64_to_f32_bits(lo, hi);
|
|
|
+ let r = self.as_float(bits);
|
|
|
+ float(self, r)
|
|
|
+ }
|
|
|
"v_cvt_f32_i32" | "v_cvt_f32_u32" | "v_cvt_f32_ubyte0" | "v_cvt_f32_ubyte1"
|
|
|
| "v_cvt_f32_ubyte2" | "v_cvt_f32_ubyte3" => {
|
|
|
let mut a = s(self, 0)?;
|
|
|
@@ -7094,12 +7138,6 @@ impl<'a> Lower<'a> {
|
|
|
let r = self.s.m.cast(c, op, a, self.s.t.f32);
|
|
|
float(self, r)
|
|
|
}
|
|
|
- "v_cvt_f32_f64" => {
|
|
|
- let (lo, hi) = self.f64_pair(inst, 0)?;
|
|
|
- let bits = self.f64_to_f32_bits(lo, hi);
|
|
|
- let r = self.as_float(bits);
|
|
|
- float(self, r)
|
|
|
- }
|
|
|
"v_fma_mix_f32" | "v_fma_mixlo_f16" | "v_fma_mixhi_f16" => {
|
|
|
// Each source is f32, or with op_sel_hi the low (op_sel: high)
|
|
|
// f16 half; neg_hi is the absolute value here.
|
|
|
@@ -7631,6 +7669,69 @@ impl<'a> Lower<'a> {
|
|
|
self.s.m.bin(c, Bin::Or, lo, hi)
|
|
|
}
|
|
|
|
|
|
+ /// The bits of the float nearest the double whose dwords are `lo` and
|
|
|
+ /// `hi`, on 32-bit integers: round to nearest even, infinities and NaN
|
|
|
+ /// kept (a NaN stays quiet), a result below the smallest normal float
|
|
|
+ /// signed zero (flushed, as the console's default float mode does).
|
|
|
+ // The flush-to-zero form of v_cvt_f32_f64: kept beside the IEEE form in use until the console's
|
|
|
+ // float mode for this instruction is checked.
|
|
|
+ #[allow(dead_code)]
|
|
|
+ fn f64_bits_to_f32_bits(&mut self, lo: V, hi: V) -> V {
|
|
|
+ let c = self.cur;
|
|
|
+ let k = |l: &mut Self, x: u32| l.s.m.i32(x);
|
|
|
+ let (k20, k29, k3, k23) = (k(self, 20), k(self, 29), k(self, 3), k(self, 23));
|
|
|
+ let sign_mask = k(self, 0x8000_0000);
|
|
|
+ let sign = self.s.m.bin(c, Bin::And, hi, sign_mask);
|
|
|
+ let e = self.s.m.bin(c, Bin::LShr, hi, k20);
|
|
|
+ let e_mask = k(self, 0x7ff);
|
|
|
+ let e = self.s.m.bin(c, Bin::And, e, e_mask);
|
|
|
+ // The top 23 bits of the 52-bit mantissa, and the 29 below them.
|
|
|
+ let m_mask = k(self, 0x000f_ffff);
|
|
|
+ let mh = self.s.m.bin(c, Bin::And, hi, m_mask);
|
|
|
+ let mh = self.s.m.bin(c, Bin::Shl, mh, k3);
|
|
|
+ let ml = self.s.m.bin(c, Bin::LShr, lo, k29);
|
|
|
+ let m = self.s.m.bin(c, Bin::Or, mh, ml);
|
|
|
+ let rest_mask = k(self, 0x1fff_ffff);
|
|
|
+ let rest = self.s.m.bin(c, Bin::And, lo, rest_mask);
|
|
|
+ // Round to nearest even: up past half, or at half when odd.
|
|
|
+ let half = k(self, 0x1000_0000);
|
|
|
+ let one = k(self, 1);
|
|
|
+ let above = self.s.m.cmp(c, pred::IUGT, rest, half);
|
|
|
+ let at = self.s.m.cmp(c, pred::EQ, rest, half);
|
|
|
+ let odd = self.s.m.bin(c, Bin::And, m, one);
|
|
|
+ let zero = k(self, 0);
|
|
|
+ let odd = self.s.m.cmp(c, pred::NE, odd, zero);
|
|
|
+ let tie = self.s.m.bin(c, Bin::And, at, odd);
|
|
|
+ let up = self.s.m.bin(c, Bin::Or, above, tie);
|
|
|
+ let up = self.s.m.select(c, up, one, zero);
|
|
|
+ // Rebias the exponent (1023 → 127); a carry out of the mantissa
|
|
|
+ // steps the exponent, up to infinity.
|
|
|
+ let bias = k(self, 1023 - 127);
|
|
|
+ let e32 = self.s.m.bin(c, Bin::Sub, e, bias);
|
|
|
+ let ex = self.s.m.bin(c, Bin::Shl, e32, k23);
|
|
|
+ let normal = self.s.m.bin(c, Bin::Add, ex, m);
|
|
|
+ let normal = self.s.m.bin(c, Bin::Add, normal, up);
|
|
|
+ let normal = self.s.m.bin(c, Bin::Or, normal, sign);
|
|
|
+ // Exponents out of the float's range (signed, after rebiasing).
|
|
|
+ let inf = k(self, 0x7f80_0000);
|
|
|
+ let inf = self.s.m.bin(c, Bin::Or, inf, sign);
|
|
|
+ let k255 = k(self, 255);
|
|
|
+ let big = self.s.m.cmp(c, pred::SGE, e32, k255);
|
|
|
+ let small = self.s.m.cmp(c, pred::SLE, e32, zero);
|
|
|
+ let r = self.s.m.select(c, big, inf, normal);
|
|
|
+ let r = self.s.m.select(c, small, sign, r);
|
|
|
+ // Infinity and NaN (a NaN with any mantissa bit set stays a NaN).
|
|
|
+ let all = k(self, 0x7ff);
|
|
|
+ let special = self.s.m.cmp(c, pred::EQ, e, all);
|
|
|
+ let any = self.s.m.bin(c, Bin::Or, mh, ml);
|
|
|
+ let any = self.s.m.bin(c, Bin::Or, any, rest);
|
|
|
+ let nan = self.s.m.cmp(c, pred::NE, any, zero);
|
|
|
+ let quiet = k(self, 0x0040_0000);
|
|
|
+ let quiet = self.s.m.select(c, nan, quiet, zero);
|
|
|
+ let special_bits = self.s.m.bin(c, Bin::Or, inf, quiet);
|
|
|
+ self.s.m.select(c, special, special_bits, r)
|
|
|
+ }
|
|
|
+
|
|
|
/// The low and high dwords of an i64.
|
|
|
fn split64(&mut self, x: V) -> (V, V) {
|
|
|
let c = self.cur;
|