diff --git a/crates/wasmi/src/engine/bytecode/construct.rs b/crates/wasmi/src/engine/bytecode/construct.rs index bb1aa7ffcb..7bc6e5bb14 100644 --- a/crates/wasmi/src/engine/bytecode/construct.rs +++ b/crates/wasmi/src/engine/bytecode/construct.rs @@ -18,9 +18,6 @@ use super::{ RegSpan, RegSpanIter, SignatureIdx, - StoreAtInstr, - StoreInstr, - StoreOffset16Instr, TableIdx, UnaryInstr, }; @@ -1621,43 +1618,43 @@ macro_rules! constructor_for_store_instrs { ( @impl fn $fn_name:ident() -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(ptr: Reg, offset: Const32) -> Self { - Self::$op_code(StoreInstr::new(ptr, offset)) + Self::$op_code { ptr, offset: u32::from(offset) } } }; ( @impl fn $fn_name:ident(at) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(address: Const32, value: Reg) -> Self { - Self::$op_code(StoreAtInstr::new(address, value)) + Self::$op_code { address: u32::from(address), value } } }; ( @impl fn $fn_name:ident(offset16) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(ptr: Reg, offset: u16, value: Reg) -> Self { - Self::$op_code(StoreOffset16Instr::new(ptr, offset.into(), value)) + Self::$op_code { ptr, offset: offset.into(), value } } }; ( @impl fn $fn_name:ident({offset16_imm}) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(ptr: Reg, offset: u16, value: i8) -> Self { - Self::$op_code(StoreOffset16Instr::new(ptr, offset.into(), value.into())) + Self::$op_code { ptr, offset: offset.into(), value: value.into() } } }; ( @impl fn $fn_name:ident({offset16_imm}) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(ptr: Reg, offset: u16, value: i16) -> Self { - Self::$op_code(StoreOffset16Instr::new(ptr, offset.into(), value.into())) + Self::$op_code { ptr, offset: offset.into(), value: value.into() } } }; ( @impl fn $fn_name:ident({at_imm}) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(address: Const32, value: i8) -> Self { - Self::$op_code(StoreAtInstr::new(address, value.into())) + Self::$op_code { address: u32::from(address), value: value.into() } } }; ( @impl fn $fn_name:ident({at_imm}) -> Self::$op_code:ident ) => { #[doc = concat!("Creates a new [`Instruction::", stringify!($op_code), "`].")] pub fn $fn_name(address: Const32, value: i16) -> Self { - Self::$op_code(StoreAtInstr::new(address, value.into())) + Self::$op_code { address: u32::from(address), value: value.into() } } }; } diff --git a/crates/wasmi/src/engine/bytecode/mod.rs b/crates/wasmi/src/engine/bytecode/mod.rs index 8d09324457..d835050479 100644 --- a/crates/wasmi/src/engine/bytecode/mod.rs +++ b/crates/wasmi/src/engine/bytecode/mod.rs @@ -30,9 +30,6 @@ pub(crate) use self::{ RegSpanIter, Sign, SignatureIdx, - StoreAtInstr, - StoreInstr, - StoreOffset16Instr, TableIdx, UnaryInstr, }, @@ -2163,127 +2160,364 @@ pub enum Instruction { /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I32Store(StoreInstr), + I32Store { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I32Store`] for 16-bit `offset`. - I32StoreOffset16(StoreOffset16Instr), + I32StoreOffset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I32StoreOffset16`] for constant 16-bit `value`. - I32StoreOffset16Imm16(StoreOffset16Instr>), + I32StoreOffset16Imm16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Const16, + }, /// Variant of [`Instruction::I32Store`] for constant `address`. - I32StoreAt(StoreAtInstr), + I32StoreAt { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I32StoreAt`] for constant 16-bit `value`. - I32StoreAtImm16(StoreAtInstr>), + I32StoreAtImm16 { + /// The value to be stored. + value: Const16, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i32.store8` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I32Store8(StoreInstr), + I32Store8 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I32Store8`] for 16-bit `offset`. - I32Store8Offset16(StoreOffset16Instr), + I32Store8Offset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I32Store8Offset16`] for constant `value`. - I32Store8Offset16Imm(StoreOffset16Instr), + I32Store8Offset16Imm { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: i8, + }, /// Variant of [`Instruction::I32Store8`] for constant `address`. - I32Store8At(StoreAtInstr), + I32Store8At { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I32Store8At`] for constant `value`. - I32Store8AtImm(StoreAtInstr), + I32Store8AtImm { + /// The value to be stored. + value: i8, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i32.store16` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I32Store16(StoreInstr), + I32Store16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I32Store16`] for 16-bit `offset`. - I32Store16Offset16(StoreOffset16Instr), + I32Store16Offset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I32Store16Offset16`] for constant `value`. - I32Store16Offset16Imm(StoreOffset16Instr), + I32Store16Offset16Imm { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: i16, + }, /// Variant of [`Instruction::I32Store16`] for constant `address`. - I32Store16At(StoreAtInstr), + I32Store16At { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I32Store16At`] for constant `value`. - I32Store16AtImm(StoreAtInstr), + I32Store16AtImm { + /// The value to be stored. + value: i16, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i64.store` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I64Store(StoreInstr), + I64Store { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I64Store`] for 16-bit `offset`. - I64StoreOffset16(StoreOffset16Instr), + I64StoreOffset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I64StoreOffset16`] for constant 16-bit `value`. - I64StoreOffset16Imm16(StoreOffset16Instr>), + I64StoreOffset16Imm16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Const16, + }, /// Variant of [`Instruction::I64Store`] for constant `address`. - I64StoreAt(StoreAtInstr), + I64StoreAt { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I64StoreAt`] for 16-bit `value`. - I64StoreAtImm16(StoreAtInstr>), + I64StoreAtImm16 { + /// The value to be stored. + value: Const16, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i64.store8` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I64Store8(StoreInstr), + I64Store8 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I64Store8`] for 16-bit `offset`. - I64Store8Offset16(StoreOffset16Instr), + I64Store8Offset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I64Store8Offset16`] for constant `value`. - I64Store8Offset16Imm(StoreOffset16Instr), + I64Store8Offset16Imm { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: i8, + }, /// Variant of [`Instruction::I64Store8`] for constant `address`. - I64Store8At(StoreAtInstr), + I64Store8At { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I64Store8At`] for constant `value`. - I64Store8AtImm(StoreAtInstr), + I64Store8AtImm { + /// The value to be stored. + value: i8, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i64.store16` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I64Store16(StoreInstr), + I64Store16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I64Store16`] for 16-bit `offset`. - I64Store16Offset16(StoreOffset16Instr), + I64Store16Offset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I64Store16Offset16`] for constant `value`. - I64Store16Offset16Imm(StoreOffset16Instr), + I64Store16Offset16Imm { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: i16, + }, /// Variant of [`Instruction::I64Store16`] for constant `address`. - I64Store16At(StoreAtInstr), + I64Store16At { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I64Store16At`] for constant `value`. - I64Store16AtImm(StoreAtInstr), + I64Store16AtImm { + /// The value to be stored. + value: i16, + /// The constant address to store the value. + address: u32, + }, /// Wasm `i64.store32` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by [`Instruction::Register`] to encode `value`. - I64Store32(StoreInstr), + I64Store32 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::I64Store32`] for 16-bit `offset`. - I64Store32Offset16(StoreOffset16Instr), + I64Store32Offset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::I64Store32Offset16`] for constant 16-bit `value`. - I64Store32Offset16Imm16(StoreOffset16Instr>), + I64Store32Offset16Imm16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Const16, + }, /// Variant of [`Instruction::I64Store32`] for constant `address`. - I64Store32At(StoreAtInstr), + I64Store32At { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Variant of [`Instruction::I64Store32At`] for constant 16-bit `value`. - I64Store32AtImm16(StoreAtInstr>), + I64Store32AtImm16 { + /// The value to be stored. + value: Const16, + /// The constant address to store the value. + address: u32, + }, /// Wasm `f32.store` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by an [`Instruction::Register`] to encode `value`. - F32Store(StoreInstr), + F32Store { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::F32Store`] for 16-bit `offset`. - F32StoreOffset16(StoreOffset16Instr), + F32StoreOffset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::F32Store`] for constant `address`. - F32StoreAt(StoreAtInstr), + F32StoreAt { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// Wasm `f32.store` equivalent Wasmi instruction. /// /// # Encoding /// /// Must be followed by an [`Instruction::Register`] to encode `value`. - F64Store(StoreInstr), + F64Store { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: u32, + }, /// Variant of [`Instruction::F32Store`] for 16-bit `offset`. - F64StoreOffset16(StoreOffset16Instr), + F64StoreOffset16 { + /// The register storing the pointer of the `store` instruction. + ptr: Reg, + /// The register storing the pointer offset of the `store` instruction. + offset: Const16, + /// The value to be stored. + value: Reg, + }, /// Variant of [`Instruction::F32Store`] for constant `address`. - F64StoreAt(StoreAtInstr), + F64StoreAt { + /// The value to be stored. + value: Reg, + /// The constant address to store the value. + address: u32, + }, /// `i32` equality comparison instruction: `r0 = r1 == r2` I32Eq(BinInstr), diff --git a/crates/wasmi/src/engine/bytecode/utils.rs b/crates/wasmi/src/engine/bytecode/utils.rs index c71be9b95c..bf22ceb9ce 100644 --- a/crates/wasmi/src/engine/bytecode/utils.rs +++ b/crates/wasmi/src/engine/bytecode/utils.rs @@ -1,4 +1,4 @@ -use super::{Const16, Const32}; +use super::Const16; use crate::{ core::UntypedVal, engine::{Instr, TranslationError}, @@ -321,78 +321,6 @@ impl UnaryInstr { } } -/// A general `store` instruction. -/// -/// # Encoding -/// -/// Must be followed by an [`Instruction::Register] to encode `value`. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct StoreInstr { - /// The register storing the pointer of the `store` instruction. - pub ptr: Reg, - /// The register storing the pointer offset of the `store` instruction. - pub offset: Const32, -} - -impl StoreInstr { - /// Creates a new [`StoreInstr`]. - pub fn new(ptr: Reg, offset: Const32) -> Self { - Self { ptr, offset } - } -} - -/// A `store` instruction. -/// -/// # Note -/// -/// - Variant of [`StoreInstr`] for 16-bit address offsets. -/// - This allow encoding of the entire [`Instruction`] in a single word. -/// -/// # Encoding -/// -/// Must be followed by an [`Instruction::Register] to encode `value`. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct StoreOffset16Instr { - /// The register storing the pointer of the `store` instruction. - pub ptr: Reg, - /// The register storing the pointer offset of the `store` instruction. - pub offset: Const16, - /// The value to be stored. - pub value: T, -} - -impl StoreOffset16Instr { - /// Creates a new [`StoreOffset16Instr`]. - pub fn new(ptr: Reg, offset: Const16, value: T) -> Self { - Self { ptr, offset, value } - } -} - -/// A `store` instruction. -/// -/// # Note -/// -/// Variant of [`StoreInstr`] for constant address values. -/// -/// # Encoding -/// -/// 1. `T is Register`: The stored `value` is loaded from the register. -/// 1. Otherwise `T` is stored inline, e.g. as `i8` or `i16` value. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct StoreAtInstr { - /// The constant address to store the value. - pub address: Const32, - /// The value to be stored. - pub value: T, -} - -impl StoreAtInstr { - /// Creates a new [`StoreAtInstr`]. - pub fn new(address: Const32, value: T) -> Self { - Self { address, value } - } -} - /// The sign of a value. #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Sign { diff --git a/crates/wasmi/src/engine/executor/instrs.rs b/crates/wasmi/src/engine/executor/instrs.rs index 97c6c73b31..55321445f4 100644 --- a/crates/wasmi/src/engine/executor/instrs.rs +++ b/crates/wasmi/src/engine/executor/instrs.rs @@ -650,61 +650,111 @@ impl<'engine> Executor<'engine> { ptr, offset, } => self.execute_i64_load32_u_offset16(result, ptr, offset)?, - Instr::I32Store(instr) => self.execute_i32_store(instr)?, - Instr::I32StoreOffset16(instr) => self.execute_i32_store_offset16(instr)?, - Instr::I32StoreOffset16Imm16(instr) => { - self.execute_i32_store_offset16_imm16(instr)? - } - Instr::I32StoreAt(instr) => self.execute_i32_store_at(instr)?, - Instr::I32StoreAtImm16(instr) => self.execute_i32_store_at_imm16(instr)?, - Instr::I32Store8(instr) => self.execute_i32_store8(instr)?, - Instr::I32Store8Offset16(instr) => self.execute_i32_store8_offset16(instr)?, - Instr::I32Store8Offset16Imm(instr) => { - self.execute_i32_store8_offset16_imm(instr)? - } - Instr::I32Store8At(instr) => self.execute_i32_store8_at(instr)?, - Instr::I32Store8AtImm(instr) => self.execute_i32_store8_at_imm(instr)?, - Instr::I32Store16(instr) => self.execute_i32_store16(instr)?, - Instr::I32Store16Offset16(instr) => self.execute_i32_store16_offset16(instr)?, - Instr::I32Store16Offset16Imm(instr) => { - self.execute_i32_store16_offset16_imm(instr)? - } - Instr::I32Store16At(instr) => self.execute_i32_store16_at(instr)?, - Instr::I32Store16AtImm(instr) => self.execute_i32_store16_at_imm(instr)?, - Instr::I64Store(instr) => self.execute_i64_store(instr)?, - Instr::I64StoreOffset16(instr) => self.execute_i64_store_offset16(instr)?, - Instr::I64StoreOffset16Imm16(instr) => { - self.execute_i64_store_offset16_imm16(instr)? - } - Instr::I64StoreAt(instr) => self.execute_i64_store_at(instr)?, - Instr::I64StoreAtImm16(instr) => self.execute_i64_store_at_imm16(instr)?, - Instr::I64Store8(instr) => self.execute_i64_store8(instr)?, - Instr::I64Store8Offset16(instr) => self.execute_i64_store8_offset16(instr)?, - Instr::I64Store8Offset16Imm(instr) => { - self.execute_i64_store8_offset16_imm(instr)? - } - Instr::I64Store8At(instr) => self.execute_i64_store8_at(instr)?, - Instr::I64Store8AtImm(instr) => self.execute_i64_store8_at_imm(instr)?, - Instr::I64Store16(instr) => self.execute_i64_store16(instr)?, - Instr::I64Store16Offset16(instr) => self.execute_i64_store16_offset16(instr)?, - Instr::I64Store16Offset16Imm(instr) => { - self.execute_i64_store16_offset16_imm(instr)? - } - Instr::I64Store16At(instr) => self.execute_i64_store16_at(instr)?, - Instr::I64Store16AtImm(instr) => self.execute_i64_store16_at_imm(instr)?, - Instr::I64Store32(instr) => self.execute_i64_store32(instr)?, - Instr::I64Store32Offset16(instr) => self.execute_i64_store32_offset16(instr)?, - Instr::I64Store32Offset16Imm16(instr) => { - self.execute_i64_store32_offset16_imm16(instr)? - } - Instr::I64Store32At(instr) => self.execute_i64_store32_at(instr)?, - Instr::I64Store32AtImm16(instr) => self.execute_i64_store32_at_imm16(instr)?, - Instr::F32Store(instr) => self.execute_f32_store(instr)?, - Instr::F32StoreOffset16(instr) => self.execute_f32_store_offset16(instr)?, - Instr::F32StoreAt(instr) => self.execute_f32_store_at(instr)?, - Instr::F64Store(instr) => self.execute_f64_store(instr)?, - Instr::F64StoreOffset16(instr) => self.execute_f64_store_offset16(instr)?, - Instr::F64StoreAt(instr) => self.execute_f64_store_at(instr)?, + Instr::I32Store { ptr, offset } => self.execute_i32_store(ptr, offset)?, + Instr::I32StoreOffset16 { ptr, offset, value } => { + self.execute_i32_store_offset16(ptr, offset, value)? + } + Instr::I32StoreOffset16Imm16 { ptr, offset, value } => { + self.execute_i32_store_offset16_imm16(ptr, offset, value)? + } + Instr::I32StoreAt { address, value } => { + self.execute_i32_store_at(address, value)? + } + Instr::I32StoreAtImm16 { address, value } => { + self.execute_i32_store_at_imm16(address, value)? + } + Instr::I32Store8 { ptr, offset } => self.execute_i32_store8(ptr, offset)?, + Instr::I32Store8Offset16 { ptr, offset, value } => { + self.execute_i32_store8_offset16(ptr, offset, value)? + } + Instr::I32Store8Offset16Imm { ptr, offset, value } => { + self.execute_i32_store8_offset16_imm(ptr, offset, value)? + } + Instr::I32Store8At { address, value } => { + self.execute_i32_store8_at(address, value)? + } + Instr::I32Store8AtImm { address, value } => { + self.execute_i32_store8_at_imm(address, value)? + } + Instr::I32Store16 { ptr, offset } => self.execute_i32_store16(ptr, offset)?, + Instr::I32Store16Offset16 { ptr, offset, value } => { + self.execute_i32_store16_offset16(ptr, offset, value)? + } + Instr::I32Store16Offset16Imm { ptr, offset, value } => { + self.execute_i32_store16_offset16_imm(ptr, offset, value)? + } + Instr::I32Store16At { address, value } => { + self.execute_i32_store16_at(address, value)? + } + Instr::I32Store16AtImm { address, value } => { + self.execute_i32_store16_at_imm(address, value)? + } + Instr::I64Store { ptr, offset } => self.execute_i64_store(ptr, offset)?, + Instr::I64StoreOffset16 { ptr, offset, value } => { + self.execute_i64_store_offset16(ptr, offset, value)? + } + Instr::I64StoreOffset16Imm16 { ptr, offset, value } => { + self.execute_i64_store_offset16_imm16(ptr, offset, value)? + } + Instr::I64StoreAt { address, value } => { + self.execute_i64_store_at(address, value)? + } + Instr::I64StoreAtImm16 { address, value } => { + self.execute_i64_store_at_imm16(address, value)? + } + Instr::I64Store8 { ptr, offset } => self.execute_i64_store8(ptr, offset)?, + Instr::I64Store8Offset16 { ptr, offset, value } => { + self.execute_i64_store8_offset16(ptr, offset, value)? + } + Instr::I64Store8Offset16Imm { ptr, offset, value } => { + self.execute_i64_store8_offset16_imm(ptr, offset, value)? + } + Instr::I64Store8At { address, value } => { + self.execute_i64_store8_at(address, value)? + } + Instr::I64Store8AtImm { address, value } => { + self.execute_i64_store8_at_imm(address, value)? + } + Instr::I64Store16 { ptr, offset } => self.execute_i64_store16(ptr, offset)?, + Instr::I64Store16Offset16 { ptr, offset, value } => { + self.execute_i64_store16_offset16(ptr, offset, value)? + } + Instr::I64Store16Offset16Imm { ptr, offset, value } => { + self.execute_i64_store16_offset16_imm(ptr, offset, value)? + } + Instr::I64Store16At { address, value } => { + self.execute_i64_store16_at(address, value)? + } + Instr::I64Store16AtImm { address, value } => { + self.execute_i64_store16_at_imm(address, value)? + } + Instr::I64Store32 { ptr, offset } => self.execute_i64_store32(ptr, offset)?, + Instr::I64Store32Offset16 { ptr, offset, value } => { + self.execute_i64_store32_offset16(ptr, offset, value)? + } + Instr::I64Store32Offset16Imm16 { ptr, offset, value } => { + self.execute_i64_store32_offset16_imm16(ptr, offset, value)? + } + Instr::I64Store32At { address, value } => { + self.execute_i64_store32_at(address, value)? + } + Instr::I64Store32AtImm16 { address, value } => { + self.execute_i64_store32_at_imm16(address, value)? + } + Instr::F32Store { ptr, offset } => self.execute_f32_store(ptr, offset)?, + Instr::F32StoreOffset16 { ptr, offset, value } => { + self.execute_f32_store_offset16(ptr, offset, value)? + } + Instr::F32StoreAt { address, value } => { + self.execute_f32_store_at(address, value)? + } + Instr::F64Store { ptr, offset } => self.execute_f64_store(ptr, offset)?, + Instr::F64StoreOffset16 { ptr, offset, value } => { + self.execute_f64_store_offset16(ptr, offset, value)? + } + Instr::F64StoreAt { address, value } => { + self.execute_f64_store_at(address, value)? + } Instr::I32Eq(instr) => self.execute_i32_eq(instr), Instr::I32EqImm16(instr) => self.execute_i32_eq_imm16(instr), Instr::I32Ne(instr) => self.execute_i32_ne(instr), diff --git a/crates/wasmi/src/engine/executor/instrs/store.rs b/crates/wasmi/src/engine/executor/instrs/store.rs index 4afbe0936e..f377259383 100644 --- a/crates/wasmi/src/engine/executor/instrs/store.rs +++ b/crates/wasmi/src/engine/executor/instrs/store.rs @@ -1,15 +1,7 @@ use super::Executor; use crate::{ core::{TrapCode, UntypedVal}, - engine::bytecode::{ - Const16, - Instruction, - InstructionPtr, - Reg, - StoreAtInstr, - StoreInstr, - StoreOffset16Instr, - }, + engine::bytecode::{Const16, Instruction, InstructionPtr, Reg}, Error, }; @@ -58,11 +50,11 @@ impl<'engine> Executor<'engine> { } #[inline(always)] - fn execute_store(&mut self, instr: StoreInstr, store_op: WasmStoreOp) -> Result<(), Error> { + fn execute_store(&mut self, ptr: Reg, offset: u32, store_op: WasmStoreOp) -> Result<(), Error> { let value = self.fetch_store_value(1); self.execute_store_wrap( - self.get_register(instr.ptr), - u32::from(instr.offset), + self.get_register(ptr), + offset, self.get_register(value), store_op, )?; @@ -72,13 +64,15 @@ impl<'engine> Executor<'engine> { #[inline(always)] fn execute_store_offset16( &mut self, - instr: StoreOffset16Instr, + ptr: Reg, + offset: Const16, + value: Reg, store_op: WasmStoreOp, ) -> Result<(), Error> { self.execute_store_wrap( - self.get_register(instr.ptr), - u32::from(instr.offset), - self.get_register(instr.value), + self.get_register(ptr), + u32::from(offset), + self.get_register(value), store_op, )?; self.try_next_instr() @@ -87,16 +81,18 @@ impl<'engine> Executor<'engine> { #[inline(always)] fn execute_store_offset16_imm16( &mut self, - instr: StoreOffset16Instr, + ptr: Reg, + offset: Const16, + value: V, store_op: WasmStoreOp, ) -> Result<(), Error> where T: From + Into, { self.execute_store_wrap( - self.get_register(instr.ptr), - u32::from(instr.offset), - T::from(instr.value).into(), + self.get_register(ptr), + u32::from(offset), + T::from(value).into(), store_op, )?; self.try_next_instr() @@ -105,13 +101,14 @@ impl<'engine> Executor<'engine> { #[inline(always)] fn execute_store_at( &mut self, - instr: StoreAtInstr, + address: u32, + value: Reg, store_op: WasmStoreOp, ) -> Result<(), Error> { self.execute_store_wrap( UntypedVal::from(0u32), - u32::from(instr.address), - self.get_register(instr.value), + address, + self.get_register(value), store_op, )?; self.try_next_instr() @@ -120,7 +117,8 @@ impl<'engine> Executor<'engine> { #[inline(always)] fn execute_store_at_imm16( &mut self, - instr: StoreAtInstr, + address: u32, + value: V, store_op: WasmStoreOp, ) -> Result<(), Error> where @@ -128,8 +126,8 @@ impl<'engine> Executor<'engine> { { self.execute_store_wrap( UntypedVal::from(0u32), - u32::from(instr.address), - T::from(instr.value).into(), + address, + T::from(value).into(), store_op, )?; self.try_next_instr() @@ -151,41 +149,46 @@ macro_rules! impl_execute_istore { $( #[doc = concat!("Executes an [`Instruction::", stringify!($var_store), "`].")] #[inline(always)] - pub fn $fn_store(&mut self, instr: StoreInstr) -> Result<(), Error> { - self.execute_store(instr, $impl_fn) + pub fn $fn_store(&mut self, ptr: Reg, offset: u32) -> Result<(), Error> { + self.execute_store(ptr, offset, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_off16), "`].")] #[inline(always)] pub fn $fn_store_off16( &mut self, - instr: StoreOffset16Instr, + ptr: Reg, + offset: Const16, + value: Reg, ) -> Result<(), Error> { - self.execute_store_offset16(instr, $impl_fn) + self.execute_store_offset16(ptr, offset, value, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_off16_imm16), "`].")] #[inline(always)] pub fn $fn_store_off16_imm16( &mut self, - instr: StoreOffset16Instr<$from_ty>, + ptr: Reg, + offset: Const16, + value: $from_ty, ) -> Result<(), Error> { - self.execute_store_offset16_imm16::<$to_ty, _>(instr, $impl_fn) + self.execute_store_offset16_imm16::<$to_ty, _>(ptr, offset, value, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_at), "`].")] #[inline(always)] - pub fn $fn_store_at(&mut self,instr: StoreAtInstr) -> Result<(), Error> { - self.execute_store_at(instr, $impl_fn) + pub fn $fn_store_at(&mut self, address: u32, value: Reg) -> Result<(), Error> { + self.execute_store_at(address, value, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_at_imm16), "`].")] #[inline(always)] pub fn $fn_store_at_imm16( &mut self, - instr: StoreAtInstr<$from_ty>, + address: u32, + value: $from_ty, ) -> Result<(), Error> { - self.execute_store_at_imm16::<$to_ty, _>(instr, $impl_fn) + self.execute_store_at_imm16::<$to_ty, _>(address, value, $impl_fn) } )* }; @@ -270,23 +273,25 @@ macro_rules! impl_execute_fstore { $( #[doc = concat!("Executes an [`Instruction::", stringify!($var_store), "`].")] #[inline(always)] - pub fn $fn_store(&mut self, instr: StoreInstr) -> Result<(), Error> { - self.execute_store(instr, $impl_fn) + pub fn $fn_store(&mut self, ptr: Reg, offset: u32) -> Result<(), Error> { + self.execute_store(ptr, offset, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_off16), "`].")] #[inline(always)] pub fn $fn_store_off16( &mut self, - instr: StoreOffset16Instr, + ptr: Reg, + offset: Const16, + value: Reg, ) -> Result<(), Error> { - self.execute_store_offset16(instr, $impl_fn) + self.execute_store_offset16(ptr, offset, value, $impl_fn) } #[doc = concat!("Executes an [`Instruction::", stringify!($var_store_at), "`].")] #[inline(always)] - pub fn $fn_store_at(&mut self, instr: StoreAtInstr) -> Result<(), Error> { - self.execute_store_at(instr, $impl_fn) + pub fn $fn_store_at(&mut self, address: u32, value: Reg) -> Result<(), Error> { + self.execute_store_at(address, value, $impl_fn) } )* } diff --git a/crates/wasmi/src/engine/translator/relink_result.rs b/crates/wasmi/src/engine/translator/relink_result.rs index 06e0365864..d447c2b977 100644 --- a/crates/wasmi/src/engine/translator/relink_result.rs +++ b/crates/wasmi/src/engine/translator/relink_result.rs @@ -277,47 +277,47 @@ impl Instruction { I::I64Load16uOffset16 { result, .. } | I::I64Load32sOffset16 { result, .. } | I::I64Load32uOffset16 { result, .. } => relink_simple(result, new_result, old_result), - I::I32Store(_) - | I::I32StoreOffset16(_) - | I::I32StoreOffset16Imm16(_) - | I::I32StoreAt(_) - | I::I32StoreAtImm16(_) - | I::I32Store8(_) - | I::I32Store8Offset16(_) - | I::I32Store8Offset16Imm(_) - | I::I32Store8At(_) - | I::I32Store8AtImm(_) - | I::I32Store16(_) - | I::I32Store16Offset16(_) - | I::I32Store16Offset16Imm(_) - | I::I32Store16At(_) - | I::I32Store16AtImm(_) - | I::I64Store(_) - | I::I64StoreOffset16(_) - | I::I64StoreOffset16Imm16(_) - | I::I64StoreAt(_) - | I::I64StoreAtImm16(_) - | I::I64Store8(_) - | I::I64Store8Offset16(_) - | I::I64Store8Offset16Imm(_) - | I::I64Store8At(_) - | I::I64Store8AtImm(_) - | I::I64Store16(_) - | I::I64Store16Offset16(_) - | I::I64Store16Offset16Imm(_) - | I::I64Store16At(_) - | I::I64Store16AtImm(_) - | I::I64Store32(_) - | I::I64Store32Offset16(_) - | I::I64Store32Offset16Imm16(_) - | I::I64Store32At(_) - | I::I64Store32AtImm16(_) - | I::F32Store(_) - | I::F32StoreOffset16(_) - | I::F32StoreAt(_) - | I::F64Store(_) - | I::F64StoreOffset16(_) - | I::F64StoreAt(_) => Ok(false), + I::I32Store { .. } + | I::I32StoreOffset16 { .. } + | I::I32StoreOffset16Imm16 { .. } + | I::I32StoreAt { .. } + | I::I32StoreAtImm16 { .. } + | I::I32Store8 { .. } + | I::I32Store8Offset16 { .. } + | I::I32Store8Offset16Imm { .. } + | I::I32Store8At { .. } + | I::I32Store8AtImm { .. } + | I::I32Store16 { .. } + | I::I32Store16Offset16 { .. } + | I::I32Store16Offset16Imm { .. } + | I::I32Store16At { .. } + | I::I32Store16AtImm { .. } + | I::I64Store { .. } + | I::I64StoreOffset16 { .. } + | I::I64StoreOffset16Imm16 { .. } + | I::I64StoreAt { .. } + | I::I64StoreAtImm16 { .. } + | I::I64Store8 { .. } + | I::I64Store8Offset16 { .. } + | I::I64Store8Offset16Imm { .. } + | I::I64Store8At { .. } + | I::I64Store8AtImm { .. } + | I::I64Store16 { .. } + | I::I64Store16Offset16 { .. } + | I::I64Store16Offset16Imm { .. } + | I::I64Store16At { .. } + | I::I64Store16AtImm { .. } + | I::I64Store32 { .. } + | I::I64Store32Offset16 { .. } + | I::I64Store32Offset16Imm16 { .. } + | I::I64Store32At { .. } + | I::I64Store32AtImm16 { .. } + | I::F32Store { .. } + | I::F32StoreOffset16 { .. } + | I::F32StoreAt { .. } + | I::F64Store { .. } + | I::F64StoreOffset16 { .. } + | I::F64StoreAt { .. } => Ok(false), I::I32Eq(instr) | I::I64Eq(instr) | I::I32Ne(instr) | diff --git a/crates/wasmi/src/engine/translator/visit_register.rs b/crates/wasmi/src/engine/translator/visit_register.rs index 6c068d08ab..7a5c5c9127 100644 --- a/crates/wasmi/src/engine/translator/visit_register.rs +++ b/crates/wasmi/src/engine/translator/visit_register.rs @@ -1,14 +1,10 @@ use crate::engine::bytecode::{ BinInstr, BinInstrImm, - Const16, Instruction, Reg, RegSpan, RegSpanIter, - StoreAtInstr, - StoreInstr, - StoreOffset16Instr, UnaryInstr, }; @@ -308,7 +304,6 @@ impl VisitInputRegisters for Instruction { Instruction::I64Load16uOffset16 { ptr, .. } | Instruction::I64Load32sOffset16 { ptr, .. } | Instruction::I64Load32uOffset16 { ptr, .. } => f(ptr), - Instruction::I32Store(instr) => instr.visit_input_registers(f), Instruction::I32LoadAt { .. } => {}, Instruction::I64LoadAt { .. } => {}, Instruction::F32LoadAt { .. } => {}, @@ -323,46 +318,47 @@ impl VisitInputRegisters for Instruction { Instruction::I64Load16uAt { .. } => {}, Instruction::I64Load32sAt { .. } => {}, Instruction::I64Load32uAt { .. } => {}, - Instruction::I32StoreOffset16(instr) => instr.visit_input_registers(f), - Instruction::I32StoreOffset16Imm16(instr) => instr.visit_input_registers(f), - Instruction::I32StoreAt(instr) => instr.visit_input_registers(f), - Instruction::I32StoreAtImm16(instr) => instr.visit_input_registers(f), - Instruction::I32Store8(instr) => instr.visit_input_registers(f), - Instruction::I32Store8Offset16(instr) => instr.visit_input_registers(f), - Instruction::I32Store8Offset16Imm(instr) => instr.visit_input_registers(f), - Instruction::I32Store8At(instr) => instr.visit_input_registers(f), - Instruction::I32Store8AtImm(instr) => instr.visit_input_registers(f), - Instruction::I32Store16(instr) => instr.visit_input_registers(f), - Instruction::I32Store16Offset16(instr) => instr.visit_input_registers(f), - Instruction::I32Store16Offset16Imm(instr) => instr.visit_input_registers(f), - Instruction::I32Store16At(instr) => instr.visit_input_registers(f), - Instruction::I32Store16AtImm(instr) => instr.visit_input_registers(f), - Instruction::I64Store(instr) => instr.visit_input_registers(f), - Instruction::I64StoreOffset16(instr) => instr.visit_input_registers(f), - Instruction::I64StoreOffset16Imm16(instr) => instr.visit_input_registers(f), - Instruction::I64StoreAt(instr) => instr.visit_input_registers(f), - Instruction::I64StoreAtImm16(instr) => instr.visit_input_registers(f), - Instruction::I64Store8(instr) => instr.visit_input_registers(f), - Instruction::I64Store8Offset16(instr) => instr.visit_input_registers(f), - Instruction::I64Store8Offset16Imm(instr) => instr.visit_input_registers(f), - Instruction::I64Store8At(instr) => instr.visit_input_registers(f), - Instruction::I64Store8AtImm(instr) => instr.visit_input_registers(f), - Instruction::I64Store16(instr) => instr.visit_input_registers(f), - Instruction::I64Store16Offset16(instr) => instr.visit_input_registers(f), - Instruction::I64Store16Offset16Imm(instr) => instr.visit_input_registers(f), - Instruction::I64Store16At(instr) => instr.visit_input_registers(f), - Instruction::I64Store16AtImm(instr) => instr.visit_input_registers(f), - Instruction::I64Store32(instr) => instr.visit_input_registers(f), - Instruction::I64Store32Offset16(instr) => instr.visit_input_registers(f), - Instruction::I64Store32Offset16Imm16(instr) => instr.visit_input_registers(f), - Instruction::I64Store32At(instr) => instr.visit_input_registers(f), - Instruction::I64Store32AtImm16(instr) => instr.visit_input_registers(f), - Instruction::F32Store(instr) => instr.visit_input_registers(f), - Instruction::F32StoreOffset16(instr) => instr.visit_input_registers(f), - Instruction::F32StoreAt(instr) => instr.visit_input_registers(f), - Instruction::F64Store(instr) => instr.visit_input_registers(f), - Instruction::F64StoreOffset16(instr) => instr.visit_input_registers(f), - Instruction::F64StoreAt(instr) => instr.visit_input_registers(f), + Instruction::I32Store { ptr, .. } | + Instruction::I32StoreOffset16Imm16 { ptr, .. } | + Instruction::I32Store8 { ptr, .. } | + Instruction::I32Store8Offset16Imm { ptr, .. } | + Instruction::I32Store16 { ptr, .. } | + Instruction::I32Store16Offset16Imm { ptr, .. } | + Instruction::I64Store { ptr, .. } | + Instruction::I64StoreOffset16Imm16 { ptr, .. } | + Instruction::I64Store8 { ptr, .. } | + Instruction::I64Store8Offset16Imm { ptr, .. } | + Instruction::I64Store16 { ptr, .. } | + Instruction::I64Store16Offset16Imm { ptr, .. } | + Instruction::I64Store32 { ptr, .. } | + Instruction::I64Store32Offset16Imm16 { ptr, .. } | + Instruction::F32Store { ptr, .. } | + Instruction::F64Store { ptr, .. } => f(ptr), + Instruction::F32StoreAt { value, .. } | + Instruction::F64StoreAt { value, .. } | + Instruction::I32StoreAt { value, .. } | + Instruction::I32Store8At { value, .. } | + Instruction::I32Store16At { value, .. } | + Instruction::I64StoreAt { value, .. } | + Instruction::I64Store8At { value, .. } | + Instruction::I64Store16At { value, .. } | + Instruction::I64Store32At { value, .. } => f(value), + Instruction::I32StoreAtImm16 { .. } | + Instruction::I32Store8AtImm { .. } | + Instruction::I32Store16AtImm { .. } | + Instruction::I64StoreAtImm16 { .. } | + Instruction::I64Store8AtImm { .. } | + Instruction::I64Store16AtImm { .. } | + Instruction::I64Store32AtImm16 { .. } => {} + Instruction::I32StoreOffset16 { ptr, value, ..} | + Instruction::I32Store8Offset16 { ptr, value, ..} | + Instruction::I32Store16Offset16 { ptr, value, ..} | + Instruction::I64StoreOffset16 { ptr, value, ..} | + Instruction::I64Store8Offset16 { ptr, value, ..} | + Instruction::I64Store16Offset16 { ptr, value, ..} | + Instruction::I64Store32Offset16 { ptr, value, ..} | + Instruction::F32StoreOffset16 { ptr, value, .. } | + Instruction::F64StoreOffset16 { ptr, value, .. } => visit_registers!(f, ptr, value), Instruction::I32Eq(instr) => instr.visit_input_registers(f), Instruction::I32EqImm16(instr) => instr.visit_input_registers(f), Instruction::I64Eq(instr) => instr.visit_input_registers(f), @@ -579,72 +575,6 @@ impl VisitInputRegisters for [Reg; N] { } } -impl VisitInputRegisters for StoreInstr { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.ptr); - } -} - -impl VisitInputRegisters for StoreAtInstr { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.value); - } -} - -impl VisitInputRegisters for StoreAtInstr { - fn visit_input_registers(&mut self, _f: impl FnMut(&mut Reg)) { - // Nothing to do. - } -} - -impl VisitInputRegisters for StoreAtInstr { - fn visit_input_registers(&mut self, _f: impl FnMut(&mut Reg)) { - // Nothing to do. - } -} - -impl VisitInputRegisters for StoreAtInstr> { - fn visit_input_registers(&mut self, _f: impl FnMut(&mut Reg)) { - // Nothing to do. - } -} - -impl VisitInputRegisters for StoreAtInstr> { - fn visit_input_registers(&mut self, _f: impl FnMut(&mut Reg)) { - // Nothing to do. - } -} - -impl VisitInputRegisters for StoreOffset16Instr { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - visit_registers!(f, &mut self.ptr, &mut self.value) - } -} - -impl VisitInputRegisters for StoreOffset16Instr { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.ptr) - } -} - -impl VisitInputRegisters for StoreOffset16Instr { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.ptr) - } -} - -impl VisitInputRegisters for StoreOffset16Instr> { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.ptr) - } -} - -impl VisitInputRegisters for StoreOffset16Instr> { - fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { - f(&mut self.ptr) - } -} - impl VisitInputRegisters for UnaryInstr { fn visit_input_registers(&mut self, mut f: impl FnMut(&mut Reg)) { f(&mut self.input)