Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reroll outer loop #30

Merged
merged 2 commits into from
May 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 41 additions & 51 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,73 +66,63 @@ const RC: [u64; 24] = [
#[allow(unused_assignments)]
/// keccak-f[1600]
pub fn keccakf(a: &mut [u64; PLEN]) {
let mut arrays: [[u64; 5]; 24] = [[0; 5]; 24];

unroll! {
for i in 0..24 {
// Theta
unroll! {
for x in 0..5 {
// This looks useless but it gets way slower without it. I tried using
// `mem::uninitialized` for the initialisation of `arrays` but that also makes
// it slower, although not by as much as removing this assignment. Optimisers
// are weird. Maybe a different version of LLVM will react differently, so if
// you see this comment in the future try deleting this assignment and using
// uninit above and see how it affects the benchmarks.
arrays[i][x] = 0;

unroll! {
for y_count in 0..5 {
let y = y_count * 5;
arrays[i][x] ^= a[x + y];
}
for i in 0..24 {
let mut array: [u64; 5] = [0; 5];

// Theta
unroll! {
for x in 0..5 {
unroll! {
for y_count in 0..5 {
let y = y_count * 5;
array[x] ^= a[x + y];
}
}
}
}

unroll! {
for x in 0..5 {
unroll! {
for y_count in 0..5 {
let y = y_count * 5;
a[y + x] ^= arrays[i][(x + 4) % 5] ^ arrays[i][(x + 1) % 5].rotate_left(1);
}
unroll! {
for x in 0..5 {
unroll! {
for y_count in 0..5 {
let y = y_count * 5;
a[y + x] ^= array[(x + 4) % 5] ^ array[(x + 1) % 5].rotate_left(1);
}
}
}
}

// Rho and pi
let mut last = a[1];
unroll! {
for x in 0..24 {
arrays[i][0] = a[PI[x]];
a[PI[x]] = last.rotate_left(RHO[x]);
last = arrays[i][0];
}
// Rho and pi
let mut last = a[1];
unroll! {
for x in 0..24 {
array[0] = a[PI[x]];
a[PI[x]] = last.rotate_left(RHO[x]);
last = array[0];
}
}

// Chi
unroll! {
for y_step in 0..5 {
let y = y_step * 5;
// Chi
unroll! {
for y_step in 0..5 {
let y = y_step * 5;

unroll! {
for x in 0..5 {
arrays[i][x] = a[y + x];
}
unroll! {
for x in 0..5 {
array[x] = a[y + x];
}
}

unroll! {
for x in 0..5 {
a[y + x] = arrays[i][x] ^ ((!arrays[i][(x + 1) % 5]) & (arrays[i][(x + 2) % 5]));
}
unroll! {
for x in 0..5 {
a[y + x] = array[x] ^ ((!array[(x + 1) % 5]) & (array[(x + 2) % 5]));
}
}
};
}
};

// Iota
a[0] ^= RC[i];
}
// Iota
a[0] ^= RC[i];
}
}

Expand Down