Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
progpow: unroll loops in keccak_f800_round
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Oct 17, 2018
1 parent a7ec80a commit b9fb187
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions ethash/src/progpow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,50 @@ const KECCAKF_PILN: [usize; 24] = [
fn keccak_f800_round(st: &mut [u32; 25], r: usize) {
// Theta
let mut bc = [0u32; 5];
for i in 0..bc.len() {
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];

debug_assert_eq!(bc.len(), 5);
unroll! {
for i in 0..5 {
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];
}
}

for i in 0..bc.len() {
let t = bc[(i + 4) % 5] ^ bc[(i + 1) % 5].rotate_left(1);
for j in (0..st.len()).step_by(5) {
st[j + i] ^= t;
unroll! {
for i in 0..5 {
let t = bc[(i + 4) % 5] ^ bc[(i + 1) % 5].rotate_left(1);
for j in (0..st.len()).step_by(5) {
st[j + i] ^= t;
}
}
}

// Rho Pi
let mut t = st[1];
for i in 0..KECCAKF_ROTC.len() {
let j = KECCAKF_PILN[i];
bc[0] = st[j];
st[j] = t.rotate_left(KECCAKF_ROTC[i]);
t = bc[0];

debug_assert_eq!(KECCAKF_ROTC.len(), 24);
unroll! {
for i in 0..24 {
let j = KECCAKF_PILN[i];
bc[0] = st[j];
st[j] = t.rotate_left(KECCAKF_ROTC[i]);
t = bc[0];
}
}

// Chi
for j in (0..st.len()).step_by(5) {
for i in 0..bc.len() {
bc[i] = st[j + i];
debug_assert_eq!(st.len(), 25);
debug_assert_eq!(bc.len(), 5);
for j in (0..25).step_by(5) {
unroll! {
for i in 0..5 {
bc[i] = st[j + i];
}
}
for i in 0..bc.len() {
st[j + i] ^= (!bc[(i + 1) % 5]) & bc[(i + 2) % 5];

unroll! {
for i in 0..5 {
st[j + i] ^= (!bc[(i + 1) % 5]) & bc[(i + 2) % 5];
}
}
}

Expand Down

0 comments on commit b9fb187

Please sign in to comment.