From 6da473c27219f4200ce06b2f8799fcc104616516 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Tue, 10 Mar 2026 03:43:47 +0000 Subject: [PATCH] PEAK optimisation. 420mips. it's not getting much faster tbh. --- decomp2.txt | 0 dsa/emulator/src/lib.rs | 1 + dsa/emulator/src/processor/processor.rs | 23 +++++++++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 decomp2.txt diff --git a/decomp2.txt b/decomp2.txt new file mode 100644 index 0000000..e69de29 diff --git a/dsa/emulator/src/lib.rs b/dsa/emulator/src/lib.rs index 9e368f0..9920c43 100644 --- a/dsa/emulator/src/lib.rs +++ b/dsa/emulator/src/lib.rs @@ -1,4 +1,5 @@ #![feature(likely_unlikely)] +#![feature(inherent_associated_types)] pub mod args; pub mod config; diff --git a/dsa/emulator/src/processor/processor.rs b/dsa/emulator/src/processor/processor.rs index 93f402c..d3c278c 100644 --- a/dsa/emulator/src/processor/processor.rs +++ b/dsa/emulator/src/processor/processor.rs @@ -158,7 +158,7 @@ impl Emulator { #[cold] fn boot(&mut self) -> Result<(), String> { if !(self.__io_configured && self.__mmap_configured) { - return Err("Processor not configured".to_string()); + return Err("Emulator not configured".to_string()); } if let Some(map) = &self.memory_map { @@ -207,16 +207,18 @@ impl Emulator { 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 Emulator { } self.mut_reg(Register::Pcx).add_assign(4); + self.execute(Instruction(instruction)); // Check if executing the interrupt caused a fault.