|
|
@@ -1231,6 +1231,19 @@ impl<'a> Lower<'a> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// GFX10 puts an inline f16 constant in the low half of the operand.
|
|
|
+ fn f16_operand(&mut self, inst: &Inst, op: &Operand) -> Result<V, Why> {
|
|
|
+ match *op {
|
|
|
+ Operand::Const(c @ 240..=248) => {
|
|
|
+ let h = [
|
|
|
+ 0x3800, 0xB800, 0x3C00, 0xBC00, 0x4000, 0xC000, 0x4400, 0xC400, 0x3118,
|
|
|
+ ][usize::from(c - 240)];
|
|
|
+ Ok(self.s.m.i32(h))
|
|
|
+ }
|
|
|
+ _ => self.operand(inst, op),
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fn as_float(&mut self, x: V) -> V {
|
|
|
self.s.m.cast(self.cur, Cast::Bitcast, x, self.s.t.f32)
|
|
|
}
|
|
|
@@ -4147,15 +4160,9 @@ impl<'a> Lower<'a> {
|
|
|
_ => return Err("a byte select on a 16-bit operation"),
|
|
|
}
|
|
|
}
|
|
|
- let x = match (op, self.src0) {
|
|
|
- (_, Some(x)) if k == 0 => x,
|
|
|
- (Operand::Const(c @ 240..=248), _) => {
|
|
|
- let h = [
|
|
|
- 0x3800, 0xB800, 0x3C00, 0xBC00, 0x4000, 0xC000, 0x4400, 0xC400, 0x3118,
|
|
|
- ][usize::from(c - 240)];
|
|
|
- self.s.m.i32(h)
|
|
|
- }
|
|
|
- _ => self.operand(inst, &op)?,
|
|
|
+ let x = match self.src0 {
|
|
|
+ Some(x) if k == 0 => x,
|
|
|
+ _ => self.f16_operand(inst, &op)?,
|
|
|
};
|
|
|
let c = self.cur;
|
|
|
let x = if high {
|
|
|
@@ -4574,22 +4581,18 @@ impl<'a> Lower<'a> {
|
|
|
|
|
|
/// Half `high` of source `k` of a packed (VOP3P) operation, in the low
|
|
|
/// 16 bits: op_sel picks the half the low result reads, op_sel_hi the
|
|
|
- /// half the high result reads. Inline float constants are f16 values.
|
|
|
- fn packed_src(&mut self, inst: &Inst, k: usize, high: bool) -> Result<V, Why> {
|
|
|
+ /// half the high result reads. Packed integer instructions see the f32
|
|
|
+ /// bits of an inline float constant.
|
|
|
+ fn packed_src(&mut self, inst: &Inst, k: usize, high: bool, float: bool) -> Result<V, Why> {
|
|
|
let Fields::Valu(v) = &inst.fields else {
|
|
|
unreachable!()
|
|
|
};
|
|
|
let op = *v.src.get(k).ok_or("a missing operand")?;
|
|
|
let sel = if high { v.opsel_hi } else { v.opsel } >> k & 1 != 0;
|
|
|
- let x = match op {
|
|
|
- Operand::Const(c @ 240..=248) => {
|
|
|
- let h = [
|
|
|
- 0x3800, 0xB800, 0x3C00, 0xBC00, 0x4000, 0xC000, 0x4400, 0xC400, 0x3118,
|
|
|
- ][usize::from(c - 240)];
|
|
|
- // shortcut: taken to fill both halves.
|
|
|
- self.s.m.i32(h | h << 16)
|
|
|
- }
|
|
|
- _ => self.operand(inst, &op)?,
|
|
|
+ let x = if float {
|
|
|
+ self.f16_operand(inst, &op)?
|
|
|
+ } else {
|
|
|
+ self.operand(inst, &op)?
|
|
|
};
|
|
|
let c = self.cur;
|
|
|
let x = if sel {
|
|
|
@@ -4625,7 +4628,7 @@ impl<'a> Lower<'a> {
|
|
|
for high in [false, true] {
|
|
|
let mut xs = Vec::new();
|
|
|
for k in 0..n {
|
|
|
- let h = self.packed_src(inst, k, high)?;
|
|
|
+ let h = self.packed_src(inst, k, high, float)?;
|
|
|
if float {
|
|
|
let mut f = self
|
|
|
.s
|