Skip to content

Commit e2afd72

Browse files
committed
NoSimd: faster mul_add
1 parent 2c322b0 commit e2afd72

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/engine/engine_nosimd.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::iter::zip;
2+
13
use crate::engine::{
24
tables::{self, Mul16, Skew},
35
Engine, GfElement, ShardsRefMut, GF_MODULUS,
@@ -97,16 +99,20 @@ impl NoSimd {
9799
fn mul_add(&self, x: &mut [u8], y: &[u8], log_m: GfElement) {
98100
let lut = &self.mul16[log_m as usize];
99101

100-
let mut pos = 0;
101-
while pos < x.len() {
102+
for (x_chunk, y_chunk) in zip(x.chunks_exact_mut(64), y.chunks_exact(64)) {
103+
let (x_lo, x_hi) = x_chunk.split_at_mut(32);
104+
let (y_lo, y_hi) = y_chunk.split_at(32);
105+
102106
for i in 0..32 {
103-
let lo = y[pos + i] as usize;
104-
let hi = y[pos + i + 32] as usize;
105-
let prod = lut[0][lo & 15] ^ lut[1][lo >> 4] ^ lut[2][hi & 15] ^ lut[3][hi >> 4];
106-
x[pos + i] ^= prod as u8;
107-
x[pos + i + 32] ^= (prod >> 8) as u8;
107+
let lo = y_lo[i];
108+
let hi = y_hi[i];
109+
let prod = lut[0][usize::from(lo & 15)]
110+
^ lut[1][usize::from(lo >> 4)]
111+
^ lut[2][usize::from(hi & 15)]
112+
^ lut[3][usize::from(hi >> 4)];
113+
x_lo[i] ^= prod as u8;
114+
x_hi[i] ^= (prod >> 8) as u8;
108115
}
109-
pos += 64;
110116
}
111117
}
112118
}

0 commit comments

Comments
 (0)