Skip to content

Commit

Permalink
Using alloc to improve performance (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson authored Feb 21, 2024
1 parent 98787e0 commit 0ec3188
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions definitions/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
instructions::Instruction, MEMORY_FRAMES, MEMORY_FRAMESIZE, MEMORY_FRAME_SHIFTS,
RISCV_GENERAL_REGISTER_NUMBER, RISCV_MAX_MEMORY, RISCV_PAGES, RISCV_PAGESIZE,
};
use std::alloc::{alloc_zeroed, Layout};
use std::alloc::{alloc, Layout};

// The number of trace items to keep
pub const TRACE_SIZE: usize = 8192;
Expand Down Expand Up @@ -88,19 +88,30 @@ impl AsmCoreMachine {
std::mem::size_of::<AsmCoreMachine>() - RISCV_MAX_MEMORY + memory_size;

let layout = Layout::array::<u8>(machine_size).unwrap();
let raw_allocation = alloc_zeroed(layout) as *mut AsmCoreMachine;
let raw_allocation = alloc(layout) as *mut AsmCoreMachine;
Box::from_raw(raw_allocation)
};
machine.registers = [0; RISCV_GENERAL_REGISTER_NUMBER];
machine.pc = 0;
machine.next_pc = 0;
machine.running = 0;
machine.cycles = 0;
machine.max_cycles = max_cycles;
if cfg!(feature = "enable-chaos-mode-by-default") {
machine.chaos_mode = 1;
} else {
machine.chaos_mode = 0;
}
machine.chaos_seed = 0;
machine.load_reservation_address = u64::MAX;
machine.reset_signal = 0;
machine.version = version;
machine.isa = isa;
machine.flags = [0; RISCV_PAGES];
for i in 0..TRACE_SIZE {
machine.traces[i] = Trace::default();
}
machine.frames = [0; MEMORY_FRAMES];

machine.memory_size = memory_size as u64;
machine.frames_size = (memory_size / MEMORY_FRAMESIZE) as u64;
Expand Down

0 comments on commit 0ec3188

Please sign in to comment.