From 2640f91e36558650bb988dcc82b5148ee71f3eb0 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 18 Aug 2026 22:22:27 -0700 Subject: optimize with settlement counter --- src/sim/cell/cell.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/sim/cell/cell.rs') diff --git a/src/sim/cell/cell.rs b/src/sim/cell/cell.rs index d567893..edb2402 100644 --- a/src/sim/cell/cell.rs +++ b/src/sim/cell/cell.rs @@ -10,6 +10,7 @@ pub struct Cell { impl Cell { const FLAG_PARITY: u8 = 0b0000_0001; const FLAG_RB: u8 = 0b0000_0010; + const MASK_SETTLED: u8 = 0b0001_1100; #[inline] pub fn parity(self) -> u8 { @@ -33,6 +34,7 @@ impl Cell { pub fn rb(self) -> bool { (self.flags & Self::FLAG_RB) == Self::FLAG_RB } + #[inline] pub fn set_rb(&mut self, rb: bool) { if rb { self.flags |= Self::FLAG_RB @@ -40,6 +42,28 @@ impl Cell { self.flags = self.flags & !Self::FLAG_RB } } + + #[inline] + pub fn settled(self) -> u8 { + (self.flags & Self::MASK_SETTLED) >> 2 + } + #[inline] + fn set_settled(&mut self, settled: u8) { + debug_assert!(settled <= 7); + self.flags = (settled << 2) | (self.flags & !Self::MASK_SETTLED); + } + #[inline] + pub fn reset_settled(&mut self) { + self.flags &= !Self::MASK_SETTLED; + } + + #[inline] + pub fn increment_settled(&mut self) { + let s = self.settled(); + if s < 7 { + self.set_settled(s + 1); + } + } } impl Cell { -- cgit v1.3.1