From 5db298323af3a9e8b415e6212642818d752f8e79 Mon Sep 17 00:00:00 2001 From: svv232 Date: Mon, 25 Nov 2024 10:36:07 -0500 Subject: [PATCH] implementation for riscv32im store word --- .../src/interpreters/riscv32im/interpreter.rs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/o1vm/src/interpreters/riscv32im/interpreter.rs b/o1vm/src/interpreters/riscv32im/interpreter.rs index bc9aef00f2..bc2e37abbd 100644 --- a/o1vm/src/interpreters/riscv32im/interpreter.rs +++ b/o1vm/src/interpreters/riscv32im/interpreter.rs @@ -2021,7 +2021,38 @@ pub fn interpret_stype(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)); } }; }