Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

o1vm/riscv32im: helper to read a uint32 from memory #2916

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions o1vm/src/interpreters/riscv32im/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,4 +945,15 @@ impl<Fp: Field> Env<Fp> {
pub fn normalized_instruction_counter(&self) -> u64 {
self.instruction_counter / MAX_ACC
}

/// Get a u32 from memory, starting from address `addr`.
pub fn get_uint32(&mut self, addr: u32) -> u32 {
let page = addr >> PAGE_ADDRESS_SIZE;
let page_address = (addr & PAGE_ADDRESS_MASK) as usize;
let memory_page_idx = self.get_memory_page_index(page);
let value = self.memory[memory_page_idx].1[page_address..page_address + 4]
.try_into()
.expect("get_uint32 values fit in a u32");
u32::from_be_bytes(value)
}
}
Loading