From be3c350746e3dc6284b40349a8ac4a170d807c58 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 11 Aug 2026 00:09:26 +0200 Subject: chore: improve interpreter loop performance, add more super instructions Signed-off-by: Henry --- crates/parser/src/optimize.rs | 62 ++++++++++++ crates/tinywasm/src/interpreter/executor.rs | 148 ++++++++++++++++++---------- crates/tinywasm/src/interpreter/values.rs | 10 +- crates/types/src/instructions.rs | 19 ++-- 4 files changed, 172 insertions(+), 67 deletions(-) (limited to 'crates') diff --git a/crates/parser/src/optimize.rs b/crates/parser/src/optimize.rs index be37e5e..2b5e331 100644 --- a/crates/parser/src/optimize.rs +++ b/crates/parser/src/optimize.rs @@ -131,6 +131,14 @@ fn rewrite( rewrite!(instrs, i, [BinOpLocalConst64(BinOp::IShl, local, 32), Const64(32)] => [LocalGet64(local), I64Extend32S]); } } + instr @ (I32Eq | I32Ne | I32LtS | I32LtU | I32GtS | I32GtU | I32LeS | I32LeU | I32GeS | I32GeU) => { + let Some(op) = cmp_op(instr) else { unreachable!() }; + rewrite!(instrs, i, [LocalGet32(left), LocalGet32(right)] => CmpLocalLocal32(op, left, right)); + } + instr @ (I64Eq | I64Ne | I64LtS | I64LtU | I64GtS | I64GtU | I64LeS | I64LeU | I64GeS | I64GeU) => { + let Some(op) = cmp_op(instr) else { unreachable!() }; + rewrite!(instrs, i, [LocalGet64(left), LocalGet64(right)] => CmpLocalLocal64(op, left, right)); + } instr @ (F32Add | F32Mul | F32Min | F32Max) => { let Some(op) = float_bin_op(instr) else { unreachable!() }; rewrite!(instrs, i, [LocalGet32(a), LocalGet32(b)] => BinOpLocalLocal32(op, a, b)); @@ -543,6 +551,31 @@ fn rewrite( replace!(instrs, i, 1 => JumpIfNonZero64(target)); continue; }); + rewrite!(instrs, i, + [BinOpLocalConstTee32(BinOp::IAdd, local, delta, dst)] if (local == dst) => + IncLocalJump32 { target_ip: target, local, delta, on_zero: true } + ); + rewrite!(instrs, i, + [CmpLocalLocal32(op, left, right)] => + JumpCmpLocalLocal32 { target_ip: target, left, right, op: inverse_cmp_op(op) } + ); + rewrite!(instrs, i, + [CmpLocalLocal64(op, left, right)] => + JumpCmpLocalLocal64 { target_ip: target, left, right, op: inverse_cmp_op(op) } + ); + rewrite!(instrs, i, + [BinOpLocalConstTee32(BinOp::IAdd, local, delta, dst), LocalGet32(right), cmp] if + (local == dst && let Some(op) = cmp_op(cmp)) => + IncLocalJumpCmpLocal32 { target_ip: target, local, delta, right, op: inverse_cmp_op(op) } + ); + rewrite!(instrs, i, + [LocalGet32(local), cmp] if (let Some(op) = cmp_op(cmp)) => + JumpCmpStackLocal32 { target_ip: target, local, op: inverse_cmp_op(op) } + ); + rewrite!(instrs, i, + [LocalGet64(local), cmp] if (let Some(op) = cmp_op(cmp)) => + JumpCmpStackLocal64 { target_ip: target, local, op: inverse_cmp_op(op) } + ); rewrite!(instrs, i, [LocalGet32(local), Const32(imm), cmp] if (let Some(op) = cmp_op(cmp)) => match (imm, inverse_cmp_op(op)) { @@ -599,6 +632,31 @@ fn rewrite( replace!(instrs, i, 1 => JumpIfZero64(target)); continue; }); + rewrite!(instrs, i, + [BinOpLocalConstTee32(BinOp::IAdd, local, delta, dst)] if (local == dst) => + IncLocalJump32 { target_ip: target, local, delta, on_zero: false } + ); + rewrite!(instrs, i, + [CmpLocalLocal32(op, left, right)] => + JumpCmpLocalLocal32 { target_ip: target, left, right, op } + ); + rewrite!(instrs, i, + [CmpLocalLocal64(op, left, right)] => + JumpCmpLocalLocal64 { target_ip: target, left, right, op } + ); + rewrite!(instrs, i, + [BinOpLocalConstTee32(BinOp::IAdd, local, delta, dst), LocalGet32(right), cmp] if + (local == dst && let Some(op) = cmp_op(cmp)) => + IncLocalJumpCmpLocal32 { target_ip: target, local, delta, right, op } + ); + rewrite!(instrs, i, + [LocalGet32(local), cmp] if (let Some(op) = cmp_op(cmp)) => + JumpCmpStackLocal32 { target_ip: target, local, op } + ); + rewrite!(instrs, i, + [LocalGet64(local), cmp] if (let Some(op) = cmp_op(cmp)) => + JumpCmpStackLocal64 { target_ip: target, local, op } + ); rewrite!(instrs, i, [LocalGet32(local), Const32(imm), cmp] if (let Some(op) = cmp_op(cmp)) => match (imm, op) { @@ -861,6 +919,10 @@ fn instruction_target_mut(instr: &mut Instruction) -> Option<&mut u32> { | Instruction::BrOnCast(ip, _, _) | Instruction::JumpCmpStackConst32 { target_ip: ip, .. } | Instruction::JumpCmpStackConst64 { target_ip: ip, .. } + | Instruction::JumpCmpStackLocal32 { target_ip: ip, .. } + | Instruction::JumpCmpStackLocal64 { target_ip: ip, .. } + | Instruction::IncLocalJump32 { target_ip: ip, .. } + | Instruction::IncLocalJumpCmpLocal32 { target_ip: ip, .. } | Instruction::JumpIfLocalZero32 { target_ip: ip, .. } | Instruction::JumpIfLocalNonZero32 { target_ip: ip, .. } | Instruction::JumpIfLocalZero64 { target_ip: ip, .. } diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs index d9d00eb..2d2a745 100644 --- a/crates/tinywasm/src/interpreter/executor.rs +++ b/crates/tinywasm/src/interpreter/executor.rs @@ -65,7 +65,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { } #[inline(always)] - fn exec(&mut self) -> Result> { + fn exec(&mut self, instr_ptr: usize) -> Result> { macro_rules! stack_op { (unary $ty:ty, |$v:ident| $expr:expr) => { stack_op!(unary $ty => $ty, |$v| $expr) @@ -197,6 +197,11 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { <$vt>::local_set(&mut self.store.value_stack, &self.cf, *$dst, value); self.store.value_stack.push(value)?; }}; + (local_local_cmp $vt:ty, $cmp:ident, $op:ident, $a:ident, $b:ident) => {{ + let lhs = <$vt>::local_get(&self.store.value_stack, &self.cf, *$a); + let rhs = <$vt>::local_get(&self.store.value_stack, &self.cf, *$b); + self.store.value_stack.push(i32::from($cmp(lhs, rhs, *$op)))?; + }}; (local_const $vt:ty, $width:tt, $op:ident, $local:ident, $rhs:expr) => {{ let lhs = <$vt>::local_get(&self.store.value_stack, &self.cf, *$local); self.store.value_stack.push(exec_binop!($width, *$op, lhs, $rhs))?; @@ -222,14 +227,14 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { use tinywasm_types::Instruction::*; #[rustfmt::skip] - match &self.func.instructions[self.cf.instr_ptr] { + match &self.func.instructions[instr_ptr] { Unreachable => { cold_path(); return Err(Trap::Unreachable.into()) }, Drop32 => { _ = Value32::stack_pop(&mut self.store.value_stack)}, Drop64 => { _ = Value64::stack_pop(&mut self.store.value_stack)}, Drop128 => { _ = Value128::stack_pop(&mut self.store.value_stack)}, - Select32 => Value32::stack_select(&mut self.store.value_stack)?, - Select64 => Value64::stack_select(&mut self.store.value_stack)?, - Select128 => Value128::stack_select(&mut self.store.value_stack)?, + Select32 => Value32::stack_select(&mut self.store.value_stack), + Select64 => Value64::stack_select(&mut self.store.value_stack), + Select128 => Value128::stack_select(&mut self.store.value_stack), SelectMulti(counts) => self.store.value_stack.select_multi(*counts), Call(v) => { self.exec_call_direct(*v)?; return Ok(None); } CallSelf => { self.exec_call_self()?; return Ok(None); } @@ -255,6 +260,10 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { JumpIfLocalNonZero64 { target_ip, local } => if self.exec_jump_local_non_zero_64(*target_ip, *local) { return Ok(None) }, JumpCmpStackConst32 { target_ip, imm, op } => if self.exec_jump_cmp_stack_const_32(*target_ip, *imm, *op) { return Ok(None) }, JumpCmpStackConst64 { target_ip, imm, op } => if self.exec_jump_cmp_stack_const_64(*target_ip, *imm, *op) { return Ok(None) }, + JumpCmpStackLocal32 { target_ip, local, op } => if self.exec_jump_cmp_stack_local_32(*target_ip, *local, *op) { return Ok(None) }, + JumpCmpStackLocal64 { target_ip, local, op } => if self.exec_jump_cmp_stack_local_64(*target_ip, *local, *op) { return Ok(None) }, + IncLocalJump32 { target_ip, local, delta, on_zero } => if self.exec_inc_local_jump_32(*target_ip, *local, *delta, *on_zero) { return Ok(None) }, + IncLocalJumpCmpLocal32 { target_ip, local, delta, right, op } => if self.exec_inc_local_jump_cmp_local_32(*target_ip, *local, *delta, *right, *op) { return Ok(None) }, JumpCmpLocalConst32 { target_ip, local, imm, op } => if self.exec_jump_cmp_local_const_32(*target_ip, *local, *imm, *op) { return Ok(None) }, JumpCmpLocalConst64 { target_ip, local, imm, op } => if self.exec_jump_cmp_local_const_64(*target_ip, *local, *imm, *op) { return Ok(None) }, JumpCmpLocalLocal32 { target_ip, left, right, op } => if self.exec_jump_cmp_local_local_32(*target_ip, *left, *right, *op) { return Ok(None) }, @@ -288,6 +297,8 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { BinOpLocalLocal32(op, a, b) => binop!(local_local Value32, 32, op, a, b), BinOpLocalLocal64(op, a, b) => binop!(local_local Value64, 64, op, a, b), BinOpLocalLocal128(op, a, b) => binop!(local_local Value128, 128, op, a, b), + CmpLocalLocal32(op, a, b) => binop!(local_local_cmp i32, cmp_i32, op, a, b), + CmpLocalLocal64(op, a, b) => binop!(local_local_cmp i64, cmp_i64, op, a, b), BinOpLocalLocalSet32(op, a, b, dst) => binop!(local_local_set Value32, 32, op, a, b, dst), BinOpLocalLocalSet64(op, a, b, dst) => binop!(local_local_set Value64, 64, op, a, b, dst), BinOpLocalLocalSet128(op, a, b, dst) => binop!(local_local_set Value128, 128, op, a, b, dst), @@ -313,24 +324,12 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { StoreLocalLocal32(m, addr_local, value_local) => self.exec_store_local_local::(*m, *addr_local, *value_local)?, StoreLocalLocal64(m, addr_local, value_local) => self.exec_store_local_local::(*m, *addr_local, *value_local)?, StoreLocalLocal128(m, addr_local, value_local) => self.exec_store_local_local::(*m, *addr_local, *value_local)?, - LoadLocal32(m, addr_local) => self.store.value_stack.push(self.exec_load_local_value::(*m, *addr_local)?)?, - LoadLocal64(m, addr_local) => self.store.value_stack.push(self.exec_load_local_value::(*m, *addr_local)?)?, - LoadLocal8S32(m, addr_local) => { - let value = self.exec_load_local_value::(*m, *addr_local)?; - self.store.value_stack.push(i32::from(value))?; - } - LoadLocal8U32(m, addr_local) => { - let value = self.exec_load_local_value::(*m, *addr_local)?; - self.store.value_stack.push(i32::from(value))?; - } - LoadLocal16S32(m, addr_local) => { - let value = self.exec_load_local_value::(*m, *addr_local)?; - self.store.value_stack.push(i32::from(value))?; - } - LoadLocal16U32(m, addr_local) => { - let value = self.exec_load_local_value::(*m, *addr_local)?; - self.store.value_stack.push(i32::from(value))?; - } + LoadLocal32(m, addr_local) => self.exec_load_local::(*m, *addr_local, |v| v)?, + LoadLocal64(m, addr_local) => self.exec_load_local::(*m, *addr_local, |v| v)?, + LoadLocal8S32(m, addr_local) => self.exec_load_local::(*m, *addr_local, i32::from)?, + LoadLocal8U32(m, addr_local) => self.exec_load_local::(*m, *addr_local, i32::from)?, + LoadLocal16S32(m, addr_local) => self.exec_load_local::(*m, *addr_local, i32::from)?, + LoadLocal16U32(m, addr_local) => self.exec_load_local::(*m, *addr_local, i32::from)?, LoadLocalTee32(m, addr_local, dst_local) => self.exec_load_local_tee::(*m, *addr_local, *dst_local, |v| v)?, LoadLocalSet32(m, addr_local, dst_local) => self.exec_load_local_set::(*m, *addr_local, *dst_local, |v| v)?, LoadLocalTee8S32(m, addr_local, dst_local) => self.exec_load_local_tee::(*m, *addr_local, *dst_local, i32::from)?, @@ -466,17 +465,8 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { I31GetS => self.exec_i31_get(true)?, I31GetU => self.exec_i31_get(false)?, RefEq => stack_op!(binary ValueRef => i32, |a, b| i32::from(a == b)), - RefTest(ty) => { - let value = ValueRef::stack_pop(&mut self.store.value_stack); - let ty = self.canonical_ref_type(*ty); - self.store.value_stack.push(i32::from(self.store.state.value_ref_matches(value, ty)))?; - } - RefCast(ty) => { - if !self.exec_ref_matches(*ty) { - cold_path(); - return Err(Trap::CastFailure.into()); - } - } + RefTest(ty) => self.exec_ref_test(*ty)?, + RefCast(ty) => self.exec_ref_cast(*ty)?, // GC objects StructNew(ty) => self.exec_struct_new(*ty, false)?, StructNewDefault(ty) => self.exec_struct_new(*ty, true)?, @@ -864,7 +854,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { I32x4RelaxedTruncF64x2UZero => stack_op!(unary Value128, |v| v.i32x4_relaxed_trunc_f64x2_u_zero()), }; - self.cf.instr_ptr += 1; + self.cf.instr_ptr = instr_ptr + 1; Ok(None) } @@ -951,6 +941,42 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { self.jump_if(condition, target_ip) } + #[inline(always)] + fn exec_jump_cmp_stack_local_32(&mut self, target_ip: u32, local: LocalAddr, op: CmpOp) -> bool { + let lhs = ::stack_pop(&mut self.store.value_stack); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, local); + self.jump_if(cmp_i32(lhs, rhs, op), target_ip) + } + + #[inline(always)] + fn exec_jump_cmp_stack_local_64(&mut self, target_ip: u32, local: LocalAddr, op: CmpOp) -> bool { + let lhs = ::stack_pop(&mut self.store.value_stack); + let rhs = i64::local_get(&self.store.value_stack, &self.cf, local); + self.jump_if(cmp_i64(lhs, rhs, op), target_ip) + } + + #[inline(always)] + fn exec_inc_local_jump_32(&mut self, target_ip: u32, local: LocalAddr, delta: i32, on_zero: bool) -> bool { + let value = i32::local_get(&self.store.value_stack, &self.cf, local).wrapping_add(delta); + i32::local_set(&mut self.store.value_stack, &self.cf, local, value); + self.jump_if((value == 0) == on_zero, target_ip) + } + + #[inline(always)] + fn exec_inc_local_jump_cmp_local_32( + &mut self, + target_ip: u32, + local: LocalAddr, + delta: i32, + right: LocalAddr, + op: CmpOp, + ) -> bool { + let lhs = i32::local_get(&self.store.value_stack, &self.cf, local).wrapping_add(delta); + i32::local_set(&mut self.store.value_stack, &self.cf, local, lhs); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, right); + self.jump_if(cmp_i32(lhs, rhs, op), target_ip) + } + #[inline(always)] fn exec_jump_cmp_local_const_32(&mut self, target_ip: u32, local: LocalAddr, imm: i32, op: CmpOp) -> bool { self.jump_if(cmp_i32(i32::local_get(&self.store.value_stack, &self.cf, local), imm, op), target_ip) @@ -1372,6 +1398,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { self.finish_return() } + #[inline(always)] fn exec_store_local_local, const N: usize>( &mut self, memarg: MemoryArg, @@ -1382,8 +1409,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { let value = T::local_get(&self.store.value_stack, &self.cf, u16::from(value_local)); let mem = self.store.state.get_mem_mut(self.module.resolve_mem_addr(memarg.mem_addr())); let addr = mem.effective_addr_32::(base, memarg.offset())?; - value.store_at(&mut *mem.inner, addr)?; - Ok(()) + value.store_at(&mut *mem.inner, addr) } #[inline(always)] @@ -1439,6 +1465,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { T::local_update(&mut self.store.value_stack, &self.cf, acc, |v| add(mul(lhs, rhs), v)); } + #[inline(always)] fn exec_load_local_value, const N: usize>( &self, memarg: MemoryArg, @@ -1452,15 +1479,21 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { let base = u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); mem.effective_addr_32::(base, memarg.offset())? }; - match T::load_at(&*mem.inner, addr) { - Ok(res) => Ok(res), - Err(err) => { - cold_path(); - Err(err) - } - } + T::load_at(&*mem.inner, addr) + } + + #[inline(always)] + fn exec_load_local, const N: usize, TARGET: InternalValue>( + &mut self, + memarg: MemoryArg, + addr_local: u8, + cast: impl Fn(LOAD) -> TARGET, + ) -> Result<(), Trap> { + let value = cast(self.exec_load_local_value::(memarg, addr_local)?); + TARGET::stack_push(&mut self.store.value_stack, value) } + #[inline(always)] fn exec_load_local_tee, const N: usize, TARGET: InternalValue>( &mut self, memarg: MemoryArg, @@ -1474,6 +1507,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { Ok(()) } + #[inline(always)] fn exec_load_local_set, const N: usize, TARGET: InternalValue>( &mut self, memarg: MemoryArg, @@ -1514,6 +1548,20 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)) } + fn exec_ref_test(&mut self, ty: RefType) -> Result<(), Trap> { + let value = ValueRef::stack_pop(&mut self.store.value_stack); + let matches = self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)); + self.store.value_stack.push(i32::from(matches)) + } + + fn exec_ref_cast(&self, ty: RefType) -> Result<(), Trap> { + if !self.exec_ref_matches(ty) { + cold_path(); + return Err(Trap::CastFailure); + } + Ok(()) + } + fn exec_i31_get(&mut self, signed: bool) -> Result<(), Trap> { let value = ValueRef::stack_pop(&mut self.store.value_stack); if value.is_null() { @@ -2037,10 +2085,10 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { impl<'store> Executor<'store, false> { #[inline(always)] - pub(crate) fn run_to_completion(&mut self) -> Result<()> { + pub(crate) fn run_to_completion(mut self) -> Result<()> { // ideally we use `loop_match` / `become` once thats stabilized loop { - if self.exec()?.is_some() { + if self.exec(self.cf.instr_ptr)?.is_some() { return Ok(()); } } @@ -2048,7 +2096,7 @@ impl<'store> Executor<'store, false> { #[cfg(feature = "std")] #[inline(always)] - pub(crate) fn run_with_time_budget(&mut self, time_budget: core::time::Duration) -> Result { + pub(crate) fn run_with_time_budget(mut self, time_budget: core::time::Duration) -> Result { use crate::std::time::Instant; let start = Instant::now(); if time_budget.is_zero() { @@ -2057,7 +2105,7 @@ impl<'store> Executor<'store, false> { loop { for _ in 0..128 { - if self.exec()?.is_some() { + if self.exec(self.cf.instr_ptr)?.is_some() { return Ok(ExecState::Completed); } } @@ -2071,7 +2119,7 @@ impl<'store> Executor<'store, false> { impl<'store> Executor<'store, true> { #[inline(always)] - pub(crate) fn run_with_fuel(&mut self, fuel: u32) -> Result { + pub(crate) fn run_with_fuel(mut self, fuel: u32) -> Result { self.store.execution_fuel = fuel; if self.store.execution_fuel == 0 { return Ok(ExecState::Suspended(self.cf)); @@ -2079,7 +2127,7 @@ impl<'store> Executor<'store, true> { loop { for _ in 0..128 { - if self.exec()?.is_some() { + if self.exec(self.cf.instr_ptr)?.is_some() { return Ok(ExecState::Completed); } } diff --git a/crates/tinywasm/src/interpreter/values.rs b/crates/tinywasm/src/interpreter/values.rs index b3382e8..cc91a55 100644 --- a/crates/tinywasm/src/interpreter/values.rs +++ b/crates/tinywasm/src/interpreter/values.rs @@ -135,7 +135,7 @@ pub(crate) trait InternalValue: sealed::Sealed + Copy + Default { fn stack_push(stack: &mut ValueStack, value: Self) -> Result<(), crate::Trap>; fn stack_pop(stack: &mut ValueStack) -> Self; fn stack_peek(stack: &ValueStack) -> Self; - fn stack_select(stack: &mut ValueStack) -> Result<(), crate::Trap>; + fn stack_select(stack: &mut ValueStack); fn local_get(stack: &ValueStack, frame: &CallFrame, index: LocalAddr) -> Self; fn local_set(stack: &mut ValueStack, frame: &CallFrame, index: LocalAddr, value: Self); fn local_update(stack: &mut ValueStack, frame: &CallFrame, index: LocalAddr, f: impl FnOnce(Self) -> Self); @@ -227,16 +227,14 @@ macro_rules! impl_internalvalue { } #[inline(always)] - fn stack_select(stack: &mut ValueStack) -> Result<(), crate::Trap> { + fn stack_select(stack: &mut ValueStack) { let cond = stack.stack_32.pop() as i32; let val2 = stack.$stack.pop(); if cond == 0 { - Self::stack_pop(stack); - stack.$stack.push(val2)?; + let val1 = stack.$stack.len() - 1; + stack.$stack.set(val1, val2); } - - Ok(()) } } )* diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 5eb5491..4e14d75 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -186,6 +186,7 @@ pub enum Instruction { // The 32/64 suffix describes the operand width. Future compare-style ops may still yield i32 results. BinOpLocalLocal32(BinOp, LocalAddr, LocalAddr), BinOpLocalLocal64(BinOp, LocalAddr, LocalAddr), BinOpLocalLocal128(BinOp128, LocalAddr, LocalAddr), + CmpLocalLocal32(CmpOp, LocalAddr, LocalAddr), CmpLocalLocal64(CmpOp, LocalAddr, LocalAddr), BinOpLocalLocalSet32(BinOp, LocalAddr, LocalAddr, LocalAddr), BinOpLocalLocalSet64(BinOp, LocalAddr, LocalAddr, LocalAddr), BinOpLocalLocalSet128(BinOp128, LocalAddr, LocalAddr, LocalAddr), @@ -255,6 +256,10 @@ pub enum Instruction { JumpIfLocalNonZero64 { target_ip: u32, local: LocalAddr }, JumpCmpStackConst32 { target_ip: u32, imm: i32, op: CmpOp }, JumpCmpStackConst64 { target_ip: u32, imm: i64, op: CmpOp }, + JumpCmpStackLocal32 { target_ip: u32, local: LocalAddr, op: CmpOp }, + JumpCmpStackLocal64 { target_ip: u32, local: LocalAddr, op: CmpOp }, + IncLocalJump32 { target_ip: u32, local: LocalAddr, delta: i32, on_zero: bool }, + IncLocalJumpCmpLocal32 { target_ip: u32, local: LocalAddr, delta: i32, right: LocalAddr, op: CmpOp }, JumpCmpLocalConst32 { target_ip: u32, local: LocalAddr, imm: i32, op: CmpOp }, JumpCmpLocalConst64 { target_ip: u32, local: LocalAddr, imm: i32, op: CmpOp }, JumpCmpLocalLocal32 { target_ip: u32, left: LocalAddr, right: LocalAddr, op: CmpOp }, @@ -477,9 +482,11 @@ pub enum Instruction { F64x2RelaxedMin, F64x2RelaxedMax, I16x8RelaxedQ15mulrS, I16x8RelaxedDotI8x16I7x16S, - I32x4RelaxedDotI8x16I7x16AddS + I32x4RelaxedDotI8x16I7x16AddS, } +const _: () = assert!(core::mem::size_of::() <= 16); + impl Instruction { #[inline] pub const fn memory_addr(&self) -> Option { @@ -564,13 +571,3 @@ impl Instruction { } } } - -#[cfg(test)] -mod tests { - use super::Instruction; - - #[test] - fn instruction_layout_size_is_stable() { - assert_eq!(core::mem::size_of::(), 16); - } -} -- cgit v1.3.1