aboutsummaryrefslogtreecommitdiff
path: root/src/block.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-07-12 17:02:56 +0200
committerDaniel Schadt <kingdread@gmx.de>2025-07-12 17:02:56 +0200
commitb43c8ea324fcf484191b7fcf097b1b0dd6234c1d (patch)
treebdbeffc2e0760dfbdc537f0dda629086a0513c88 /src/block.rs
parent749a79d9325a1242c9e7246352ee1930a7d5eb70 (diff)
downloadzears-b43c8ea324fcf484191b7fcf097b1b0dd6234c1d.tar.gz
zears-b43c8ea324fcf484191b7fcf097b1b0dd6234c1d.tar.bz2
zears-b43c8ea324fcf484191b7fcf097b1b0dd6234c1d.zip
manually implement addition-by-one
The int conversion is quite costly, so this is a lot faster (especially in the non-simd build).
Diffstat (limited to 'src/block.rs')
-rw-r--r--src/block.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/block.rs b/src/block.rs
index 96c3496..8327286 100644
--- a/src/block.rs
+++ b/src/block.rs
@@ -12,6 +12,18 @@ pub struct Block(u8x16);
#[cfg(not(feature = "simd"))]
pub struct Block([u8; 16]);
+macro_rules! add_ladder {
+ ($ar:expr, $lit:literal) => {
+ $ar[$lit] = $ar[$lit].wrapping_add(1);
+ };
+ ($ar:expr, $lit:literal $($rest:literal) +) => {
+ $ar[$lit] = $ar[$lit].wrapping_add(1);
+ if $ar[$lit] == 0 {
+ add_ladder!($ar, $($rest) +);
+ }
+ };
+}
+
impl Block {
pub fn null() -> Block {
Block([0; 16].into())
@@ -95,6 +107,10 @@ impl Block {
_ => (*self * 2).exp(exponent - 1),
}
}
+
+ pub fn count_up(&mut self) {
+ add_ladder!(self, 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0);
+ }
}
impl From<[u8; 16]> for Block {