Translate WASM shr to CLIF sshr and ushr

As with shift left, the spec requires that the shift count is computed modulo the lane width (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#left-shift-by-scalar).
This commit is contained in:
Andrew Brown
2019-10-07 10:48:10 -07:00
parent f1904bffea
commit 19a980363e

View File

@@ -1120,6 +1120,24 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let b_mod_bitwidth = builder.ins().band_imm(b, bitwidth - 1);
state.push1(builder.ins().ishl(bitcast_a, b_mod_bitwidth))
}
Operator::I16x8ShrU | Operator::I32x4ShrU | Operator::I64x2ShrU => {
let (a, b) = state.pop2();
let bitcast_a = optionally_bitcast_vector(a, type_of(op), builder);
let bitwidth = i64::from(builder.func.dfg.value_type(a).bits());
// The spec expects to shift with `b mod lanewidth`; so, e.g., for 16 bit lane-width
// we do `b AND 15`; this means fewer instructions than `iconst + urem`.
let b_mod_bitwidth = builder.ins().band_imm(b, bitwidth - 1);
state.push1(builder.ins().ushr(bitcast_a, b_mod_bitwidth))
}
Operator::I16x8ShrS | Operator::I32x4ShrS => {
let (a, b) = state.pop2();
let bitcast_a = optionally_bitcast_vector(a, type_of(op), builder);
let bitwidth = i64::from(builder.func.dfg.value_type(a).bits());
// The spec expects to shift with `b mod lanewidth`; so, e.g., for 16 bit lane-width
// we do `b AND 15`; this means fewer instructions than `iconst + urem`.
let b_mod_bitwidth = builder.ins().band_imm(b, bitwidth - 1);
state.push1(builder.ins().sshr(bitcast_a, b_mod_bitwidth))
}
Operator::I8x16Eq
| Operator::I8x16Ne
| Operator::I8x16LtS
@@ -1171,16 +1189,11 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::I8x16Mul
| Operator::I16x8AnyTrue
| Operator::I16x8AllTrue
| Operator::I16x8ShrS
| Operator::I16x8ShrU
| Operator::I32x4AnyTrue
| Operator::I32x4AllTrue
| Operator::I32x4ShrS
| Operator::I32x4ShrU
| Operator::I64x2AnyTrue
| Operator::I64x2AllTrue
| Operator::I64x2ShrS
| Operator::I64x2ShrU
| Operator::F32x4Abs
| Operator::F32x4Neg
| Operator::F32x4Sqrt