Implement Swizzle and Splat for interpreter (#3268)

* Implement `Swizzle` and `Splat` for interpreter

Implemented for the Cranelift interpreter:
- `Swizzle` to shuffle an `i8x16` SIMD vector based
on the indices specified in another vector of the same size.
- `Splat` to create a SIMD vector with all lanes having the same value.

Copyright (c) 2021, Arm Limited

* Fix old x86 backend failing test

Copyright (c) 2021, Arm Limited

* Represent i16x8 and above as hex

Copyright (c) 2021, Arm Limited
This commit is contained in:
Damian Heaton
2021-09-07 17:53:49 +01:00
committed by GitHub
parent 63e9a81deb
commit dd23a21b9b
3 changed files with 84 additions and 2 deletions

View File

@@ -777,8 +777,24 @@ where
ValueConversionKind::RoundNearestEven(ctrl_ty),
)?),
Opcode::Shuffle => unimplemented!("Shuffle"),
Opcode::Swizzle => unimplemented!("Swizzle"),
Opcode::Splat => unimplemented!("Splat"),
Opcode::Swizzle => {
let x = Value::into_array(&arg(0)?)?;
let s = Value::into_array(&arg(1)?)?;
let mut new = [0u8; 16];
for i in 0..new.len() {
if (s[i] as usize) < new.len() {
new[i] = x[s[i] as usize];
} // else leave as 0
}
assign(Value::vector(new, ctrl_ty)?)
}
Opcode::Splat => {
let mut new_vector = SimdVec::new();
for _ in 0..ctrl_ty.lane_count() {
new_vector.push(arg(0)?.into_int()?);
}
assign(vectorizelanes(&new_vector, ctrl_ty)?)
}
Opcode::Insertlane => {
let idx = imm().into_int()? as usize;
let mut vector = extractlanes(&arg(0)?, ctrl_ty.lane_type())?;