From ffc0299cfd9bf32e02b61d15e52904d7ce268565 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 13 Jun 2025 17:35:46 +0200 Subject: use SIMD for left-shift This saves the integer conversion. Here, for the 1024 byte benchmark, I get an improvement of ~4% in runtime --- src/block.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/block.rs') 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 for Block { impl Shl 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) } } -- cgit v1.2.3