PEAK optimisation. 420mips. it's not getting much faster tbh.

This commit is contained in:
2026-03-10 03:43:47 +00:00
parent e01a9f2808
commit 6da473c272
3 changed files with 14 additions and 10 deletions
+1
View File
@@ -1,4 +1,5 @@
#![feature(likely_unlikely)]
#![feature(inherent_associated_types)]
pub mod args;
pub mod config;
+13 -10
View File
@@ -158,7 +158,7 @@ impl<Mem: RandomAccessMemory> Emulator<Mem> {
#[cold]
fn boot(&mut self) -> Result<(), String> {
if !(self.__io_configured && self.__mmap_configured) {
return Err("Processor not configured".to_string());
return Err("Emulator<Mem> not configured".to_string());
}
if let Some(map) = &self.memory_map {
@@ -207,16 +207,18 @@ impl<Mem: RandomAccessMemory> Emulator<Mem> {
let mut time = Instant::now();
'emu: loop {
// Update UI thread (roughly every 512k cycles targeting 60 UPS)
if unlikely(self.internal_state.clock & 0x7FFFF == 0) {
if self.shared_state.update_req.load(Ordering::Relaxed) {
self.update();
}
}
// IMPORTANT
// do not change anything about this loop. it's fully optimised afaik.
// Check for commands or hardware Interrupts every 32k cycles
if self.internal_state.clock % 0x7FFF == 0 {
if self.shared_state.running.load(Ordering::Relaxed) == false {
if unlikely(self.internal_state.clock & 0x7FFF == 0) {
// Update UI thread (roughly every 512k cycles targeting 60 UPS)
if unlikely(self.internal_state.clock & 0x7FFFF == 0) {
if self.shared_state.update_req.load(Ordering::Relaxed) {
self.update();
}
}
if unlikely(!self.shared_state.running.load(Ordering::Relaxed)) {
self.idle_wait();
}
@@ -260,6 +262,7 @@ impl<Mem: RandomAccessMemory> Emulator<Mem> {
}
self.mut_reg(Register::Pcx).add_assign(4);
self.execute(Instruction(instruction));
// Check if executing the interrupt caused a fault.