diff --git a/crates/wasmi/src/engine/regmach/executor/instrs.rs b/crates/wasmi/src/engine/regmach/executor/instrs.rs index b851abee36..26a409fa1b 100644 --- a/crates/wasmi/src/engine/regmach/executor/instrs.rs +++ b/crates/wasmi/src/engine/regmach/executor/instrs.rs @@ -15,7 +15,7 @@ use crate::{ Instruction, Register, RegisterSpan, - UnaryInstr, + UnaryInstr, BranchOffset16, }, code_map::{CodeMap, InstructionPtr}, stack::{CallFrame, CallStack, ValueStack, ValueStackPtr}, @@ -926,6 +926,16 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { self.ip.offset(offset.to_i32() as isize) } + /// Branches and adjusts the value stack. + /// + /// # Note + /// + /// Offsets the instruction pointer using the given [`BranchOffset`]. + #[inline(always)] + fn branch_to16(&mut self, offset: BranchOffset16) { + self.ip.offset(offset.to_i16() as isize) + } + /// Returns the [`ValueStackPtr`] of the [`CallFrame`]. fn frame_stack_ptr(&mut self, frame: &CallFrame) -> ValueStackPtr { Self::frame_stack_ptr_impl(self.value_stack, frame) diff --git a/crates/wasmi/src/engine/regmach/executor/instrs/branch.rs b/crates/wasmi/src/engine/regmach/executor/instrs/branch.rs index 55644ffe2f..ad67d266bb 100644 --- a/crates/wasmi/src/engine/regmach/executor/instrs/branch.rs +++ b/crates/wasmi/src/engine/regmach/executor/instrs/branch.rs @@ -47,7 +47,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { let lhs: T = self.get_register_as(instr.lhs); let rhs = T::from(instr.rhs); if f(lhs, rhs) { - return self.branch_to(instr.offset.into()); + return self.branch_to16(instr.offset); } self.next_instr() }