Skip to content

Commit

Permalink
feat: i32.rotl bitwise operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Jul 2, 2024
1 parent 7c819c2 commit 3af3601
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ impl<'b> RuntimeInstance<'b> {
trace!("Instruction: i32.shr_u [{v2} {v1}] -> [{res}]");
stack.push_value(res.into());
}
// i32.rotl: [i32 i32] -> [i32]
0x77 => {
let v1: i32 = stack.pop_value(ValType::NumType(NumType::I32)).into();
let v2: i32 = stack.pop_value(ValType::NumType(NumType::I32)).into();

let res = v2.rotate_left(v1 as u32);

trace!("Instruction: i32.rotl [{v2} {v1}] -> [{res}]");
stack.push_value(res.into());
}
other => {
trace!("Unknown instruction {other:#x}, skipping..");
}
Expand Down
7 changes: 7 additions & 0 deletions src/validation/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ fn read_instructions(

value_stack.push_back(ValType::NumType(NumType::I32));
}
// i32.rotl: [i32 i32] -> [i32]
0x77 => {
assert_pop_value_stack(value_stack, ValType::NumType(NumType::I32))?;
assert_pop_value_stack(value_stack, ValType::NumType(NumType::I32))?;

value_stack.push_back(ValType::NumType(NumType::I32));
}
other => {
return Err(Error::InvalidInstr(other));
}
Expand Down

0 comments on commit 3af3601

Please sign in to comment.