From 21ed2b33fda4dad4b9391dfb7b0ad4807b4df6d6 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 19 Oct 2023 12:01:59 +0300 Subject: [PATCH] refactor: more readable `mem_total_pages` implementation --- frontend-wasm/src/code_translator/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend-wasm/src/code_translator/mod.rs b/frontend-wasm/src/code_translator/mod.rs index ff8629635..53135051a 100644 --- a/frontend-wasm/src/code_translator/mod.rs +++ b/frontend-wasm/src/code_translator/mod.rs @@ -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(