From c1b350ee623f331e3a9d161569190c7cb2152a8d Mon Sep 17 00:00:00 2001 From: svv232 Date: Mon, 25 Nov 2024 10:51:56 -0500 Subject: [PATCH 1/2] implementation for add upper immediate in riscv32im --- o1vm/src/interpreters/riscv32im/interpreter.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/o1vm/src/interpreters/riscv32im/interpreter.rs b/o1vm/src/interpreters/riscv32im/interpreter.rs index 2c3cb9eb4e..3ae830de49 100644 --- a/o1vm/src/interpreters/riscv32im/interpreter.rs +++ b/o1vm/src/interpreters/riscv32im/interpreter.rs @@ -2205,7 +2205,21 @@ pub fn interpret_utype(env: &mut Env, instr: UInstruction) env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32)); } UInstruction::AddUpperImmediate => { - unimplemented!("AddUpperImmediate") + // auipc: x[rd] = pc + sext(immediate[31:12] << 12) + let local_imm = { + let pos = env.alloc_scratch(); + let shifted_imm = unsafe { env.shift_left(&imm, &Env::constant(12), pos) }; + env.sign_extend(&shifted_imm, 32) + }; + let local_pc = instruction_pointer.clone(); + let pos = env.alloc_scratch(); + let overflow_pos = env.alloc_scratch(); + let (local_rd, _) = + unsafe { env.add_witness(&local_pc, &local_imm, pos, overflow_pos) }; + env.write_register(&rd, local_rd); + + env.set_instruction_pointer(next_instruction_pointer.clone()); + env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32)); } }; } From 75bc47d418797bd307199744bc53385ad32ec335 Mon Sep 17 00:00:00 2001 From: svv232 Date: Tue, 17 Dec 2024 00:56:11 -0500 Subject: [PATCH 2/2] move position scratch variables into local scope for interpreter variable --- o1vm/src/interpreters/riscv32im/interpreter.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/o1vm/src/interpreters/riscv32im/interpreter.rs b/o1vm/src/interpreters/riscv32im/interpreter.rs index 3ae830de49..5f36fffbcb 100644 --- a/o1vm/src/interpreters/riscv32im/interpreter.rs +++ b/o1vm/src/interpreters/riscv32im/interpreter.rs @@ -2212,10 +2212,11 @@ pub fn interpret_utype(env: &mut Env, instr: UInstruction) env.sign_extend(&shifted_imm, 32) }; let local_pc = instruction_pointer.clone(); - let pos = env.alloc_scratch(); - let overflow_pos = env.alloc_scratch(); - let (local_rd, _) = - unsafe { env.add_witness(&local_pc, &local_imm, pos, overflow_pos) }; + let (local_rd, _) = { + let pos = env.alloc_scratch(); + let overflow_pos = env.alloc_scratch(); + unsafe { env.add_witness(&local_pc, &local_imm, pos, overflow_pos) } + }; env.write_register(&rd, local_rd); env.set_instruction_pointer(next_instruction_pointer.clone());