aboutsummaryrefslogtreecommitdiff
path: root/src/block.rs
diff options
context:
space:
mode:
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 {