Skip to content

Commit 2bc2de2

Browse files
committedDec 5, 2023
Implement beq
1 parent cb8cf82 commit 2bc2de2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed
 

‎optimism/src/mips/interpreter.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,25 @@ pub fn interpret_itype<Env: InterpreterEnv>(env: &mut Env, instr: ITypeInstructi
756756
unsafe { env.bitmask(&instruction, 16, 0, pos) }
757757
};
758758
match instr {
759-
ITypeInstruction::BranchEq => (),
759+
ITypeInstruction::BranchEq => {
760+
let offset = env.sign_extend(&(immediate * Env::constant(1 << 2)), 18);
761+
let rs = env.read_register(&rs);
762+
let rt = env.read_register(&rt);
763+
let equals = {
764+
// FIXME: Requires constraints
765+
let pos = env.alloc_scratch();
766+
unsafe { env.equals_zero(&(rs - rt), pos) }
767+
};
768+
let offset = (Env::constant(1) - equals.clone()) * Env::constant(4) + equals * offset;
769+
let addr = {
770+
let pos = env.alloc_scratch();
771+
env.copy(&(next_instruction_pointer.clone() + offset), pos)
772+
};
773+
env.set_instruction_pointer(next_instruction_pointer);
774+
env.set_next_instruction_pointer(addr);
775+
// REMOVEME: when all itype instructions are implemented.
776+
return;
777+
}
760778
ITypeInstruction::BranchNeq => (),
761779
ITypeInstruction::BranchLeqZero => (),
762780
ITypeInstruction::BranchGtZero => (),

0 commit comments

Comments
 (0)
Please sign in to comment.