Skip to content

Commit

Permalink
Merge pull request #1411 from o1-labs/feature/mips/neq
Browse files Browse the repository at this point in the history
Implement `neq`
  • Loading branch information
dannywillems authored Dec 6, 2023
2 parents 758b5be + 283fa5e commit eee0c5c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,25 @@ pub fn interpret_itype<Env: InterpreterEnv>(env: &mut Env, instr: ITypeInstructi
// REMOVEME: when all itype instructions are implemented.
return;
}
ITypeInstruction::BranchNeq => (),
ITypeInstruction::BranchNeq => {
let offset = env.sign_extend(&(immediate * Env::constant(1 << 2)), 18);
let rs = env.read_register(&rs);
let rt = env.read_register(&rt);
let equals = {
// FIXME: Requires constraints
let pos = env.alloc_scratch();
unsafe { env.test_zero(&(rs - rt), pos) }
};
let offset = equals.clone() * Env::constant(4) + (Env::constant(1) - equals) * offset;
let addr = {
let pos = env.alloc_scratch();
env.copy(&(next_instruction_pointer.clone() + offset), pos)
};
env.set_instruction_pointer(next_instruction_pointer);
env.set_next_instruction_pointer(addr);
// REMOVEME: when all itype instructions are implemented.
return;
}
ITypeInstruction::BranchLeqZero => (),
ITypeInstruction::BranchGtZero => (),
ITypeInstruction::AddImmediate => {
Expand Down

0 comments on commit eee0c5c

Please sign in to comment.