From b42df8d46174f38c2d57ad32778045b4866c5712 Mon Sep 17 00:00:00 2001 From: svv232 Date: Mon, 25 Nov 2024 10:49:02 -0500 Subject: [PATCH] implementation for load upper immediate in riscv32im --- o1vm/src/interpreters/riscv32im/interpreter.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/o1vm/src/interpreters/riscv32im/interpreter.rs b/o1vm/src/interpreters/riscv32im/interpreter.rs index bc2e37abbd..2c3cb9eb4e 100644 --- a/o1vm/src/interpreters/riscv32im/interpreter.rs +++ b/o1vm/src/interpreters/riscv32im/interpreter.rs @@ -2152,7 +2152,7 @@ pub fn interpret_sbtype(env: &mut Env, instr: SBInstruction /// [here](https://www.cs.cornell.edu/courses/cs3410/2024fa/assignments/cpusim/riscv-instructions.pdf) pub fn interpret_utype(env: &mut Env, instr: UInstruction) { let instruction_pointer = env.get_instruction_pointer(); - let _next_instruction_pointer = env.get_next_instruction_pointer(); + let next_instruction_pointer = env.get_next_instruction_pointer(); let instruction = { let v0 = env.read_memory(&instruction_pointer); @@ -2193,7 +2193,16 @@ pub fn interpret_utype(env: &mut Env, instr: UInstruction) match instr { UInstruction::LoadUpperImmediate => { - unimplemented!("LoadUpperImmediate") + // lui: x[rd] = 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) + }; + env.write_register(&rd, local_imm); + + env.set_instruction_pointer(next_instruction_pointer.clone()); + env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32)); } UInstruction::AddUpperImmediate => { unimplemented!("AddUpperImmediate")