aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-06-13 17:35:46 +0200
committerDaniel Schadt <kingdread@gmx.de>2025-06-13 17:39:21 +0200
commitffc0299cfd9bf32e02b61d15e52904d7ce268565 (patch)
treee39a113e3cca63df6673d9ac029805bbb3860a4a
parent9ff8dcab2c0de9dfceeadb2894afe1b079613faa (diff)
downloadzears-ffc0299cfd9bf32e02b61d15e52904d7ce268565.tar.gz
zears-ffc0299cfd9bf32e02b61d15e52904d7ce268565.tar.bz2
zears-ffc0299cfd9bf32e02b61d15e52904d7ce268565.zip
use SIMD for left-shift
This saves the integer conversion. Here, for the 1024 byte benchmark, I get an improvement of ~4% in runtime
-rw-r--r--src/block.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/block.rs b/src/block.rs
index bde60fc..0e64bbe 100644
--- a/src/block.rs
+++ b/src/block.rs
@@ -148,6 +148,14 @@ impl BitXor<Block> for Block {
impl Shl<u32> for Block {
type Output = Block;
fn shl(self, rhs: u32) -> Block {
+ // We often use a shift by one, for example in the multiplication. We therefore optimize
+ // for this special case.
+ #[cfg(feature = "simd")]
+ {
+ if rhs == 1 {
+ return Block((self.0 << 1) | (self.0.shift_elements_left::<1>(0) >> 7));
+ }
+ }
Block::from(self.to_int() << rhs)
}
}