Skip to content

Commit

Permalink
o1vm/riscv32im: add semantic for MInstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Dec 4, 2024
1 parent 54edc55 commit 964cfeb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)

match instr {
MInstruction::Mul => {
// x[rd] = x[rs1] * x[rs2]
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2253,6 +2254,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Mulh => {
// x[rd] = (signed(x[rs1]) * signed(x[rs2])) >> 32
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2266,6 +2268,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Mulhsu => {
// x[rd] = (signed(x[rs1]) * x[rs2]) >> 32
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2279,6 +2282,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Mulhu => {
// x[rd] = (x[rs1] * x[rs2]) >> 32
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2292,6 +2296,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Div => {
// x[rd] = signed(x[rs1]) / signed(x[rs2])
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2305,6 +2310,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Divu => {
// x[rd] = x[rs1] / x[rs2]
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2318,6 +2324,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Rem => {
// x[rd] = signed(x[rs1]) % signed(x[rs2])
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand All @@ -2331,6 +2338,7 @@ pub fn interpret_mtype<Env: InterpreterEnv>(env: &mut Env, instr: MInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
MInstruction::Remu => {
// x[rd] = x[rs1] % x[rs2]
let rs1 = env.read_register(&rs1);
let rs2 = env.read_register(&rs2);
// FIXME: constrain
Expand Down

0 comments on commit 964cfeb

Please sign in to comment.