Skip to content

Commit

Permalink
WIP: no-op MIPS
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Dec 23, 2024
1 parent 0a6e0ac commit bcc9e1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions o1vm/src/interpreters/mips/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl From<Instruction> for usize {
IType(itype) => {
N_MIPS_REL_COLS + RTypeInstruction::COUNT + JTypeInstruction::COUNT + itype as usize
}
Instruction::NoOp => {
N_MIPS_REL_COLS
+ RTypeInstruction::COUNT
+ JTypeInstruction::COUNT
+ ITypeInstruction::COUNT
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions o1vm/src/interpreters/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum Instruction {
RType(RTypeInstruction),
JType(JTypeInstruction),
IType(ITypeInstruction),
NoOp,
}

#[derive(
Expand Down Expand Up @@ -153,6 +154,7 @@ impl IntoIterator for Instruction {
}
iter_contents.into_iter()
}
Instruction::NoOp => vec![Instruction::NoOp].into_iter(),
}
}
}
Expand Down Expand Up @@ -964,9 +966,31 @@ pub fn interpret_instruction<Env: InterpreterEnv>(env: &mut Env, instr: Instruct
Instruction::RType(instr) => interpret_rtype(env, instr),
Instruction::JType(instr) => interpret_jtype(env, instr),
Instruction::IType(instr) => interpret_itype(env, instr),
Instruction::NoOp => interpret_noop(env),
}
}

pub fn interpret_noop<Env: InterpreterEnv>(env: &mut env) {
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.clone() + Env::constant(3)));
(v0 * Env::constant(1 << 24))
+ (v1 * Env::constant(1 << 16))
+ (v2 * Env::constant(1 << 8))
+ v3
};
let opcode = {
let pos = env.alloc_scratch();
unsafe { env.bitmask(&instruction, 32, 26, pos) }
};

env.range_check8(&opcode, 6);
env.assert_zero(&opcode);
}

pub fn interpret_rtype<Env: InterpreterEnv>(env: &mut Env, instr: RTypeInstruction) {
let instruction_pointer = env.get_instruction_pointer();
let next_instruction_pointer = env.get_next_instruction_pointer();
Expand Down
8 changes: 7 additions & 1 deletion o1vm/src/interpreters/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,13 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle> {
let opcode = {
match instruction >> 26 {
0x00 => match instruction & 0x3F {
0x00 => Instruction::RType(RTypeInstruction::ShiftLeftLogical),
0x00 => {
if instruction == 0 {
Instruction::NoOp
} else {
Instruction::RType(RTypeInstruction::ShiftLeftLogical)
}
}
0x02 => Instruction::RType(RTypeInstruction::ShiftRightLogical),
0x03 => Instruction::RType(RTypeInstruction::ShiftRightArithmetic),
0x04 => Instruction::RType(RTypeInstruction::ShiftLeftLogicalVariable),
Expand Down

0 comments on commit bcc9e1c

Please sign in to comment.