Skip to content

Commit

Permalink
feat: i32.rotr bitwise operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Jul 2, 2024
1 parent 35b39da commit b980739
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 @@ -282,6 +282,16 @@ impl<'b> RuntimeInstance<'b> {
trace!("Instruction: i32.rotl [{v2} {v1}] -> [{res}]");
stack.push_value(res.into());
}
// i32.rotr: [i32 i32] -> [i32]
0x78 => {
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_right(v1 as u32);

trace!("Instruction: i32.rotr [{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 @@ -230,6 +230,13 @@ fn read_instructions(

value_stack.push_back(ValType::NumType(NumType::I32));
}
// i32.rotr: [i32 i32] -> [i32]
0x78 => {
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 b980739

Please sign in to comment.