Skip to content

Commit

Permalink
Merge pull request #2848 from o1-labs/sai/store-byte-riscv32im
Browse files Browse the repository at this point in the history
implementation for store byte instruction riscv32im
  • Loading branch information
dannywillems authored Dec 19, 2024
2 parents 318a2d0 + d800479 commit 161540c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ pub fn interpret_stype<Env: InterpreterEnv>(env: &mut Env, instr: SInstruction)
/* fetch instruction pointer from the program state */
let instruction_pointer = env.get_instruction_pointer();
/* compute the next instruction ptr and add one, as well record raml lookup */
let _next_instruction_pointer = env.get_next_instruction_pointer();
let next_instruction_pointer = env.get_next_instruction_pointer();
/* read instruction from ip address */
let instruction = {
let v0 = env.read_memory(&instruction_pointer);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ pub fn interpret_stype<Env: InterpreterEnv>(env: &mut Env, instr: SInstruction)
let local_imm0_11 = unsafe { env.or_witness(&shifted_imm5_11, &local_imm0_4, pos) };
env.sign_extend(&local_imm0_11, 11)
};
let _address = {
let address = {
let address_scratch = env.alloc_scratch();
let overflow_scratch = env.alloc_scratch();
let (address, _overflow) = unsafe {
Expand All @@ -2047,11 +2047,21 @@ pub fn interpret_stype<Env: InterpreterEnv>(env: &mut Env, instr: SInstruction)
};
address
};
let _local_rs2 = env.read_register(&rs2);
let local_rs2 = env.read_register(&rs2);

match instr {
SInstruction::StoreByte => {
unimplemented!("StoreByte")
// sb: M[x[rs1] + sext(offset)] = x[rs2][7:0]
let v0 = {
let value_scratch = env.alloc_scratch();
unsafe { env.bitmask(&local_rs2, 8, 0, value_scratch) }
};

env.lookup_8bits(&v0);
env.write_memory(&address, v0);

env.set_instruction_pointer(next_instruction_pointer.clone());
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
SInstruction::StoreHalf => {
unimplemented!("StoreHalf")
Expand Down

0 comments on commit 161540c

Please sign in to comment.