From bcc9e1c87936868886dbb24f71ab616adb20aff1 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Mon, 23 Dec 2024 21:12:41 +0100 Subject: [PATCH] WIP: no-op MIPS --- o1vm/src/interpreters/mips/column.rs | 6 ++++++ o1vm/src/interpreters/mips/interpreter.rs | 24 +++++++++++++++++++++++ o1vm/src/interpreters/mips/witness.rs | 8 +++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/o1vm/src/interpreters/mips/column.rs b/o1vm/src/interpreters/mips/column.rs index cd895198b7..87f7fe574b 100644 --- a/o1vm/src/interpreters/mips/column.rs +++ b/o1vm/src/interpreters/mips/column.rs @@ -94,6 +94,12 @@ impl From 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 + } } } } diff --git a/o1vm/src/interpreters/mips/interpreter.rs b/o1vm/src/interpreters/mips/interpreter.rs index 0ea55c67ea..83a436ff02 100644 --- a/o1vm/src/interpreters/mips/interpreter.rs +++ b/o1vm/src/interpreters/mips/interpreter.rs @@ -31,6 +31,7 @@ pub enum Instruction { RType(RTypeInstruction), JType(JTypeInstruction), IType(ITypeInstruction), + NoOp, } #[derive( @@ -153,6 +154,7 @@ impl IntoIterator for Instruction { } iter_contents.into_iter() } + Instruction::NoOp => vec![Instruction::NoOp].into_iter(), } } } @@ -964,9 +966,31 @@ pub fn interpret_instruction(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: &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: &mut Env, instr: RTypeInstruction) { let instruction_pointer = env.get_instruction_pointer(); let next_instruction_pointer = env.get_next_instruction_pointer(); diff --git a/o1vm/src/interpreters/mips/witness.rs b/o1vm/src/interpreters/mips/witness.rs index 991b946c8d..7018b74798 100644 --- a/o1vm/src/interpreters/mips/witness.rs +++ b/o1vm/src/interpreters/mips/witness.rs @@ -989,7 +989,13 @@ impl Env { 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),