Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower load and store instructions by pruning types where possible #1303

Merged
merged 13 commits into from
Nov 10, 2024
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
Loading