Skip to content

Commit

Permalink
Lower load and store instructions by pruning types where possible (
Browse files Browse the repository at this point in the history
…#1303)

* add new load and store instructions

* remove replaced load and store instructions

* emit new load and store instructions in translator

* implement load{32,64} in wasmi_core

* implement load{32,64} instr in Wasmi executor

* implement store{32,64} support in wasmi_core

* implement new store instructions in executor

* apply rustfmt

* adjust tests for instruction changes

* fix intra doc links

* fix outdated docs and an invalid doc link

* remove no longer needed trait impls

* move trait impls down in file
  • Loading branch information
Robbepop authored Nov 10, 2024
1 parent 7a302a9 commit 1aa2256
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 584 deletions.
74 changes: 12 additions & 62 deletions crates/core/src/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,44 +178,24 @@ impl UntypedVal {
Self::load_extend::<T, T>(memory, address, offset)
}

/// Executes the `i32.load` Wasm operation.
/// Executes a Wasmi `load32` instruction.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` loads out of bounds from `memory`.
pub fn i32_load(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<i32>(memory, address, offset)
pub fn load32(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<u32>(memory, address, offset)
}

/// Executes the `i64.load` Wasm operation.
/// Executes a Wasmi `load64` instruction.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` loads out of bounds from `memory`.
pub fn i64_load(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<i64>(memory, address, offset)
}

/// Executes the `f32.load` Wasm operation.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` loads out of bounds from `memory`.
pub fn f32_load(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<F32>(memory, address, offset)
}

/// Executes the `f64.load` Wasm operation.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` loads out of bounds from `memory`.
pub fn f64_load(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<F64>(memory, address, offset)
pub fn load64(memory: &[u8], address: Self, offset: u32) -> Result<Self, TrapCode> {
Self::load::<u64>(memory, address, offset)
}

/// Executes the `i32.load8_s` Wasm operation.
Expand Down Expand Up @@ -355,64 +335,34 @@ impl UntypedVal {
Self::store_wrap::<T, T>(memory, address, offset, value)
}

/// Executes the `i32.store` Wasm operation.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` stores out of bounds from `memory`.
pub fn i32_store(
memory: &mut [u8],
address: Self,
offset: u32,
value: Self,
) -> Result<(), TrapCode> {
Self::store::<i32>(memory, address, offset, value)
}

/// Executes the `i64.store` Wasm operation.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` stores out of bounds from `memory`.
pub fn i64_store(
memory: &mut [u8],
address: Self,
offset: u32,
value: Self,
) -> Result<(), TrapCode> {
Self::store::<i64>(memory, address, offset, value)
}

/// Executes the `f32.store` Wasm operation.
/// Executes a Wasmi `store32` instruction.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` stores out of bounds from `memory`.
pub fn f32_store(
pub fn store32(
memory: &mut [u8],
address: Self,
offset: u32,
value: Self,
) -> Result<(), TrapCode> {
Self::store::<F32>(memory, address, offset, value)
Self::store::<u32>(memory, address, offset, value)
}

/// Executes the `f64.store` Wasm operation.
/// Executes a Wasmi `store64` instruction.
///
/// # Errors
///
/// - If `address + offset` overflows.
/// - If `address + offset` stores out of bounds from `memory`.
pub fn f64_store(
pub fn store64(
memory: &mut [u8],
address: Self,
offset: u32,
value: Self,
) -> Result<(), TrapCode> {
Self::store::<F64>(memory, address, offset, value)
Self::store::<u64>(memory, address, offset, value)
}

/// Executes the `i32.store8` Wasm operation.
Expand Down
13 changes: 4 additions & 9 deletions crates/core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,8 @@ impl_wrap_into!(i64, i32);
impl_wrap_into!(i64, f32, F32);
impl_wrap_into!(u64, f32, F32);

// Casting to self
impl_wrap_into!(i32, i32);
impl_wrap_into!(i64, i64);
impl_wrap_into!(F32, F32);
impl_wrap_into!(F64, F64);
impl_wrap_into!(u32, u32);
impl_wrap_into!(u64, u64);

impl WrapInto<F32> for F64 {
#[inline]
Expand Down Expand Up @@ -403,10 +400,8 @@ impl_extend_into!(u64, f64, F64);
impl_extend_into!(f32, f64, F64);

// Casting to self
impl_extend_into!(i32, i32);
impl_extend_into!(i64, i64);
impl_extend_into!(F32, F32);
impl_extend_into!(F64, F64);
impl_extend_into!(u32, u32);
impl_extend_into!(u64, u64);

impl ExtendInto<F64> for F32 {
#[inline]
Expand Down
Loading

0 comments on commit 1aa2256

Please sign in to comment.