From bb17468c990ba2ef819e5d3349539bb7a4aaedbd Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 29 Aug 2026 14:34:58 +0200 Subject: chore: improve optimizer and simplify function execution - add stack-constant and fused local-update rewrites - split host and Wasm function storage and execution paths - add the default full feature - recursively discover WAST test files Signed-off-by: Henry --- crates/types/src/instructions.rs | 14 +++++++++++--- crates/types/src/operands.rs | 19 ++----------------- 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'crates/types/src') diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index b92a0f4..6a357ea 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -511,8 +511,9 @@ pub enum BinOp128 { #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum Instruction { LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr), - AddConst32(i32), AddConst64(Operand64Idx), + AddConst32(i32), AndConst32(i32), XorConst32(i32), ShrUConst32(i32), AddConst64(Operand64Idx), IncLocal32(I32LocalArg), IncLocal64(PackedOp64), + // 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), @@ -520,18 +521,25 @@ pub enum Instruction { AddLocalLocalSet32(LocalTripleArg), AddLocalLocalTee32(LocalTripleArg), BinOpLocalLocalSet32(PackedOp64), BinOpLocalLocalSet64(PackedOp64), BinOpLocalLocalSet128(PackedOp64), BinOpLocalLocalTee32(PackedOp64), BinOpLocalLocalTee64(PackedOp64), BinOpLocalLocalTee128(PackedOp64), + AddLocalConst32(I32LocalArg), SubLocalConst32(I32LocalArg), MulLocalConst32(I32LocalArg), + AndLocalConst32(I32LocalArg), ShrULocalConst32(I32LocalArg), BinOpLocalConst32(PackedOp64), BinOpLocalConst64(PackedOp128), - BinOpGlobalConst32(PackedOp64), BinOpGlobalConst64(PackedOp128), - BinOpGlobalConst128(PackedOp64)>), BinOpLocalConst128(PackedOp64)>), + BinOpLocalConst128(PackedOp64)>), BinOpLocalConstSet32(PackedOp64), BinOpLocalConstSet64(PackedOp128), BinOpLocalConstSet128(PackedOp64)>), BinOpLocalConstTee32(PackedOp64), BinOpLocalConstTee64(PackedOp128), BinOpLocalConstTee128(PackedOp64)>), + + BinOpStackConst32(BinOp, i32), BinOpStackConst64(PackedOp64), + BinOpStackLocal32(BinOp, LocalAddr), BinOpStackLocalSet32(BinOp, LocalAddr, LocalAddr), BinOpStackLocalTee32(BinOp, LocalAddr, LocalAddr), BinOpStackLocal128(BinOp128, LocalAddr), BinOpStackGlobal32(BinOp, u32), BinOpStackGlobal64(BinOp, u32), + BinOpGlobalConst32(PackedOp64), BinOpGlobalConst64(PackedOp128), + BinOpGlobalConst128(PackedOp64)>), + SetLocalConst32(I32LocalArg), SetLocalConst64(PackedOp64), SetLocalConst128(PackedOp128), IncMemoryLocal32(MemoryLocalArg), IncMemoryLocal64(MemoryLocalArg), StoreLocalLocal32(MemoryLocalArg), StoreLocalLocal64(MemoryLocalArg), StoreLocalLocal128(MemoryLocalArg), diff --git a/crates/types/src/operands.rs b/crates/types/src/operands.rs index edbab26..af1b17f 100644 --- a/crates/types/src/operands.rs +++ b/crates/types/src/operands.rs @@ -146,26 +146,11 @@ macro_rules! define_operand { define_operand!(Operand64, 8); define_operand!(Operand128, 16); -macro_rules! unwrap_or_unreachable { - ($value:expr) => {{ - match $value { - Some(value) => value, - None => { core::hint::cold_path(); unreachable!() }, - } - }}; - ($value:expr, $($arg:tt)+) => {{ - match $value { - Some(value) => value, - None => { core::hint::cold_path(); unreachable!($($arg)+) }, - } - }}; -} - impl Operand64Idx { /// Resolves this index to a copied 64-bit packed operand. #[inline(always)] pub fn resolve(self, data: &crate::WasmFunctionData) -> Operand64 { - (*unwrap_or_unreachable!(data.operands64.get(self.index()), "invalid 64-bit operand index")).cast() + data.operands64[self.index as usize].cast() } } @@ -173,7 +158,7 @@ impl Operand128Idx { /// Resolves this index to a copied 128-bit packed operand. #[inline(always)] pub fn resolve(self, data: &crate::WasmFunctionData) -> Operand128 { - (*unwrap_or_unreachable!(data.operands128.get(self.index()), "invalid 128-bit operand index")).cast() + data.operands128[self.index as usize].cast() } } -- cgit v1.3.1