Skip to content

Commit

Permalink
Merge pull request #1393 from o1-labs/feature/rtype-instruction-parsing
Browse files Browse the repository at this point in the history
Add parsing for r-type instructions
  • Loading branch information
dannywillems authored Dec 5, 2023
2 parents 6800e29 + eca5ba7 commit 2bf1969
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,47 @@ pub fn interpret_instruction<Env: InterpreterEnv>(env: &mut Env, instr: Instruct
}

pub fn interpret_rtype<Env: InterpreterEnv>(env: &mut Env, instr: RTypeInstruction) {
let instruction_pointer = env.get_instruction_pointer();
let instruction = {
let v0 = env.read_memory(&instruction_pointer);
let v1 = env.read_memory(&(instruction_pointer.clone() + Env::constant(1)));
let v2 = env.read_memory(&(instruction_pointer.clone() + Env::constant(2)));
let v3 = env.read_memory(&(instruction_pointer + Env::constant(3)));
(v0 * Env::constant(1 << 24))
+ (v1 * Env::constant(1 << 16))
+ (v2 * Env::constant(1 << 8))
+ v3
};
let _opcode = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 32, 26, pos) }
};
let _rs = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 26, 21, pos) }
};
let _rt = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 21, 16, pos) }
};
let _rd = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 16, 11, pos) }
};
let _shamt = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 11, 6, pos) }
};
let _funct = {
// FIXME: Requires a range check
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 6, 0, pos) }
};
match instr {
RTypeInstruction::ShiftLeftLogical => (),
RTypeInstruction::ShiftRightLogical => (),
Expand Down

0 comments on commit 2bf1969

Please sign in to comment.