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

Remove no-op reinterpret wasmi instructions #518

Merged
merged 18 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/wasmi/src/engine/bytecode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ pub enum Instruction {
F64ConvertI64S,
F64ConvertI64U,
F64PromoteF32,
I32ReinterpretF32,
I64ReinterpretF64,
F32ReinterpretI32,
F64ReinterpretI64,
I32Extend8S,
I32Extend16S,
I64Extend8S,
Expand Down
9 changes: 5 additions & 4 deletions crates/wasmi/src/engine/bytecode/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::*;
use core::mem::size_of;

#[test]
fn size_of_instruction() {
assert_eq!(core::mem::size_of::<Instruction>(), 16);
assert_eq!(core::mem::size_of::<DropKeep>(), 4);
assert_eq!(core::mem::size_of::<BranchParams>(), 8);
assert_eq!(core::mem::size_of::<BranchOffset>(), 4);
assert_eq!(size_of::<Instruction>(), 16);
assert_eq!(size_of::<DropKeep>(), 4);
assert_eq!(size_of::<BranchParams>(), 8);
assert_eq!(size_of::<BranchOffset>(), 4);
}
29 changes: 0 additions & 29 deletions crates/wasmi/src/engine/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,6 @@ impl<'ctx, 'engine, 'func, HostData> Executor<'ctx, 'engine, 'func, HostData> {
Instr::F64ConvertI64S => self.visit_f64_convert_i64(),
Instr::F64ConvertI64U => self.visit_f64_convert_u64(),
Instr::F64PromoteF32 => self.visit_f64_promote_f32(),
Instr::I32ReinterpretF32 => self.visit_i32_reinterpret_f32(),
Instr::I64ReinterpretF64 => self.visit_i64_reinterpret_f64(),
Instr::F32ReinterpretI32 => self.visit_f32_reinterpret_i32(),
Instr::F64ReinterpretI64 => self.visit_f64_reinterpret_i64(),
Instr::I32TruncSatF32S => self.visit_i32_trunc_sat_f32(),
Instr::I32TruncSatF32U => self.visit_u32_trunc_sat_f32(),
Instr::I32TruncSatF64S => self.visit_i32_trunc_sat_f64(),
Expand Down Expand Up @@ -446,15 +442,6 @@ impl<'ctx, 'engine, 'func, HostData> Executor<'ctx, 'engine, 'func, HostData> {
Ok(())
}

fn execute_reinterpret<T, U>(&mut self)
where
UntypedValue: From<U>,
T: From<UntypedValue>,
{
// Nothing to do for `wasmi` bytecode.
self.next_instr()
}

fn next_instr(&mut self) {
self.ip_add(1)
}
Expand Down Expand Up @@ -1234,22 +1221,6 @@ impl<'ctx, 'engine, 'func, HostData> Executor<'ctx, 'engine, 'func, HostData> {
self.execute_unary(UntypedValue::f64_promote_f32)
}

fn visit_i32_reinterpret_f32(&mut self) {
self.execute_reinterpret::<F32, i32>()
}

fn visit_i64_reinterpret_f64(&mut self) {
self.execute_reinterpret::<F64, i64>()
}

fn visit_f32_reinterpret_i32(&mut self) {
self.execute_reinterpret::<i32, F32>()
}

fn visit_f64_reinterpret_i64(&mut self) {
self.execute_reinterpret::<i64, F64>()
}

fn visit_i32_sign_extend8(&mut self) {
self.execute_unary(UntypedValue::i32_extend8_s)
}
Expand Down
41 changes: 21 additions & 20 deletions crates/wasmi/src/engine/func_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,40 +1903,41 @@ impl<'parser> FuncBuilder<'parser> {
self.translate_conversion(ValueType::F32, ValueType::F64, Instruction::F64PromoteF32)
}

/// Translate a Wasm reinterpret instruction.
///
/// Since `wasmi` bytecode is untyped those reinterpret
/// instructions from Wasm are simply dropped from codegen.
///
/// - `i32.reinterpret_f32`
/// - `i64.reinterpret_f64`
/// - `f32.reinterpret_i32`
/// - `f64.reinterpret_i64`
pub fn translate_reinterpret(
&mut self,
_input_type: ValueType,
_output_type: ValueType,
) -> Result<(), TranslationError> {
Ok(())
}

/// Translate a Wasm `i32.reinterpret_f32` instruction.
pub fn translate_i32_reinterpret_f32(&mut self) -> Result<(), TranslationError> {
self.translate_conversion(
ValueType::F32,
ValueType::I32,
Instruction::I32ReinterpretF32,
)
self.translate_reinterpret(ValueType::F32, ValueType::I32)
}

/// Translate a Wasm `i64.reinterpret_f64` instruction.
pub fn translate_i64_reinterpret_f64(&mut self) -> Result<(), TranslationError> {
self.translate_conversion(
ValueType::F64,
ValueType::I64,
Instruction::I64ReinterpretF64,
)
self.translate_reinterpret(ValueType::F64, ValueType::I64)
}

/// Translate a Wasm `f32.reinterpret_i32` instruction.
pub fn translate_f32_reinterpret_i32(&mut self) -> Result<(), TranslationError> {
self.translate_conversion(
ValueType::I32,
ValueType::F32,
Instruction::F32ReinterpretI32,
)
self.translate_reinterpret(ValueType::I32, ValueType::F32)
}

/// Translate a Wasm `f64.reinterpret_i64` instruction.
pub fn translate_f64_reinterpret_i64(&mut self) -> Result<(), TranslationError> {
self.translate_conversion(
ValueType::I64,
ValueType::F64,
Instruction::F64ReinterpretI64,
)
self.translate_reinterpret(ValueType::I64, ValueType::F64)
}

/// Translate a Wasm `i32.extend_8s` instruction.
Expand Down