Skip to content

Commit

Permalink
minor optimization in executor
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Nov 25, 2023
1 parent 834c3fb commit 720ffff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion crates/wasmi/src/engine/regmach/executor/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
Instruction,
Register,
RegisterSpan,
UnaryInstr,
UnaryInstr, BranchOffset16,
},
code_map::{CodeMap, InstructionPtr},
stack::{CallFrame, CallStack, ValueStack, ValueStackPtr},
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/regmach/executor/instrs/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 720ffff

Please sign in to comment.