Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-op MIPS #2910

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/o1vm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ jobs:
eval $(opam env)
cd o1vm
unzip -q -o /tmp/o1vm-e2e-testing-cache.zip -d ./
RUN_WITH_CACHED_DATA="y" FILENAME="env-for-latest-l2-block.sh" O1VM_FLAVOR="pickles" STOP_AT="=3000000" ./run-code.sh
RUST_LOG=debug RUN_WITH_CACHED_DATA="y" FILENAME="env-for-latest-l2-block.sh" O1VM_FLAVOR="pickles" STOP_AT="=3000000" ./run-code.sh
9 changes: 8 additions & 1 deletion o1vm/src/interpreters/mips/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ pub const SCRATCH_SIZE_INVERSE: usize = 12;
pub const N_MIPS_REL_COLS: usize = SCRATCH_SIZE + SCRATCH_SIZE_INVERSE + 2;

/// The number of witness columns used to store the instruction selectors.
/// NOTE: The +1 is coming from the NoOp instruction.
pub const N_MIPS_SEL_COLS: usize =
RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT;
RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT + 1;

/// All the witness columns used in MIPS
pub const N_MIPS_COLS: usize = N_MIPS_REL_COLS + N_MIPS_SEL_COLS;
Expand Down Expand Up @@ -97,6 +98,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
27 changes: 27 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 @@ -970,9 +972,34 @@ 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_is_zero(opcode);
let next_instruction_pointer = env.get_next_instruction_pointer();
env.set_instruction_pointer(next_instruction_pointer.clone());
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}

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
3 changes: 2 additions & 1 deletion o1vm/src/interpreters/mips/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ fn test_regression_selectors_for_instructions() {
constraints.len() - 1,
// We could use N_MIPS_SEL_COLS, but sanity check in case this value is
// changed.
RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT
// the +1 is coming from NoOp instruction
RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT + 1
);
// All instructions are degree 1 or 2.
constraints
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 @@ -1076,7 +1076,13 @@ impl<Fp: PrimeField, 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
2 changes: 1 addition & 1 deletion o1vm/src/pickles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const DEGREE_QUOTIENT_POLYNOMIAL: u64 = 7;

/// Total number of constraints for all instructions, including the constraints
/// added for the selectors.
pub const TOTAL_NUMBER_OF_CONSTRAINTS: usize = 464;
pub const TOTAL_NUMBER_OF_CONSTRAINTS: usize = 466;

#[cfg(test)]
mod tests;
Loading