Implement Shuffle for the interpreter
Implemented `Shuffle` for the Cranelift interpreter, to shuffle two SIMD vectors together based on an immediate mask of 16 bytes. Copyright (c) 2021, Arm Limited
This commit is contained in:
@@ -776,7 +776,30 @@ where
|
||||
arg(0)?,
|
||||
ValueConversionKind::RoundNearestEven(ctrl_ty),
|
||||
)?),
|
||||
Opcode::Shuffle => unimplemented!("Shuffle"),
|
||||
Opcode::Shuffle => {
|
||||
if let InstructionData::Shuffle { mask, .. } = inst {
|
||||
let mask = state
|
||||
.get_current_function()
|
||||
.dfg
|
||||
.immediates
|
||||
.get(mask)
|
||||
.unwrap()
|
||||
.as_slice();
|
||||
let a = Value::into_array(&arg(0)?)?;
|
||||
let b = Value::into_array(&arg(1)?)?;
|
||||
let mut new = [0u8; 16];
|
||||
for i in 0..mask.len() {
|
||||
if (mask[i] as usize) < a.len() {
|
||||
new[i] = a[mask[i] as usize];
|
||||
} else if (mask[i] as usize - a.len()) < b.len() {
|
||||
new[i] = b[mask[i] as usize - a.len()];
|
||||
} // else leave as 0.
|
||||
}
|
||||
assign(Value::vector(new, ctrl_ty)?)
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
Opcode::Swizzle => {
|
||||
let x = Value::into_array(&arg(0)?)?;
|
||||
let s = Value::into_array(&arg(1)?)?;
|
||||
|
||||
Reference in New Issue
Block a user