From afc76e44457975e3d20b3a490c5029dec6f4983a Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sat, 1 Mar 2025 19:49:41 +0100 Subject: feat: add most basic simd instructions Signed-off-by: Henry Gressmann --- crates/parser/src/conversion.rs | 1 + crates/parser/src/visit.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/parser') diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs index 86548d6..a4e3b35 100644 --- a/crates/parser/src/conversion.rs +++ b/crates/parser/src/conversion.rs @@ -261,6 +261,7 @@ pub(crate) fn process_const_operators(ops: OperatorsReader<'_>) -> Result Ok(ConstInstruction::I64Const(*value)), wasmparser::Operator::F32Const { value } => Ok(ConstInstruction::F32Const(f32::from_bits(value.bits()))), wasmparser::Operator::F64Const { value } => Ok(ConstInstruction::F64Const(f64::from_bits(value.bits()))), + wasmparser::Operator::V128Const { value } => Ok(ConstInstruction::V128Const(value.i128())), wasmparser::Operator::GlobalGet { global_index } => Ok(ConstInstruction::GlobalGet(*global_index)), op => Err(crate::ParseError::UnsupportedOperator(format!("Unsupported const instruction: {op:?}"))), } diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index 2830d3a..270f6c6 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -111,7 +111,7 @@ macro_rules! define_mem_operands_simd_lane { pub(crate) struct FunctionBuilder { validator: FuncValidator, instructions: Vec, - v128_constants: Vec, + v128_constants: Vec, label_ptrs: Vec, local_addr_map: Vec, errors: Vec, @@ -530,12 +530,12 @@ impl wasmparser::VisitSimdOperator<'_> for FunctionBuild } fn visit_i8x16_shuffle(&mut self, lanes: [u8; 16]) -> Self::Output { - self.v128_constants.push(u128::from_le_bytes(lanes)); - self.instructions.push(Instruction::I8x16Shuffle(self.v128_constants.len() as u32 - 1)); + self.instructions.push(Instruction::I8x16Shuffle(self.v128_constants.len() as u32)); + self.v128_constants.push(i128::from_le_bytes(lanes)); } fn visit_v128_const(&mut self, value: wasmparser::V128) -> Self::Output { - self.v128_constants.push(value.i128() as u128); - self.instructions.push(Instruction::V128Const(self.v128_constants.len() as u32 - 1)); + self.instructions.push(Instruction::V128Const(self.v128_constants.len() as u32)); + self.v128_constants.push(value.i128()); } } -- cgit v1.3.1