Skip to content

Commit

Permalink
Merge pull request #1475 from o1-labs/feature/mips/movz
Browse files Browse the repository at this point in the history
Implement `movz`
  • Loading branch information
dannywillems authored Dec 7, 2023
2 parents d8e2cbc + a15a50a commit 0b4632d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ pub trait InterpreterEnv {
self.access_register_if(idx, old_value, new_value, &Self::constant(1))
}

fn write_register(&mut self, idx: &Self::Variable, new_value: Self::Variable) {
fn write_register_if(
&mut self,
idx: &Self::Variable,
new_value: Self::Variable,
if_is_true: &Self::Variable,
) {
let old_value = {
let value_location = self.alloc_scratch();
unsafe { self.fetch_register(idx, value_location) }
Expand All @@ -346,13 +351,17 @@ pub trait InterpreterEnv {
self.copy(&((Self::constant(1) - idx_is_zero) * new_value), pos)
};
unsafe {
self.access_register(idx, &old_value, &actual_new_value);
self.access_register_if(idx, &old_value, &actual_new_value, if_is_true);
};
unsafe {
self.push_register(idx, actual_new_value);
self.push_register_if(idx, actual_new_value, if_is_true);
};
}

fn write_register(&mut self, idx: &Self::Variable, new_value: Self::Variable) {
self.write_register_if(idx, new_value, &Self::constant(1))
}

/// Fetch the memory value at address `addr` and store it in local position `output`.
///
/// # Safety
Expand Down Expand Up @@ -969,7 +978,15 @@ pub fn interpret_rtype<Env: InterpreterEnv>(env: &mut Env, instr: RTypeInstructi
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
return;
}
RTypeInstruction::MoveZero => (),
RTypeInstruction::MoveZero => {
let rt = env.read_register(&rt);
let is_zero = env.is_zero(&rt);
let rs = env.read_register(&rs);
env.write_register_if(&rd, rs, &is_zero);
env.set_instruction_pointer(next_instruction_pointer.clone());
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
return;
}
RTypeInstruction::MoveNonZero => (),
RTypeInstruction::Sync => {
env.set_instruction_pointer(next_instruction_pointer.clone());
Expand Down

0 comments on commit 0b4632d

Please sign in to comment.