From: Skgland Date: Sat, 21 Mar 2026 13:20:11 +0000 (+0100) Subject: adjust interrupt handling X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=153f04b72ac68cce45374f724455683802eca74e;p=scryer-prolog.git adjust interrupt handling we used to spend ~5.8% of the time on getting the next value of the 0..INSTRUCTIONS_PER_INTERRUPT_POLL iterator increment on Wrapping now only takes ~0.58 of the time --- diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 33e9db1a..20ec38cb 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -77,8 +77,6 @@ macro_rules! push_cell { }}; } -static INSTRUCTIONS_PER_INTERRUPT_POLL: usize = 256; - impl MachineState { #[inline(always)] fn compare(&mut self) -> CallResult { @@ -1541,8 +1539,13 @@ impl Machine { } fn verify_attr_dispatch_loop(&mut self) -> Option { + let mut interrupt_counter = std::num::Wrapping(0u8); 'outer: loop { - for _ in 0..INSTRUCTIONS_PER_INTERRUPT_POLL { + loop { + interrupt_counter += 1; + if interrupt_counter.0 == 0 { + break; + } match self.code[self.machine_st.p] { Instruction::BreakFromDispatchLoop => { break 'outer; @@ -1611,8 +1614,14 @@ impl Machine { } pub(super) fn dispatch_loop(&mut self) -> std::process::ExitCode { + let mut interrupt_counter = std::num::Wrapping(0u8); 'outer: loop { - for _ in 0..INSTRUCTIONS_PER_INTERRUPT_POLL { + loop { + interrupt_counter += 1; + if interrupt_counter.0 == 0 { + break; + } + match &self.code[self.machine_st.p] { &Instruction::BreakFromDispatchLoop => { break 'outer;