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

feat(decoder): move cache to heap #357

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ pub struct Decoder {
factories: Vec<InstructionFactory>,
mop: bool,
version: u32,
// use a cache of instructions to avoid decoding the same instruction twice, pc is the key and the instruction is the value
instructions_cache: [(u64, u64); INSTRUCTION_CACHE_SIZE],
// Use a cache of instructions to avoid decoding the same instruction
// twice, pc is the key and the instruction is the value.
//
// Use Vector so that the data is on the heap. Otherwise, if there is
// a vm call chain, it will quickly consume Rust's 2M stack space.
instructions_cache: Vec<(u64, u64)>,
}

impl Decoder {
Expand All @@ -31,7 +35,7 @@ impl Decoder {
factories: vec![],
mop,
version,
instructions_cache: [(RISCV_MAX_MEMORY as u64, 0); INSTRUCTION_CACHE_SIZE],
instructions_cache: vec![(RISCV_MAX_MEMORY as u64, 0); INSTRUCTION_CACHE_SIZE],
}
}

Expand Down Expand Up @@ -864,7 +868,7 @@ impl InstDecoder for Decoder {
}

fn reset_instructions_cache(&mut self) -> Result<(), Error> {
self.instructions_cache = [(RISCV_MAX_MEMORY as u64, 0); INSTRUCTION_CACHE_SIZE];
self.instructions_cache = vec![(RISCV_MAX_MEMORY as u64, 0); INSTRUCTION_CACHE_SIZE];
Ok(())
}
}
Expand Down