cranelift: Add bmask to interpreter

This commit is contained in:
Afonso Bordado
2021-09-14 14:58:08 +01:00
parent 3ee180420e
commit 9a95ce75f1
5 changed files with 291 additions and 6 deletions

View File

@@ -767,7 +767,6 @@ where
| Opcode::Breduce
| Opcode::Bextend
| Opcode::Bint
| Opcode::Bmask
| Opcode::Ireduce => assign(Value::convert(
arg(0)?,
ValueConversionKind::Exact(ctrl_ty),
@@ -802,6 +801,19 @@ where
.collect::<ValueResult<Vec<_>>>()?;
assign(vectorizelanes(&new_vec, new_type)?)
}
Opcode::Bmask => assign({
let bool = arg(0)?;
let bool_ty = ctrl_ty.as_bool_pedantic();
if ctrl_ty.is_vector() {
let lanes = extractlanes(&bool, bool_ty.lane_type())?
.into_iter()
.map(|lane| lane.convert(ValueConversionKind::Exact(ctrl_ty.lane_type())))
.collect::<ValueResult<SimdVec<V>>>()?;
vectorizelanes(&lanes, ctrl_ty)?
} else {
bool.convert(ValueConversionKind::Exact(ctrl_ty))?
}
}),
Opcode::Sextend => assign(Value::convert(
arg(0)?,
ValueConversionKind::SignExtend(ctrl_ty),

View File

@@ -277,11 +277,11 @@ impl Value for DataValue {
(DataValue::I64(n), types::I128) => DataValue::I128(n as i128),
(DataValue::B(b), t) if t.is_bool() => DataValue::B(b),
(DataValue::B(b), t) if t.is_int() => {
let val = if b {
// Bools are represented in memory as all 1's
(1i128 << t.bits()) - 1
} else {
0
// Bools are represented in memory as all 1's
let val = match (b, t) {
(true, types::I128) => -1,
(true, t) => (1i128 << t.bits()) - 1,
_ => 0,
};
DataValue::int(val, t)?
}