[s390x, abi_impl] Add i128 support (#4598)

This adds full i128 support to the s390x target, including new filetests
and enabling the existing i128 runtest on s390x.

The ABI requires that i128 is passed and returned via implicit pointer,
but the front end still generates direct i128 types in call.  This means
we have to implement ABI support to implicitly convert i128 types to
pointers when passing arguments.

To do so, we add a new variant ABIArg::ImplicitArg.  This acts like
StructArg, except that the value type is the actual target type,
not a pointer type.  The required conversions have to be inserted
in the prologue and at function call sites.

Note that when dereferencing the implicit pointer in the prologue,
we may require a temp register: the pointer may be passed on the
stack so it needs to be loaded first, but the value register may
be in the wrong class for pointer values.  In this case, we use
the "stack limit" register, which should be available at this
point in the prologue.

For return values, we use a mechanism similar to the one used for
supporting multiple return values in the Wasmtime ABI.  The only
difference is that the hidden pointer to the return buffer must
be the *first*, not last, argument in this case.

(This implements the second half of issue #4565.)
This commit is contained in:
Ulrich Weigand
2022-08-04 22:41:26 +02:00
committed by GitHub
parent dc8362ceec
commit b17b1eb25d
46 changed files with 2424 additions and 166 deletions

View File

@@ -180,6 +180,8 @@ impl Inst {
| Inst::VecIntCmpS { .. }
| Inst::VecFloatCmp { .. }
| Inst::VecFloatCmpS { .. }
| Inst::VecInt128SCmpHi { .. }
| Inst::VecInt128UCmpHi { .. }
| Inst::VecLoad { .. }
| Inst::VecStore { .. }
| Inst::VecLoadReplicate { .. }
@@ -394,6 +396,7 @@ impl Inst {
lane_imm: 0,
},
_ if ty.is_vector() && ty.bits() == 128 => Inst::VecLoad { rd: into_reg, mem },
types::B128 | types::I128 => Inst::VecLoad { rd: into_reg, mem },
_ => unimplemented!("gen_load({})", ty),
}
}
@@ -418,6 +421,7 @@ impl Inst {
lane_imm: 0,
},
_ if ty.is_vector() && ty.bits() == 128 => Inst::VecStore { rd: from_reg, mem },
types::B128 | types::I128 => Inst::VecStore { rd: from_reg, mem },
_ => unimplemented!("gen_store({})", ty),
}
}
@@ -736,6 +740,11 @@ fn s390x_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
collector.reg_use(rn);
collector.reg_use(rm);
}
&Inst::VecInt128SCmpHi { tmp, rn, rm, .. } | &Inst::VecInt128UCmpHi { tmp, rn, rm, .. } => {
collector.reg_def(tmp);
collector.reg_use(rn);
collector.reg_use(rm);
}
&Inst::VecLoad { rd, ref mem, .. } => {
collector.reg_def(rd);
memarg_operands(mem, collector);
@@ -979,6 +988,11 @@ impl MachInst for Inst {
.only_reg()
.expect("multi-reg values not supported yet");
match ty {
types::I128 | types::B128 => {
let mut ret = SmallVec::new();
ret.push(Inst::load_vec_constant(to_reg, value));
ret
}
_ if ty.is_vector() && ty.bits() == 128 => {
let mut ret = SmallVec::new();
ret.push(Inst::load_vec_constant(to_reg, value));
@@ -1037,8 +1051,8 @@ impl MachInst for Inst {
types::R64 => Ok((&[RegClass::Int], &[types::R64])),
types::F32 => Ok((&[RegClass::Float], &[types::F32])),
types::F64 => Ok((&[RegClass::Float], &[types::F64])),
types::I128 => Ok((&[RegClass::Int, RegClass::Int], &[types::I64, types::I64])),
types::B128 => Ok((&[RegClass::Int, RegClass::Int], &[types::B64, types::B64])),
types::I128 => Ok((&[RegClass::Float], &[types::I128])),
types::B128 => Ok((&[RegClass::Float], &[types::B128])),
_ if ty.is_vector() && ty.bits() == 128 => Ok((&[RegClass::Float], &[types::I8X16])),
// FIXME: We don't really have IFLAGS, but need to allow it here
// for now to support the SelectifSpectreGuard instruction.
@@ -2202,10 +2216,12 @@ impl Inst {
VecBinaryOp::Add16x8 => "vah",
VecBinaryOp::Add32x4 => "vaf",
VecBinaryOp::Add64x2 => "vag",
VecBinaryOp::Add128 => "vaq",
VecBinaryOp::Sub8x16 => "vsb",
VecBinaryOp::Sub16x8 => "vsh",
VecBinaryOp::Sub32x4 => "vsf",
VecBinaryOp::Sub64x2 => "vsg",
VecBinaryOp::Sub128 => "vsq",
VecBinaryOp::Mul8x16 => "vmlb",
VecBinaryOp::Mul16x8 => "vmlhw",
VecBinaryOp::Mul32x4 => "vmlf",
@@ -2303,6 +2319,14 @@ impl Inst {
VecUnaryOp::Popcnt16x8 => "vpopcth",
VecUnaryOp::Popcnt32x4 => "vpopctf",
VecUnaryOp::Popcnt64x2 => "vpopctg",
VecUnaryOp::Clz8x16 => "vclzb",
VecUnaryOp::Clz16x8 => "vclzh",
VecUnaryOp::Clz32x4 => "vclzf",
VecUnaryOp::Clz64x2 => "vclzg",
VecUnaryOp::Ctz8x16 => "vctzb",
VecUnaryOp::Ctz16x8 => "vctzh",
VecUnaryOp::Ctz32x4 => "vctzf",
VecUnaryOp::Ctz64x2 => "vctzg",
VecUnaryOp::UnpackULow8x16 => "vupllb",
VecUnaryOp::UnpackULow16x8 => "vupllh",
VecUnaryOp::UnpackULow32x4 => "vupllf",
@@ -2425,6 +2449,20 @@ impl Inst {
let rm = pretty_print_reg(rm, allocs);
format!("{}{} {}, {}, {}", op, s, rd, rn, rm)
}
&Inst::VecInt128SCmpHi { tmp, rn, rm } | &Inst::VecInt128UCmpHi { tmp, rn, rm } => {
let op = match self {
&Inst::VecInt128SCmpHi { .. } => "vecg",
&Inst::VecInt128UCmpHi { .. } => "veclg",
_ => unreachable!(),
};
let tmp = pretty_print_reg(tmp.to_reg(), allocs);
let rn = pretty_print_reg(rn, allocs);
let rm = pretty_print_reg(rm, allocs);
format!(
"{} {}, {} ; jne 10 ; vchlgs {}, {}, {}",
op, rm, rn, tmp, rn, rm
)
}
&Inst::VecLoad { rd, ref mem } | &Inst::VecLoadRev { rd, ref mem } => {
let opcode = match self {
&Inst::VecLoad { .. } => "vl",