diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 22:22:27 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 22:22:27 -0700 |
| commit | 2640f91e36558650bb988dcc82b5148ee71f3eb0 (patch) | |
| tree | 5f67c648569109c84736b11b39cb6d2cd6b67e4d /src/sim/cell/cell.rs | |
| parent | 92dd02d7cc4d9fc930760d26d81edbe2197a3fc0 (diff) | |
optimize with settlement counter
Diffstat (limited to 'src/sim/cell/cell.rs')
| -rw-r--r-- | src/sim/cell/cell.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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 { |
