From d0264fcae4ba4ffb7e5417ddce464e663de66940 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Fri, 28 Feb 2025 23:28:19 +0100 Subject: wip: initial simd support Signed-off-by: Henry Gressmann --- crates/cli/src/args.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/cli') diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 96c3605..a23f1f4 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -25,6 +25,7 @@ impl FromStr for WasmArg { "i64" => val.parse::().map_err(|e| format!("invalid argument value for i64: {e:?}"))?.into(), "f32" => val.parse::().map_err(|e| format!("invalid argument value for f32: {e:?}"))?.into(), "f64" => val.parse::().map_err(|e| format!("invalid argument value for f64: {e:?}"))?.into(), + "v128" => val.parse::().map_err(|e| format!("invalid argument value for v128: {e:?}"))?.into(), t => return Err(format!("Invalid arg type: {t}")), }; -- cgit v1.3.1 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/cli/src/args.rs | 2 +- crates/parser/src/conversion.rs | 1 + crates/parser/src/visit.rs | 10 +- crates/tinywasm/src/interpreter/executor.rs | 162 ++++++++++++++++++++- crates/tinywasm/src/interpreter/mod.rs | 3 - crates/tinywasm/src/interpreter/simd.rs | 3 - .../tinywasm/src/interpreter/stack/call_stack.rs | 7 +- .../tinywasm/src/interpreter/stack/value_stack.rs | 2 +- crates/tinywasm/src/interpreter/values.rs | 31 ++-- crates/tinywasm/src/store/memory.rs | 45 ++++-- crates/tinywasm/tests/generated/wasm-simd.csv | 2 +- crates/tinywasm/tests/testsuite/util.rs | 28 ++-- crates/types/src/instructions.rs | 1 + crates/types/src/lib.rs | 2 +- crates/types/src/value.rs | 8 +- 15 files changed, 245 insertions(+), 62 deletions(-) delete mode 100644 crates/tinywasm/src/interpreter/simd.rs (limited to 'crates/cli') diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index a23f1f4..1fec2d5 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -25,7 +25,7 @@ impl FromStr for WasmArg { "i64" => val.parse::().map_err(|e| format!("invalid argument value for i64: {e:?}"))?.into(), "f32" => val.parse::().map_err(|e| format!("invalid argument value for f32: {e:?}"))?.into(), "f64" => val.parse::().map_err(|e| format!("invalid argument value for f64: {e:?}"))?.into(), - "v128" => val.parse::().map_err(|e| format!("invalid argument value for v128: {e:?}"))?.into(), + "v128" => val.parse::().map_err(|e| format!("invalid argument value for v128: {e:?}"))?.into(), t => return Err(format!("Invalid arg type: {t}")), }; 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()); } } diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs index 100075b..932fad9 100644 --- a/crates/tinywasm/src/interpreter/executor.rs +++ b/crates/tinywasm/src/interpreter/executor.rs @@ -3,14 +3,21 @@ use super::no_std_floats::NoStdFloatExt; use alloc::{format, rc::Rc, string::ToString}; -use core::ops::ControlFlow; -use core::simd::cmp::{SimdPartialEq, SimdPartialOrd}; -use core::simd::num::SimdUint; +use core::ops::{ControlFlow, IndexMut, Shl, Shr}; + use interpreter::stack::CallFrame; use tinywasm_types::*; #[cfg(feature = "simd")] -use super::simd::*; +mod simd { + #[cfg(feature = "std")] + pub(super) use crate::std::simd::StdFloat; + pub(super) use core::simd::cmp::{SimdOrd, SimdPartialEq, SimdPartialOrd}; + pub(super) use core::simd::num::{SimdFloat, SimdInt, SimdUint}; + pub(super) use core::simd::*; +} +#[cfg(feature = "simd")] +use simd::*; use super::num_helpers::*; use super::stack::{BlockFrame, BlockType, Stack}; @@ -315,8 +322,16 @@ impl<'store, 'stack> Executor<'store, 'stack> { V128Or => self.stack.values.calculate_same::(|a, b| Ok(a | b)).to_cf()?, V128Xor => self.stack.values.calculate_same::(|a, b| Ok(a ^ b)).to_cf()?, V128Bitselect => self.stack.values.calculate_same_3::(|v1, v2, c| Ok((v1 & c) | (v2 & !c))).to_cf()?, - V128AnyTrue => self.stack.values.replace_top::(|v| Ok((v.reduce_sum() != 0) as i32)).to_cf()?, + V128AnyTrue => self.stack.values.replace_top::(|v| Ok((v.reduce_or() != 0) as i32)).to_cf()?, I8x16Swizzle => self.stack.values.calculate_same::(|a, s| Ok(a.swizzle_dyn(s))).to_cf()?, + V128Load(arg) => self.exec_mem_load::(arg.mem_addr(), arg.offset(), |v| v)?, + V128Store(arg) => self.exec_mem_store::(arg.mem_addr(), arg.offset(), |v| v)?, + V128Const(arg) => self.exec_const::( self.cf.data().v128_constants[*arg as usize].to_le_bytes().into()), + + V128Load8Lane(arg, lane) => self.exec_mem_load_lane::(arg.mem_addr(), arg.offset(), *lane)?, + V128Load16Lane(arg, lane) => self.exec_mem_load_lane::(arg.mem_addr(), arg.offset(), *lane)?, + V128Load32Lane(arg, lane) => self.exec_mem_load_lane::(arg.mem_addr(), arg.offset(), *lane)?, + V128Load64Lane(arg, lane) => self.exec_mem_load_lane::(arg.mem_addr(), arg.offset(), *lane)?, I8x16Splat => self.stack.values.replace_top::(|v| Ok(Simd::::splat(v as i8))).to_cf()?, I16x8Splat => self.stack.values.replace_top::(|v| Ok(Simd::::splat(v as i16))).to_cf()?, @@ -373,6 +388,10 @@ impl<'store, 'stack> Executor<'store, 'stack> { I16x8LeU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_le(b).to_int())).to_cf()?, I32x4LeU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_le(b).to_int())).to_cf()?, + I8x16GeS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, + I16x8GeS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, + I32x4GeS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, + I8x16GeU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, I16x8GeU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, I32x4GeU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_ge(b).to_int())).to_cf()?, @@ -382,6 +401,98 @@ impl<'store, 'stack> Executor<'store, 'stack> { I32x4Abs => self.stack.values.replace_top_same::(|a| Ok(a.abs())).to_cf()?, I64x2Abs => self.stack.values.replace_top_same::(|a| Ok(a.abs())).to_cf()?, + I8x16Neg => self.stack.values.replace_top_same::(|a| Ok(-a)).to_cf()?, + I16x8Neg => self.stack.values.replace_top_same::(|a| Ok(-a)).to_cf()?, + I32x4Neg => self.stack.values.replace_top_same::(|a| Ok(-a)).to_cf()?, + I64x2Neg => self.stack.values.replace_top_same::(|a| Ok(-a)).to_cf()?, + + I8x16AllTrue => self.stack.values.replace_top::(|v| Ok((v != Simd::splat(0)) as i32)).to_cf()?, + I16x8AllTrue => self.stack.values.replace_top::(|v| Ok((v != Simd::splat(0)) as i32)).to_cf()?, + I32x4AllTrue => self.stack.values.replace_top::(|v| Ok((v != Simd::splat(0)) as i32)).to_cf()?, + I64x2AllTrue => self.stack.values.replace_top::(|v| Ok((v != Simd::splat(0)) as i32)).to_cf()?, + + I8x16Bitmask => self.stack.values.replace_top::(|v| Ok(v.simd_lt(Simd::splat(0)).to_bitmask() as i32)).to_cf()?, + I16x8Bitmask => self.stack.values.replace_top::(|v| Ok(v.simd_lt(Simd::splat(0)).to_bitmask() as i32)).to_cf()?, + I32x4Bitmask => self.stack.values.replace_top::(|v| Ok(v.simd_lt(Simd::splat(0)).to_bitmask() as i32)).to_cf()?, + I64x2Bitmask => self.stack.values.replace_top::(|v| Ok(v.simd_lt(Simd::splat(0)).to_bitmask() as i32)).to_cf()?, + + I8x16Shl => self.stack.values.calculate_same::(|a, b| Ok(a.shl(b))).to_cf()?, + I16x8Shl => self.stack.values.calculate_same::(|a, b| Ok(a.shl(b))).to_cf()?, + I32x4Shl => self.stack.values.calculate_same::(|a, b| Ok(a.shl(b))).to_cf()?, + I64x2Shl => self.stack.values.calculate_same::(|a, b| Ok(a.shl(b))).to_cf()?, + + I8x16ShrS => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I16x8ShrS => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I32x4ShrS => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I64x2ShrS => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + + I8x16ShrU => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I16x8ShrU => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I32x4ShrU => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + I64x2ShrU => self.stack.values.calculate_same::(|a, b| Ok(a.shr(b))).to_cf()?, + + I8x16Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + I16x8Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + I32x4Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + I64x2Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + + I8x16Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + I16x8Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + I32x4Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + I64x2Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + + I8x16MinS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + I16x8MinS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + I32x4MinS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + + I8x16MinU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + I16x8MinU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + I32x4MinU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + + I8x16MaxS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + I16x8MaxS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + I32x4MaxS => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + + I8x16MaxU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + I16x8MaxU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + I32x4MaxU => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + + I64x2Mul => self.stack.values.calculate_same::(|a, b| Ok(a * b)).to_cf()?, + + I8x16AddSatS => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_add(b))).to_cf()?, + I16x8AddSatS => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_add(b))).to_cf()?, + I8x16AddSatU => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_add(b))).to_cf()?, + I16x8AddSatU => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_add(b))).to_cf()?, + I8x16SubSatS => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_sub(b))).to_cf()?, + I16x8SubSatS => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_sub(b))).to_cf()?, + I8x16SubSatU => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_sub(b))).to_cf()?, + I16x8SubSatU => self.stack.values.calculate_same::(|a, b| Ok(a.saturating_sub(b))).to_cf()?, + + F32x4Ceil => self.stack.values.replace_top_same::(|v| Ok(v.ceil())).to_cf()?, + F64x2Ceil => self.stack.values.replace_top_same::(|v| Ok(v.ceil())).to_cf()?, + F32x4Floor => self.stack.values.replace_top_same::(|v| Ok(v.floor())).to_cf()?, + F64x2Floor => self.stack.values.replace_top_same::(|v| Ok(v.floor())).to_cf()?, + F32x4Trunc => self.stack.values.replace_top_same::(|v| Ok(v.trunc())).to_cf()?, + F64x2Trunc => self.stack.values.replace_top_same::(|v| Ok(v.trunc())).to_cf()?, + F32x4Abs => self.stack.values.replace_top_same::(|v| Ok(v.abs())).to_cf()?, + F64x2Abs => self.stack.values.replace_top_same::(|v| Ok(v.abs())).to_cf()?, + F32x4Neg => self.stack.values.replace_top_same::(|v| Ok(-v)).to_cf()?, + F64x2Neg => self.stack.values.replace_top_same::(|v| Ok(-v)).to_cf()?, + F32x4Sqrt => self.stack.values.replace_top_same::(|v| Ok(v.sqrt())).to_cf()?, + F64x2Sqrt => self.stack.values.replace_top_same::(|v| Ok(v.sqrt())).to_cf()?, + F32x4Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + F64x2Add => self.stack.values.calculate_same::(|a, b| Ok(a + b)).to_cf()?, + F32x4Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + F64x2Sub => self.stack.values.calculate_same::(|a, b| Ok(a - b)).to_cf()?, + F32x4Mul => self.stack.values.calculate_same::(|a, b| Ok(a * b)).to_cf()?, + F64x2Mul => self.stack.values.calculate_same::(|a, b| Ok(a * b)).to_cf()?, + F32x4Div => self.stack.values.calculate_same::(|a, b| Ok(a / b)).to_cf()?, + F64x2Div => self.stack.values.calculate_same::(|a, b| Ok(a / b)).to_cf()?, + F32x4Min => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + F64x2Min => self.stack.values.calculate_same::(|a, b| Ok(a.simd_min(b))).to_cf()?, + F32x4Max => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + F64x2Max => self.stack.values.calculate_same::(|a, b| Ok(a.simd_max(b))).to_cf()?, + i => return ControlFlow::Break(Some(Error::UnsupportedFeature(format!("unimplemented opcode: {i:?}")))), }; @@ -689,6 +800,47 @@ impl<'store, 'stack> Executor<'store, 'stack> { Ok(()) } + fn exec_mem_load_lane< + LOAD: MemLoadable, + INTO: InternalValue + IndexMut, + const LOAD_SIZE: usize, + >( + &mut self, + mem_addr: tinywasm_types::MemAddr, + offset: u64, + lanes: u8, + ) -> ControlFlow> { + let mem = self.store.get_mem(self.module.resolve_mem_addr(mem_addr)); + let mut imm = self.stack.values.pop::(); + let val = self.stack.values.pop::() as u64; + let Some(Ok(addr)) = offset.checked_add(val).map(TryInto::try_into) else { + cold(); + return ControlFlow::Break(Some(Error::Trap(Trap::MemoryOutOfBounds { + offset: val as usize, + len: LOAD_SIZE, + max: 0, + }))); + }; + let val = mem.load_as::(addr).to_cf()?; + imm[lanes as usize] = val; + self.stack.values.push(imm); + ControlFlow::Continue(()) + } + + // fn mem_load, const LOAD_SIZE: usize, TARGET: InternalValue>( + // &mut self, + // mem_addr: tinywasm_types::MemAddr, + // offset: u64, + // ) -> Result { + // let mem = self.store.get_mem(self.module.resolve_mem_addr(mem_addr)); + // let val = self.stack.values.pop::() as u64; + // let Some(Ok(addr)) = offset.checked_add(val).map(TryInto::try_into) else { + // cold(); + // return Err(Error::Trap(Trap::MemoryOutOfBounds { offset: val as usize, len: LOAD_SIZE, max: 0 })); + // }; + // mem.load_as::(addr) + // } + fn exec_mem_load, const LOAD_SIZE: usize, TARGET: InternalValue>( &mut self, mem_addr: tinywasm_types::MemAddr, diff --git a/crates/tinywasm/src/interpreter/mod.rs b/crates/tinywasm/src/interpreter/mod.rs index 269bcfb..0b7df2f 100644 --- a/crates/tinywasm/src/interpreter/mod.rs +++ b/crates/tinywasm/src/interpreter/mod.rs @@ -6,9 +6,6 @@ mod values; #[cfg(not(feature = "std"))] mod no_std_floats; -#[cfg(feature = "simd")] -mod simd; - use crate::{Result, Store}; pub use values::*; diff --git a/crates/tinywasm/src/interpreter/simd.rs b/crates/tinywasm/src/interpreter/simd.rs deleted file mode 100644 index 2042bc6..0000000 --- a/crates/tinywasm/src/interpreter/simd.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub(super) use core::simd::num::SimdFloat; -pub(super) use core::simd::num::SimdInt; -pub(super) use core::simd::*; diff --git a/crates/tinywasm/src/interpreter/stack/call_stack.rs b/crates/tinywasm/src/interpreter/stack/call_stack.rs index 9b6c3fd..25ad81f 100644 --- a/crates/tinywasm/src/interpreter/stack/call_stack.rs +++ b/crates/tinywasm/src/interpreter/stack/call_stack.rs @@ -7,7 +7,7 @@ use crate::{Error, unlikely}; use alloc::boxed::Box; use alloc::{rc::Rc, vec, vec::Vec}; -use tinywasm_types::{Instruction, LocalAddr, ModuleInstanceAddr, WasmFunction, WasmValue}; +use tinywasm_types::{Instruction, LocalAddr, ModuleInstanceAddr, WasmFunction, WasmFunctionData, WasmValue}; pub(crate) const MAX_CALL_STACK_SIZE: usize = 1024; @@ -70,6 +70,11 @@ impl CallFrame { self.instr_ptr } + #[inline] + pub(crate) fn data(&self) -> &WasmFunctionData { + &self.func_instance.data + } + #[inline] pub(crate) fn incr_instr_ptr(&mut self) { self.instr_ptr += 1; diff --git a/crates/tinywasm/src/interpreter/stack/value_stack.rs b/crates/tinywasm/src/interpreter/stack/value_stack.rs index 843723a..bb5b2ea 100644 --- a/crates/tinywasm/src/interpreter/stack/value_stack.rs +++ b/crates/tinywasm/src/interpreter/stack/value_stack.rs @@ -184,7 +184,7 @@ impl ValueStack { ValType::V128 => WasmValue::V128(self.pop()), #[cfg(feature = "simd")] - ValType::V128 => WasmValue::V128(u128::from_ne_bytes(self.pop::().to_array())), + ValType::V128 => WasmValue::V128(i128::from_le_bytes(self.pop::().to_array())), } } diff --git a/crates/tinywasm/src/interpreter/values.rs b/crates/tinywasm/src/interpreter/values.rs index 98d40af..335da59 100644 --- a/crates/tinywasm/src/interpreter/values.rs +++ b/crates/tinywasm/src/interpreter/values.rs @@ -10,7 +10,7 @@ pub(crate) type ValueRef = Option; #[cfg(feature = "simd")] pub(crate) type Value128 = core::simd::u8x16; #[cfg(not(feature = "simd"))] -pub(crate) type Value128 = u128; +pub(crate) type Value128 = i128; #[derive(Debug, Clone, Copy, PartialEq)] /// A untyped WebAssembly value @@ -114,7 +114,7 @@ impl TinyWasmValue { ValType::RefFunc => WasmValue::RefFunc(FuncRef::new(self.unwrap_ref())), #[cfg(feature = "simd")] - ValType::V128 => WasmValue::V128(u128::from_ne_bytes(self.unwrap_128().to_array())), + ValType::V128 => WasmValue::V128(i128::from_le_bytes(self.unwrap_128().to_array())), #[cfg(not(feature = "simd"))] ValType::V128 => WasmValue::V128(self.unwrap_128()), @@ -136,7 +136,7 @@ impl From<&WasmValue> for TinyWasmValue { WasmValue::V128(v) => TinyWasmValue::Value128(*v), #[cfg(feature = "simd")] - WasmValue::V128(v) => TinyWasmValue::Value128(v.to_ne_bytes().into()), + WasmValue::V128(v) => TinyWasmValue::Value128(v.to_le_bytes().into()), } } } @@ -269,8 +269,8 @@ impl_internalvalue! { Value64, stack_64, locals_64, u64, i64, |v| v as u64, |v| v as i64 Value32, stack_32, locals_32, u32, f32, f32::to_bits, f32::from_bits Value64, stack_64, locals_64, u64, f64, f64::to_bits, f64::from_bits - Value128, stack_128, locals_128, Value128, Value128, |v| v, |v| v ValueRef, stack_ref, locals_ref, ValueRef, ValueRef, |v| v, |v| v + Value128, stack_128, locals_128, Value128, Value128, |v| v, |v| v } #[cfg(feature = "simd")] @@ -278,15 +278,16 @@ use core::simd::{num::SimdUint, *}; #[cfg(feature = "simd")] impl_internalvalue! { - Value128, stack_128, locals_128, u8x16, u128, |v: u128| v.to_ne_bytes().into(), |v: u8x16| u128::from_ne_bytes(v.into()) - Value128, stack_128, locals_128, u8x16, i8x16, |v: i8x16| v.to_ne_bytes(), |v: u8x16| v.cast() - Value128, stack_128, locals_128, u8x16, i16x8, |v: i16x8| v.to_ne_bytes(), |v: u8x16| i16x8::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, i32x4, |v: i32x4| v.to_ne_bytes(), |v: u8x16| i32x4::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, i64x2, |v: i64x2| v.to_ne_bytes(), |v: u8x16| i64x2::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, f32x4, |v: f32x4| v.to_ne_bytes(), |v: u8x16| f32x4::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, f64x2, |v: f64x2| v.to_ne_bytes(), |v: u8x16| f64x2::from_ne_bytes(v) - - Value128, stack_128, locals_128, u8x16, u16x8, |v: u16x8| v.to_ne_bytes(), |v: u8x16| u16x8::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, u32x4, |v: u32x4| v.to_ne_bytes(), |v: u8x16| u32x4::from_ne_bytes(v) - Value128, stack_128, locals_128, u8x16, u64x2, |v: u64x2| v.to_ne_bytes(), |v: u8x16| u64x2::from_ne_bytes(v) + Value128, stack_128, locals_128, u8x16, i128, |v: i128| v.to_le_bytes().into(), |v: u8x16| i128::from_le_bytes(v.into()) + Value128, stack_128, locals_128, u8x16, u128, |v: u128| v.to_le_bytes().into(), |v: u8x16| u128::from_le_bytes(v.into()) + Value128, stack_128, locals_128, u8x16, i8x16, |v: i8x16| v.to_le_bytes(), |v: u8x16| v.cast() + Value128, stack_128, locals_128, u8x16, i16x8, |v: i16x8| v.to_le_bytes(), |v: u8x16| i16x8::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, i32x4, |v: i32x4| v.to_le_bytes(), |v: u8x16| i32x4::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, i64x2, |v: i64x2| v.to_le_bytes(), |v: u8x16| i64x2::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, f32x4, |v: f32x4| v.to_le_bytes(), |v: u8x16| f32x4::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, f64x2, |v: f64x2| v.to_le_bytes(), |v: u8x16| f64x2::from_le_bytes(v) + + Value128, stack_128, locals_128, u8x16, u16x8, |v: u16x8| v.to_le_bytes(), |v: u8x16| u16x8::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, u32x4, |v: u32x4| v.to_le_bytes(), |v: u8x16| u32x4::from_le_bytes(v) + Value128, stack_128, locals_128, u8x16, u64x2, |v: u64x2| v.to_le_bytes(), |v: u8x16| u64x2::from_le_bytes(v) } diff --git a/crates/tinywasm/src/store/memory.rs b/crates/tinywasm/src/store/memory.rs index d204c67..a1c7994 100644 --- a/crates/tinywasm/src/store/memory.rs +++ b/crates/tinywasm/src/store/memory.rs @@ -2,7 +2,10 @@ use alloc::vec; use alloc::vec::Vec; use tinywasm_types::{MemoryType, ModuleInstanceAddr}; -use crate::{Error, Result, cold, log}; +use crate::{Error, Result, cold, interpreter::Value128, log}; + +#[cfg(feature = "simd")] +use core::simd::ToBytes; /// A WebAssembly Memory Instance /// @@ -80,7 +83,7 @@ impl MemoryInstance { return Err(self.trap_oob(addr, SIZE)); } - Ok(T::from_le_bytes(match self.data[addr..end].try_into() { + Ok(T::from_mem_bytes(match self.data[addr..end].try_into() { Ok(bytes) => bytes, Err(_) => return Err(self.trap_oob(addr, SIZE)), })) @@ -158,30 +161,52 @@ pub(crate) trait MemStorable { /// A trait for types that can be loaded from memory pub(crate) trait MemLoadable: Sized + Copy { /// Load a value from memory - fn from_le_bytes(bytes: [u8; N]) -> Self; + fn from_mem_bytes(bytes: [u8; N]) -> Self; } macro_rules! impl_mem_traits { - ($($type:ty, $size:expr),*) => { + ($($ty:ty, $size:expr),*) => { $( - impl MemLoadable<$size> for $type { + impl MemLoadable<$size> for $ty { #[inline(always)] - fn from_le_bytes(bytes: [u8; $size]) -> Self { - <$type>::from_le_bytes(bytes) + fn from_mem_bytes(bytes: [u8; $size]) -> Self { + <$ty>::from_le_bytes(bytes.into()) } } - impl MemStorable<$size> for $type { + impl MemStorable<$size> for $ty { #[inline(always)] fn to_mem_bytes(self) -> [u8; $size] { - self.to_ne_bytes() + self.to_le_bytes().into() } } )* } } -impl_mem_traits!(u8, 1, i8, 1, u16, 2, i16, 2, u32, 4, i32, 4, f32, 4, u64, 8, i64, 8, f64, 8, u128, 16, i128, 16); +impl_mem_traits!(u8, 1, i8, 1, u16, 2, i16, 2, u32, 4, i32, 4, f32, 4, u64, 8, i64, 8, f64, 8, Value128, 16); + +#[cfg(feature = "simd")] +impl_mem_traits!( + core::simd::i8x16, + 16, + core::simd::i16x8, + 16, + core::simd::i32x4, + 16, + core::simd::i64x2, + 16, + core::simd::u16x8, + 16, + core::simd::u32x4, + 16, + core::simd::u64x2, + 16, + core::simd::f32x4, + 16, + core::simd::f64x2, + 16 +); #[cfg(test)] mod memory_instance_tests { diff --git a/crates/tinywasm/tests/generated/wasm-simd.csv b/crates/tinywasm/tests/generated/wasm-simd.csv index 210564b..6f37f4d 100644 --- a/crates/tinywasm/tests/generated/wasm-simd.csv +++ b/crates/tinywasm/tests/generated/wasm-simd.csv @@ -1,2 +1,2 @@ 0.8.0,1300,24679,[{"name":"simd_address.wast","passed":4,"failed":45},{"name":"simd_align.wast","passed":46,"failed":54},{"name":"simd_bit_shift.wast","passed":39,"failed":213},{"name":"simd_bitwise.wast","passed":28,"failed":141},{"name":"simd_boolean.wast","passed":16,"failed":261},{"name":"simd_const.wast","passed":301,"failed":456},{"name":"simd_conversions.wast","passed":48,"failed":234},{"name":"simd_f32x4.wast","passed":16,"failed":774},{"name":"simd_f32x4_arith.wast","passed":16,"failed":1806},{"name":"simd_f32x4_cmp.wast","passed":24,"failed":2583},{"name":"simd_f32x4_pmin_pmax.wast","passed":14,"failed":3873},{"name":"simd_f32x4_rounding.wast","passed":24,"failed":177},{"name":"simd_f64x2.wast","passed":8,"failed":795},{"name":"simd_f64x2_arith.wast","passed":16,"failed":1809},{"name":"simd_f64x2_cmp.wast","passed":24,"failed":2661},{"name":"simd_f64x2_pmin_pmax.wast","passed":14,"failed":3873},{"name":"simd_f64x2_rounding.wast","passed":24,"failed":177},{"name":"simd_i16x8_arith.wast","passed":11,"failed":183},{"name":"simd_i16x8_arith2.wast","passed":19,"failed":153},{"name":"simd_i16x8_cmp.wast","passed":30,"failed":435},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":4,"failed":17},{"name":"simd_i16x8_extmul_i8x16.wast","passed":12,"failed":105},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":3,"failed":27},{"name":"simd_i16x8_sat_arith.wast","passed":16,"failed":206},{"name":"simd_i32x4_arith.wast","passed":11,"failed":183},{"name":"simd_i32x4_arith2.wast","passed":26,"failed":123},{"name":"simd_i32x4_cmp.wast","passed":40,"failed":435},{"name":"simd_i32x4_dot_i16x8.wast","passed":3,"failed":27},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":4,"failed":17},{"name":"simd_i32x4_extmul_i16x8.wast","passed":12,"failed":105},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":4,"failed":103},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":4,"failed":103},{"name":"simd_i64x2_arith.wast","passed":11,"failed":189},{"name":"simd_i64x2_arith2.wast","passed":2,"failed":23},{"name":"simd_i64x2_cmp.wast","passed":10,"failed":103},{"name":"simd_i64x2_extmul_i32x4.wast","passed":12,"failed":105},{"name":"simd_i8x16_arith.wast","passed":8,"failed":123},{"name":"simd_i8x16_arith2.wast","passed":25,"failed":186},{"name":"simd_i8x16_cmp.wast","passed":30,"failed":415},{"name":"simd_i8x16_sat_arith.wast","passed":24,"failed":190},{"name":"simd_int_to_int_extend.wast","passed":24,"failed":229},{"name":"simd_lane.wast","passed":189,"failed":286},{"name":"simd_linking.wast","passed":0,"failed":3},{"name":"simd_load.wast","passed":8,"failed":31},{"name":"simd_load16_lane.wast","passed":3,"failed":33},{"name":"simd_load32_lane.wast","passed":3,"failed":21},{"name":"simd_load64_lane.wast","passed":3,"failed":13},{"name":"simd_load8_lane.wast","passed":3,"failed":49},{"name":"simd_load_extend.wast","passed":18,"failed":86},{"name":"simd_load_splat.wast","passed":12,"failed":114},{"name":"simd_load_zero.wast","passed":10,"failed":29},{"name":"simd_splat.wast","passed":23,"failed":162},{"name":"simd_store.wast","passed":9,"failed":19},{"name":"simd_store16_lane.wast","passed":3,"failed":33},{"name":"simd_store32_lane.wast","passed":3,"failed":21},{"name":"simd_store64_lane.wast","passed":3,"failed":13},{"name":"simd_store8_lane.wast","passed":3,"failed":49}] -0.9.0-alpha.0,1808,24172,[{"name":"simd_address.wast","passed":7,"failed":42},{"name":"simd_align.wast","passed":92,"failed":8},{"name":"simd_bit_shift.wast","passed":41,"failed":211},{"name":"simd_bitwise.wast","passed":30,"failed":139},{"name":"simd_boolean.wast","passed":123,"failed":154},{"name":"simd_const.wast","passed":551,"failed":206},{"name":"simd_conversions.wast","passed":50,"failed":232},{"name":"simd_f32x4.wast","passed":18,"failed":772},{"name":"simd_f32x4_arith.wast","passed":19,"failed":1803},{"name":"simd_f32x4_cmp.wast","passed":26,"failed":2581},{"name":"simd_f32x4_pmin_pmax.wast","passed":15,"failed":3872},{"name":"simd_f32x4_rounding.wast","passed":25,"failed":176},{"name":"simd_f64x2.wast","passed":10,"failed":793},{"name":"simd_f64x2_arith.wast","passed":19,"failed":1806},{"name":"simd_f64x2_cmp.wast","passed":26,"failed":2659},{"name":"simd_f64x2_pmin_pmax.wast","passed":15,"failed":3872},{"name":"simd_f64x2_rounding.wast","passed":25,"failed":176},{"name":"simd_i16x8_arith.wast","passed":13,"failed":181},{"name":"simd_i16x8_arith2.wast","passed":21,"failed":151},{"name":"simd_i16x8_cmp.wast","passed":32,"failed":433},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":5,"failed":16},{"name":"simd_i16x8_extmul_i8x16.wast","passed":13,"failed":104},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":4,"failed":26},{"name":"simd_i16x8_sat_arith.wast","passed":18,"failed":204},{"name":"simd_i32x4_arith.wast","passed":13,"failed":181},{"name":"simd_i32x4_arith2.wast","passed":28,"failed":121},{"name":"simd_i32x4_cmp.wast","passed":42,"failed":433},{"name":"simd_i32x4_dot_i16x8.wast","passed":4,"failed":26},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":5,"failed":16},{"name":"simd_i32x4_extmul_i16x8.wast","passed":13,"failed":104},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":5,"failed":102},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":5,"failed":102},{"name":"simd_i64x2_arith.wast","passed":13,"failed":187},{"name":"simd_i64x2_arith2.wast","passed":4,"failed":21},{"name":"simd_i64x2_cmp.wast","passed":11,"failed":102},{"name":"simd_i64x2_extmul_i32x4.wast","passed":13,"failed":104},{"name":"simd_i8x16_arith.wast","passed":10,"failed":121},{"name":"simd_i8x16_arith2.wast","passed":27,"failed":184},{"name":"simd_i8x16_cmp.wast","passed":32,"failed":413},{"name":"simd_i8x16_sat_arith.wast","passed":26,"failed":188},{"name":"simd_int_to_int_extend.wast","passed":25,"failed":228},{"name":"simd_lane.wast","passed":200,"failed":275},{"name":"simd_linking.wast","passed":0,"failed":3},{"name":"simd_load.wast","passed":22,"failed":17},{"name":"simd_load16_lane.wast","passed":4,"failed":32},{"name":"simd_load32_lane.wast","passed":4,"failed":20},{"name":"simd_load64_lane.wast","passed":4,"failed":12},{"name":"simd_load8_lane.wast","passed":4,"failed":48},{"name":"simd_load_extend.wast","passed":20,"failed":84},{"name":"simd_load_splat.wast","passed":14,"failed":112},{"name":"simd_load_zero.wast","passed":12,"failed":27},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_splat.wast","passed":26,"failed":159},{"name":"simd_store.wast","passed":11,"failed":17},{"name":"simd_store16_lane.wast","passed":3,"failed":33},{"name":"simd_store32_lane.wast","passed":3,"failed":21},{"name":"simd_store64_lane.wast","passed":3,"failed":13},{"name":"simd_store8_lane.wast","passed":3,"failed":49}] +0.9.0-alpha.0,14613,11367,[{"name":"simd_address.wast","passed":48,"failed":1},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":41,"failed":211},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":241,"failed":36},{"name":"simd_const.wast","passed":751,"failed":6},{"name":"simd_conversions.wast","passed":50,"failed":232},{"name":"simd_f32x4.wast","passed":629,"failed":161},{"name":"simd_f32x4_arith.wast","passed":1357,"failed":465},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":15,"failed":3872},{"name":"simd_f32x4_rounding.wast","passed":148,"failed":53},{"name":"simd_f64x2.wast","passed":639,"failed":164},{"name":"simd_f64x2_arith.wast","passed":1360,"failed":465},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":15,"failed":3872},{"name":"simd_f64x2_rounding.wast","passed":148,"failed":53},{"name":"simd_i16x8_arith.wast","passed":138,"failed":56},{"name":"simd_i16x8_arith2.wast","passed":142,"failed":30},{"name":"simd_i16x8_cmp.wast","passed":436,"failed":29},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":5,"failed":16},{"name":"simd_i16x8_extmul_i8x16.wast","passed":13,"failed":104},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":4,"failed":26},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":138,"failed":56},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":450,"failed":25},{"name":"simd_i32x4_dot_i16x8.wast","passed":4,"failed":26},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":5,"failed":16},{"name":"simd_i32x4_extmul_i16x8.wast","passed":13,"failed":104},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":5,"failed":102},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":5,"failed":102},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":97,"failed":16},{"name":"simd_i64x2_extmul_i32x4.wast","passed":13,"failed":104},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":148,"failed":63},{"name":"simd_i8x16_cmp.wast","passed":409,"failed":36},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":25,"failed":228},{"name":"simd_lane.wast","passed":213,"failed":262},{"name":"simd_linking.wast","passed":0,"failed":3},{"name":"simd_load.wast","passed":34,"failed":5},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":20,"failed":84},{"name":"simd_load_splat.wast","passed":14,"failed":112},{"name":"simd_load_zero.wast","passed":12,"failed":27},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_splat.wast","passed":157,"failed":28},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":3,"failed":33},{"name":"simd_store32_lane.wast","passed":3,"failed":21},{"name":"simd_store64_lane.wast","passed":3,"failed":13},{"name":"simd_store8_lane.wast","passed":3,"failed":49}] diff --git a/crates/tinywasm/tests/testsuite/util.rs b/crates/tinywasm/tests/testsuite/util.rs index f8f862b..91a1e41 100644 --- a/crates/tinywasm/tests/testsuite/util.rs +++ b/crates/tinywasm/tests/testsuite/util.rs @@ -1,9 +1,9 @@ use std::panic::{self, AssertUnwindSafe}; -use eyre::{bail, eyre, Result}; +use eyre::{Result, bail, eyre}; use tinywasm_types::{ExternRef, FuncRef, ModuleInstanceAddr, TinyWasmModule, ValType, WasmValue}; use wasm_testsuite::wast; -use wasm_testsuite::wast::{core::AbstractHeapType, QuoteWat}; +use wasm_testsuite::wast::{QuoteWat, core::AbstractHeapType}; pub fn try_downcast_panic(panic: Box) -> String { let info = panic.downcast_ref::().or(None).map(ToString::to_string).clone(); @@ -96,7 +96,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result WasmValue::F32(f32::from_bits(f.bits)), F64(f) => WasmValue::F64(f64::from_bits(f.bits)), @@ -117,19 +117,21 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result u128 { - match i { +fn wast_i128_to_i128(i: wast::core::V128Pattern) -> i128 { + let res: Vec = match i { wast::core::V128Pattern::F32x4(f) => { - f.iter().fold(0, |acc, &f| (acc << 32) | nanpattern2tinywasmvalue(f).unwrap().as_f32().unwrap() as u128) + f.iter().map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f32().unwrap().to_le_bytes()).flatten().collect() } wast::core::V128Pattern::F64x2(f) => { - f.iter().fold(0, |acc, &f| (acc << 64) | nanpattern2tinywasmvalue(f).unwrap().as_f64().unwrap() as u128) + f.iter().map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f64().unwrap().to_le_bytes()).flatten().collect() } - wast::core::V128Pattern::I16x8(f) => f.iter().fold(0, |acc, &f| (acc << 16) | f as u128), - wast::core::V128Pattern::I32x4(f) => f.iter().fold(0, |acc, &f| (acc << 32) | f as u128), - wast::core::V128Pattern::I64x2(f) => f.iter().fold(0, |acc, &f| (acc << 64) | f as u128), - wast::core::V128Pattern::I8x16(f) => f.iter().fold(0, |acc, &f| (acc << 8) | f as u128), - } + wast::core::V128Pattern::I16x8(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), + wast::core::V128Pattern::I32x4(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), + wast::core::V128Pattern::I64x2(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), + wast::core::V128Pattern::I8x16(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), + }; + + i128::from_le_bytes(res.try_into().unwrap()) } fn wastret2tinywasmvalue(ret: wast::WastRet) -> Result { @@ -137,7 +139,7 @@ fn wastret2tinywasmvalue(ret: wast::WastRet) -> Result nanpattern2tinywasmvalue(f)?, F64(f) => nanpattern2tinywasmvalue(f)?, diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 24116e8..593af2f 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -36,6 +36,7 @@ pub enum ConstInstruction { I64Const(i64), F32Const(f32), F64Const(f64), + V128Const(i128), GlobalGet(GlobalAddr), RefFunc(Option), RefExtern(Option), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index d9f2234..470c631 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -259,7 +259,7 @@ pub struct WasmFunction { #[derive(Debug, Clone, PartialEq, Default)] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct WasmFunctionData { - pub v128_constants: Box<[u128]>, + pub v128_constants: Box<[i128]>, } /// A WebAssembly Module Export diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index 01a31d5..a9498cc 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -17,7 +17,7 @@ pub enum WasmValue { /// A 64-bit float. F64(f64), // /// A 128-bit vector - V128(u128), + V128(i128), RefExtern(ExternRef), RefFunc(FuncRef), @@ -112,6 +112,7 @@ impl WasmValue { Self::I64(i) => ConstInstruction::I64Const(*i), Self::F32(i) => ConstInstruction::F32Const(*i), Self::F64(i) => ConstInstruction::F64Const(*i), + Self::V128(i) => ConstInstruction::V128Const(*i), Self::RefFunc(i) => ConstInstruction::RefFunc(i.addr()), _ => unimplemented!("no const_instr for {:?}", self), } @@ -137,6 +138,7 @@ impl WasmValue { match (self, other) { (Self::I32(a), Self::I32(b)) => a == b, (Self::I64(a), Self::I64(b)) => a == b, + (Self::V128(a), Self::V128(b)) => a == b, (Self::RefExtern(addr), Self::RefExtern(addr2)) => addr == addr2, (Self::RefFunc(addr), Self::RefFunc(addr2)) => addr == addr2, (Self::F32(a), Self::F32(b)) => { @@ -190,7 +192,7 @@ impl WasmValue { } #[doc(hidden)] - pub fn as_v128(&self) -> Option { + pub fn as_v128(&self) -> Option { match self { Self::V128(i) => Some(*i), _ => None, @@ -309,4 +311,4 @@ macro_rules! impl_conversion_for_wasmvalue { } } -impl_conversion_for_wasmvalue! { i32 => I32, i64 => I64, f32 => F32, f64 => F64, u128 => V128, ExternRef => RefExtern, FuncRef => RefFunc } +impl_conversion_for_wasmvalue! { i32 => I32, i64 => I64, f32 => F32, f64 => F64, i128 => V128, ExternRef => RefExtern, FuncRef => RefFunc } -- cgit v1.3.1 From cdc0015b7752b5404f6edd2777ad62a9eb2e6244 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Thu, 3 Apr 2025 00:52:27 +0200 Subject: chore: update deps, cargo fmt Signed-off-by: Henry Gressmann --- Cargo.lock | 128 ++++++++------------- Cargo.toml | 6 +- crates/cli/src/bin.rs | 2 +- crates/cli/src/wat.rs | 2 +- crates/parser/src/lib.rs | 8 +- crates/tinywasm/Cargo.toml | 2 +- crates/tinywasm/src/interpreter/executor.rs | 4 +- crates/tinywasm/tests/host_func_signature_check.rs | 2 +- crates/tinywasm/tests/test-wasm-1.rs | 2 +- crates/tinywasm/tests/test-wasm-2.rs | 2 +- crates/tinywasm/tests/test-wasm-3.rs | 2 +- crates/tinywasm/tests/test-wasm-annotations.rs | 2 +- crates/tinywasm/tests/test-wasm-extended-const.rs | 2 +- crates/tinywasm/tests/test-wasm-multi-memory.rs | 2 +- crates/tinywasm/tests/test-wasm-relaxed-simd.rs | 2 +- crates/tinywasm/tests/test-wast.rs | 2 +- crates/tinywasm/tests/testsuite/mod.rs | 2 +- crates/tinywasm/tests/testsuite/run.rs | 4 +- crates/tinywasm/tests/testsuite/util.rs | 14 +-- examples/archive.rs | 2 +- examples/funcref_callbacks.rs | 2 +- examples/wasm-rust.rs | 2 +- 22 files changed, 82 insertions(+), 114 deletions(-) (limited to 'crates/cli') diff --git a/Cargo.lock b/Cargo.lock index 00d3aaa..48bfcf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,18 +114,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.31" +version = "4.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" +checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.31" +version = "4.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" +checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9" dependencies = [ "anstyle", "clap_lex", @@ -258,9 +258,9 @@ dependencies = [ [[package]] name = "half" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +checksum = "7db2ff139bba50379da6aa0766b52fdcb62cb5b263009b09ed58ba604e14bbd1" dependencies = [ "cfg-if", "crunchy", @@ -274,15 +274,15 @@ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hermit-abi" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +checksum = "fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e" [[package]] name = "humantime" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" [[package]] name = "include_dir" @@ -311,9 +311,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" dependencies = [ "equivalent", "hashbrown", @@ -321,9 +321,9 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.15" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi", "libc", @@ -353,9 +353,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.170" +version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "libm" @@ -365,9 +365,9 @@ checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "log" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "memchr" @@ -386,15 +386,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.3" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "oorandom" -version = "11.1.4" +version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "owo-colors" @@ -435,9 +435,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -520,18 +520,18 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "serde" -version = "1.0.218" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.218" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", @@ -552,9 +552,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.99" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -596,7 +596,7 @@ dependencies = [ "tinywasm-parser", "tinywasm-types", "wasm-testsuite", - "wast 227.0.0", + "wast", "wat", ] @@ -609,7 +609,7 @@ dependencies = [ "log", "pretty_env_logger", "tinywasm", - "wast 227.0.0", + "wast", ] [[package]] @@ -618,7 +618,7 @@ version = "0.9.0-alpha.0" dependencies = [ "log", "tinywasm-types", - "wasmparser 0.227.0", + "wasmparser", ] [[package]] @@ -664,50 +664,29 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.226.0" +version = "0.228.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d81b727619aec227dce83e7f7420d4e56c79acd044642a356ea045b98d4e13" +checksum = "05d30290541f2d4242a162bbda76b8f2d8b1ac59eab3568ed6f2327d52c9b2c4" dependencies = [ "leb128fmt", - "wasmparser 0.226.0", -] - -[[package]] -name = "wasm-encoder" -version = "0.227.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829806010c17fa417fa56a42b76efadb35d70dbd972de9f07373b87d2729b698" -dependencies = [ - "leb128fmt", - "wasmparser 0.227.0", + "wasmparser", ] [[package]] name = "wasm-testsuite" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01c897a970135c086793fa320de6632534ad7b4a519a3ca51c7ef40e6a567d7" +checksum = "ec81df5b65371f919b41f3682861d98f1c90d081cfd8cb68784eb5d942dc1e36" dependencies = [ "include_dir", - "wast 226.0.0", -] - -[[package]] -name = "wasmparser" -version = "0.226.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc28600dcb2ba68d7e5f1c3ba4195c2bddc918c0243fd702d0b6dbd05689b681" -dependencies = [ - "bitflags", - "indexmap", - "semver", + "wast", ] [[package]] name = "wasmparser" -version = "0.227.0" +version = "0.228.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c15e32b1ab55e5e112f7c1dabd0d3f57c61992bfb0c4d4a6f141fe65c10ba750" +checksum = "4abf1132c1fdf747d56bbc1bb52152400c70f336870f968b85e89ea422198ae3" dependencies = [ "bitflags", "indexmap", @@ -716,37 +695,24 @@ dependencies = [ [[package]] name = "wast" -version = "226.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb903956d0151eabb6c30a2304dd61e5c8d7182805226120c2b6d611fb09a26" -dependencies = [ - "bumpalo", - "leb128fmt", - "memchr", - "unicode-width", - "wasm-encoder 0.226.0", -] - -[[package]] -name = "wast" -version = "227.0.0" +version = "228.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9ba0f7fe54ce2895314110aac579043d43175f66201153a0549badfa0fb04e" +checksum = "9e5aae124478cb51439f6587f074a3a5e835afd22751c59a87b2e2a882727c97" dependencies = [ "bumpalo", "leb128fmt", "memchr", "unicode-width", - "wasm-encoder 0.227.0", + "wasm-encoder", ] [[package]] name = "wat" -version = "1.227.0" +version = "1.228.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc4d0762d835bf25be727f4320a8b08ce4451fb1e5868940ad7708503c6a6c9" +checksum = "7ec29c89a8d055df988de7236483bf569988ac3d6905899f6af5ef920f9385ad" dependencies = [ - "wast 227.0.0", + "wast", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 74ad676..56e0be1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,9 @@ default-members=[".", "crates/tinywasm", "crates/types", "crates/parser"] resolver="2" [workspace.dependencies] -wast="227" -wat="1.227" -wasmparser={version="0.227", default-features=false} +wast="228" +wat="1.228" +wasmparser={version="0.228", default-features=false} eyre="0.6" log="0.4" pretty_env_logger="0.5" diff --git a/crates/cli/src/bin.rs b/crates/cli/src/bin.rs index 6efbba1..8c0fe93 100644 --- a/crates/cli/src/bin.rs +++ b/crates/cli/src/bin.rs @@ -4,7 +4,7 @@ use argh::FromArgs; use args::WasmArg; use eyre::Result; use log::{debug, info}; -use tinywasm::{types::WasmValue, Module}; +use tinywasm::{Module, types::WasmValue}; use crate::args::to_wasm_args; mod args; diff --git a/crates/cli/src/wat.rs b/crates/cli/src/wat.rs index fd00a8e..8d2998d 100644 --- a/crates/cli/src/wat.rs +++ b/crates/cli/src/wat.rs @@ -1,6 +1,6 @@ use wast::{ - parser::{self, ParseBuffer}, Wat, + parser::{self, ParseBuffer}, }; pub fn wat2wasm(wat: &str) -> Vec { diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index e5022c5..1292fa6 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -70,8 +70,6 @@ impl Parser { gc_types: true, stack_switching: false, component_model: false, - component_model_nested_names: false, - component_model_values: false, exceptions: false, gc: false, memory_control: false, @@ -79,7 +77,11 @@ impl Parser { threads: false, shared_everything_threads: false, legacy_exceptions: false, - component_model_async: false, + cm_async: false, + cm_async_builtins: false, + cm_async_stackful: false, + cm_nested_names: false, + cm_values: false, }; Validator::new_with_features(features.into()) } diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 8af013d..5810f0e 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -20,7 +20,7 @@ tinywasm-types={version="0.9.0-alpha.0", path="../types", default-features=false libm={version="0.2", default-features=false} [dev-dependencies] -wasm-testsuite={version="0.5.0"} +wasm-testsuite={version="0.5.2"} indexmap="2.7" wast={workspace=true} wat={workspace=true} diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs index d6d8089..a0153af 100644 --- a/crates/tinywasm/src/interpreter/executor.rs +++ b/crates/tinywasm/src/interpreter/executor.rs @@ -440,12 +440,12 @@ impl<'store, 'stack> Executor<'store, 'stack> { I8x16Shl => self.stack.values.calculate_diff::(|a, b| Ok(b.shl(a as i8))).to_cf()?, I16x8Shl => self.stack.values.calculate_diff::(|a, b| Ok(b.shl(a as i16))).to_cf()?, - I32x4Shl => self.stack.values.calculate_diff::(|a, b| Ok(b.shl(a as i32))).to_cf()?, + I32x4Shl => self.stack.values.calculate_diff::(|a, b| Ok(b.shl(a))).to_cf()?, I64x2Shl => self.stack.values.calculate_diff::(|a, b| Ok(b.shl(a as i64))).to_cf()?, I8x16ShrS => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a as i8))).to_cf()?, I16x8ShrS => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a as i16))).to_cf()?, - I32x4ShrS => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a as i32))).to_cf()?, + I32x4ShrS => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a))).to_cf()?, I64x2ShrS => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a as i64))).to_cf()?, I8x16ShrU => self.stack.values.calculate_diff::(|a, b| Ok(b.shr(a as u8))).to_cf()?, diff --git a/crates/tinywasm/tests/host_func_signature_check.rs b/crates/tinywasm/tests/host_func_signature_check.rs index c60ade2..698ad61 100644 --- a/crates/tinywasm/tests/host_func_signature_check.rs +++ b/crates/tinywasm/tests/host_func_signature_check.rs @@ -1,8 +1,8 @@ use eyre::Result; use std::fmt::Write; use tinywasm::{ - types::{FuncType, ValType, WasmValue}, Extern, FuncContext, Imports, Module, Store, + types::{FuncType, ValType, WasmValue}, }; use tinywasm_types::ExternRef; diff --git a/crates/tinywasm/tests/test-wasm-1.rs b/crates/tinywasm/tests/test-wasm-1.rs index 94c83f9..be235ae 100644 --- a/crates/tinywasm/tests/test-wasm-1.rs +++ b/crates/tinywasm/tests/test-wasm-1.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{spec, SpecVersion}; +use wasm_testsuite::data::{SpecVersion, spec}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wasm-2.rs b/crates/tinywasm/tests/test-wasm-2.rs index 9b30ac0..0379ca6 100644 --- a/crates/tinywasm/tests/test-wasm-2.rs +++ b/crates/tinywasm/tests/test-wasm-2.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{spec, SpecVersion}; +use wasm_testsuite::data::{SpecVersion, spec}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wasm-3.rs b/crates/tinywasm/tests/test-wasm-3.rs index a0e2543..3e63dc5 100644 --- a/crates/tinywasm/tests/test-wasm-3.rs +++ b/crates/tinywasm/tests/test-wasm-3.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{spec, SpecVersion}; +use wasm_testsuite::data::{SpecVersion, spec}; fn main() -> Result<()> { if !std::env::args().any(|x| &x == "--enable") { diff --git a/crates/tinywasm/tests/test-wasm-annotations.rs b/crates/tinywasm/tests/test-wasm-annotations.rs index 3170241..beac9eb 100644 --- a/crates/tinywasm/tests/test-wasm-annotations.rs +++ b/crates/tinywasm/tests/test-wasm-annotations.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{proposal, Proposal}; +use wasm_testsuite::data::{Proposal, proposal}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wasm-extended-const.rs b/crates/tinywasm/tests/test-wasm-extended-const.rs index 7c9a304..888a49f 100644 --- a/crates/tinywasm/tests/test-wasm-extended-const.rs +++ b/crates/tinywasm/tests/test-wasm-extended-const.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{proposal, Proposal}; +use wasm_testsuite::data::{Proposal, proposal}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wasm-multi-memory.rs b/crates/tinywasm/tests/test-wasm-multi-memory.rs index d491fb1..30052b0 100644 --- a/crates/tinywasm/tests/test-wasm-multi-memory.rs +++ b/crates/tinywasm/tests/test-wasm-multi-memory.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{proposal, Proposal}; +use wasm_testsuite::data::{Proposal, proposal}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wasm-relaxed-simd.rs b/crates/tinywasm/tests/test-wasm-relaxed-simd.rs index 7af830a..0851d18 100644 --- a/crates/tinywasm/tests/test-wasm-relaxed-simd.rs +++ b/crates/tinywasm/tests/test-wasm-relaxed-simd.rs @@ -1,7 +1,7 @@ mod testsuite; use eyre::Result; use testsuite::TestSuite; -use wasm_testsuite::data::{proposal, Proposal}; +use wasm_testsuite::data::{Proposal, proposal}; fn main() -> Result<()> { TestSuite::set_log_level(log::LevelFilter::Off); diff --git a/crates/tinywasm/tests/test-wast.rs b/crates/tinywasm/tests/test-wast.rs index 33c716c..40b0e04 100644 --- a/crates/tinywasm/tests/test-wast.rs +++ b/crates/tinywasm/tests/test-wast.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use eyre::{bail, eyre, Result}; +use eyre::{Result, bail, eyre}; use owo_colors::OwoColorize; use testsuite::TestSuite; diff --git a/crates/tinywasm/tests/testsuite/mod.rs b/crates/tinywasm/tests/testsuite/mod.rs index ee0336e..c1ba46e 100644 --- a/crates/tinywasm/tests/testsuite/mod.rs +++ b/crates/tinywasm/tests/testsuite/mod.rs @@ -1,5 +1,5 @@ #![allow(unused)] -use eyre::{eyre, Result}; +use eyre::{Result, eyre}; use indexmap::IndexMap; use owo_colors::OwoColorize; use std::io::{BufRead, Seek, SeekFrom}; diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs index 0804266..d09efdb 100644 --- a/crates/tinywasm/tests/testsuite/run.rs +++ b/crates/tinywasm/tests/testsuite/run.rs @@ -2,14 +2,14 @@ use crate::testsuite::util::*; use std::{borrow::Cow, collections::HashMap, fs::canonicalize, path::PathBuf}; use super::TestSuite; -use eyre::{eyre, Result}; +use eyre::{Result, eyre}; use indexmap::IndexMap; use log::{debug, error, info}; use tinywasm::{Extern, Imports, ModuleInstance}; use tinywasm_types::{ExternVal, MemoryType, ModuleInstanceAddr, TableType, ValType, WasmValue}; use wasm_testsuite::data::TestFile; use wasm_testsuite::wast; -use wasm_testsuite::wast::{lexer::Lexer, parser::ParseBuffer, Wast}; +use wasm_testsuite::wast::{Wast, lexer::Lexer, parser::ParseBuffer}; #[derive(Default)] struct ModuleRegistry { diff --git a/crates/tinywasm/tests/testsuite/util.rs b/crates/tinywasm/tests/testsuite/util.rs index 91a1e41..5e8558a 100644 --- a/crates/tinywasm/tests/testsuite/util.rs +++ b/crates/tinywasm/tests/testsuite/util.rs @@ -102,7 +102,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result WasmValue::F64(f64::from_bits(f.bits)), I32(i) => WasmValue::I32(i), I64(i) => WasmValue::I64(i), - V128(i) => WasmValue::V128(i128::from_le_bytes(i.to_le_bytes()).try_into().unwrap()), + V128(i) => WasmValue::V128(i128::from_le_bytes(i.to_le_bytes())), RefExtern(v) => WasmValue::RefExtern(ExternRef::new(Some(v))), RefNull(t) => match t { wast::core::HeapType::Abstract { shared: false, ty: AbstractHeapType::Func } => { @@ -120,15 +120,15 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result i128 { let res: Vec = match i { wast::core::V128Pattern::F32x4(f) => { - f.iter().map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f32().unwrap().to_le_bytes()).flatten().collect() + f.iter().flat_map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f32().unwrap().to_le_bytes()).collect() } wast::core::V128Pattern::F64x2(f) => { - f.iter().map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f64().unwrap().to_le_bytes()).flatten().collect() + f.iter().flat_map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f64().unwrap().to_le_bytes()).collect() } - wast::core::V128Pattern::I16x8(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), - wast::core::V128Pattern::I32x4(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), - wast::core::V128Pattern::I64x2(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), - wast::core::V128Pattern::I8x16(f) => f.iter().map(|v| v.to_le_bytes()).flatten().collect(), + wast::core::V128Pattern::I16x8(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), + wast::core::V128Pattern::I32x4(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), + wast::core::V128Pattern::I64x2(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), + wast::core::V128Pattern::I8x16(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), }; i128::from_le_bytes(res.try_into().unwrap()) diff --git a/examples/archive.rs b/examples/archive.rs index 6a3d54e..7a1021b 100644 --- a/examples/archive.rs +++ b/examples/archive.rs @@ -1,5 +1,5 @@ use eyre::Result; -use tinywasm::{parser::Parser, types::TinyWasmModule, Module, Store}; +use tinywasm::{Module, Store, parser::Parser, types::TinyWasmModule}; const WASM: &str = r#" (module diff --git a/examples/funcref_callbacks.rs b/examples/funcref_callbacks.rs index df50e75..01f833c 100644 --- a/examples/funcref_callbacks.rs +++ b/examples/funcref_callbacks.rs @@ -1,5 +1,5 @@ use eyre::Result; -use tinywasm::{types::FuncRef, Extern, FuncContext, Imports, Module, Store}; +use tinywasm::{Extern, FuncContext, Imports, Module, Store, types::FuncRef}; fn main() -> Result<()> { by_func_ref_passed()?; diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index 95769f4..d5a6b2a 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -1,6 +1,6 @@ use std::hint::black_box; -use eyre::{eyre, Result}; +use eyre::{Result, eyre}; use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store}; /// Examples of using WebAssembly compiled from Rust with tinywasm. -- cgit v1.3.1