Skip to content

Commit

Permalink
Merge pull request #2851 from o1-labs/sai/store-word-riscv32im
Browse files Browse the repository at this point in the history
implementation for riscv32im store word
  • Loading branch information
dannywillems authored Dec 19, 2024
2 parents a50442b + 5db2983 commit c8a6095
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,38 @@ pub fn interpret_stype<Env: InterpreterEnv>(env: &mut Env, instr: SInstruction)
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
SInstruction::StoreWord => {
unimplemented!("StoreWord")
// sw: M[x[rs1] + sext(offset)] = x[rs2][31:0]
let [v0, v1, v2, v3] = [
{
let value_scratch = env.alloc_scratch();
unsafe { env.bitmask(&local_rs2, 32, 24, value_scratch) }
},
{
let value_scratch = env.alloc_scratch();
unsafe { env.bitmask(&local_rs2, 24, 16, value_scratch) }
},
{
let value_scratch = env.alloc_scratch();
unsafe { env.bitmask(&local_rs2, 16, 8, value_scratch) }
},
{
let value_scratch = env.alloc_scratch();
unsafe { env.bitmask(&local_rs2, 8, 0, value_scratch) }
},
];

env.lookup_8bits(&v0);
env.lookup_8bits(&v1);
env.lookup_8bits(&v2);
env.lookup_8bits(&v3);

env.write_memory(&address, v0);
env.write_memory(&(address.clone() + Env::constant(1u32)), v1);
env.write_memory(&(address.clone() + Env::constant(2u32)), v2);
env.write_memory(&(address.clone() + Env::constant(3u32)), v3);

env.set_instruction_pointer(next_instruction_pointer.clone());
env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32));
}
};
}
Expand Down

0 comments on commit c8a6095

Please sign in to comment.