Skip to content

Commit

Permalink
refactor: more readable mem_total_pages implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Oct 19, 2023
1 parent c275566 commit 21ed2b3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frontend-wasm/src/code_translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,11 @@ fn translate_br_table(

/// Return the total Miden VM memory size (2^32 addresses * word (4 felts) bytes) in 64KB pages
const fn mem_total_pages() -> i32 {
let bytes_fit_in_felt = 4; // although more than 32 bits can fit into a felt, use 32 bits to be safe
let felts_in_word = 4;
let total_addresses = u32::MAX as i64;
(total_addresses * (felts_in_word * bytes_fit_in_felt) / (64 * 1024)) as i32
const FELT_BYTES: u64 = 4; // felts are effectively 32 bits
const WORD_BYTES: u64 = 4 * FELT_BYTES; // 4 felts per word
const PAGE_SIZE: u64 = 64 * 1024;
const MEMORY_SIZE: u64 = u32::MAX as u64 * WORD_BYTES;
(MEMORY_SIZE / PAGE_SIZE) as i32
}

fn translate_load(
Expand Down

0 comments on commit 21ed2b3

Please sign in to comment.