]> Repositorios git - scryer-prolog.git/commitdiff
adjust interrupt handling
authorSkgland <[email protected]>
Sat, 21 Mar 2026 13:20:11 +0000 (14:20 +0100)
committerSkgland <[email protected]>
Sat, 21 Mar 2026 13:20:11 +0000 (14:20 +0100)
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<u8> now only takes ~0.58 of the time

src/machine/dispatch.rs

index 33e9db1a2ba57ac459994b2d8586688fa22c1bff..20ec38cbfa5ee5a465f77ab49d028c8e263f26f4 100644 (file)
@@ -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<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;
@@ -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;