Skip to content

Commit

Permalink
implementation for load upper immediate in riscv32im
Browse files Browse the repository at this point in the history
  • Loading branch information
svv232 committed Nov 25, 2024
1 parent 5db2983 commit b42df8d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ pub fn interpret_sbtype<Env: InterpreterEnv>(env: &mut Env, instr: SBInstruction
/// [here](https://www.cs.cornell.edu/courses/cs3410/2024fa/assignments/cpusim/riscv-instructions.pdf)
pub fn interpret_utype<Env: InterpreterEnv>(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);
Expand Down Expand Up @@ -2193,7 +2193,16 @@ pub fn interpret_utype<Env: InterpreterEnv>(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")
Expand Down

0 comments on commit b42df8d

Please sign in to comment.