authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-03 14:29:37+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-04 14:03:54+02:00
log0adecad9e65ca85b2853db4f264fc7762a2d5983
tree9f1dfb2ee7f8c209da83c865fbdd34ff10e0f845
parente67cb2c7c9b9802bccb44be2ead04aebf771030d

Unroll for loops

Provides a 15% speedup on WebAssembly, both with wamstime and V8.

1 files changed, 6 insertions(+), 6 deletions(-)

lib/std/crypto/aegis/bitsliced.zig+6-6
......@@ -205,7 +205,7 @@ pub fn State128X(comptime degree: u7) type {
205205 }) };
206206 const input = packRate(nonce_block, key_block);
207207 for (0..10) |_| {
208 for (&state.words, context_mask) |*w, m| w.* ^= m;
208 inline for (&state.words, context_mask) |*w, m| w.* ^= m;
209209 state.update(&input);
210210 }
211211 return state;
......@@ -214,7 +214,7 @@ pub fn State128X(comptime degree: u7) type {
214214 fn update(state: *State, input: *const Aes.Bitsliced) void {
215215 var st1 = state.words;
216216 Aes.round(&st1);
217 for (&state.words, st1, input) |*w, r, in| {
217 inline for (&state.words, st1, input) |*w, r, in| {
218218 w.* ^= (((r & V.mask(0xfe)) >> 1) | ((r & V.mask(0x01)) << 7)) ^ in;
219219 }
220220 }
......@@ -225,7 +225,7 @@ pub fn State128X(comptime degree: u7) type {
225225
226226 fn keystream(state: *const State) [2][4]Word {
227227 var z: Aes.Bitsliced = undefined;
228 for (&z, &state.words) |*zw, x| {
228 inline for (&z, &state.words) |*zw, x| {
229229 zw.* = ((x & V.mask(0x02)) << 6) ^ ((x & V.mask(0x40)) << 1) ^
230230 (((x & V.mask(0x20)) << 2) & ((x & V.mask(0x10)) << 3)) ^
231231 ((x & V.mask(0x20)) >> 2) ^ ((x & V.mask(0x04)) << 1) ^
......@@ -354,7 +354,7 @@ pub fn State256X(comptime degree: u7) type {
354354 };
355355 for (0..4) |_| {
356356 for (&inputs) |*input| {
357 for (&state.words, context_mask) |*w, m| w.* ^= m;
357 inline for (&state.words, context_mask) |*w, m| w.* ^= m;
358358 state.update(input);
359359 }
360360 }
......@@ -364,7 +364,7 @@ pub fn State256X(comptime degree: u7) type {
364364 fn update(state: *State, input: *const Aes.Bitsliced) void {
365365 var st1 = state.words;
366366 Aes.round(&st1);
367 for (&state.words, st1, input) |*w, r, in| {
367 inline for (&state.words, st1, input) |*w, r, in| {
368368 w.* ^= (((r & V.mask(0xf8)) >> 1) | ((r & V.mask(0x04)) << 5)) ^ in;
369369 }
370370 }
......@@ -375,7 +375,7 @@ pub fn State256X(comptime degree: u7) type {
375375
376376 fn keystream(state: *const State) [4]Word {
377377 var z: Aes.Bitsliced = undefined;
378 for (&z, &state.words) |*zw, x| {
378 inline for (&z, &state.words) |*zw, x| {
379379 zw.* = ((x & V.mask(0x40)) << 1) ^ ((x & V.mask(0x08)) << 4) ^
380380 ((x & V.mask(0x04)) << 5) ^
381381 (((x & V.mask(0x20)) << 2) & ((x & V.mask(0x10)) << 3));