openvm_circuit/system/memory/manager/
dimensions.rsuse derive_new::new;
use openvm_stark_backend::p3_util::log2_strict_usize;
use crate::{arch::MemoryConfig, system::memory::CHUNK};
#[derive(Clone, Copy, Debug, new)]
pub struct MemoryDimensions {
pub as_height: usize,
pub address_height: usize,
pub as_offset: u32,
}
impl MemoryDimensions {
pub fn overall_height(&self) -> usize {
self.as_height + self.address_height
}
pub fn label_to_index(&self, label: (u32, u32)) -> u64 {
let (addr_space, block_id) = label;
(((addr_space - self.as_offset) as u64) << self.address_height) + block_id as u64
}
}
impl MemoryConfig {
pub fn memory_dimensions(&self) -> MemoryDimensions {
MemoryDimensions {
as_height: self.as_height,
address_height: self.pointer_max_bits - log2_strict_usize(CHUNK),
as_offset: self.as_offset,
}
}
}