Skip to content

Commit d7fec19

Browse files
committed
Only require the elements actually needed
1 parent 4c5e3fd commit d7fec19

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

std/machines/hash/keccakf32_memory.asm

+14-15
Original file line numberDiff line numberDiff line change
@@ -592,22 +592,19 @@ machine Keccakf32Memory(mem: Memory) with
592592
// }
593593
// }
594594

595-
let query_c: int, int, int, fe[] -> int = query |x, limb, bit_in_limb, a|
596-
utils::fold(
597-
5,
598-
|y| (int(a[y * 10 + x * 2 + limb]) >> bit_in_limb) & 0x1,
599-
0,
600-
|acc, e| acc ^ e
601-
);
602-
603595
query |row| {
604596
let _ = array::map_enumerated(c, |i, c_i| {
605597
let x = i / 64;
606598
let z = i % 64;
607599
let limb = z / 32;
608600
let bit_in_limb = z % 32;
609601

610-
compute_from(c_i, row, a, |a| fe(query_c(x, limb, bit_in_limb, a)))
602+
let a_elems = array::new(5, |y| a[y * 10 + x * 2 + limb]);
603+
604+
compute_from(
605+
c_i, row, a_elems,
606+
|a_elems_fe| fe(utils::fold(
607+
5, |y| (int(a_elems_fe[y]) >> bit_in_limb) & 0x1, 0, |acc, e| acc ^ e)))
611608
});
612609
};
613610

@@ -622,17 +619,18 @@ machine Keccakf32Memory(mem: Memory) with
622619
// }
623620
// }
624621

625-
let query_c_prime: int, int, fe[] -> int = query |x, z, c|
626-
int(c[x * 64 + z]) ^
627-
int(c[((x + 4) % 5) * 64 + z]) ^
628-
int(c[((x + 1) % 5) * 64 + (z + 63) % 64]);
629-
630622
query |row| {
631623
let _ = array::map_enumerated(c_prime, |i, c_i| {
632624
let x = i / 64;
633625
let z = i % 64;
634626

635-
compute_from(c_i, row, c, |c| fe(query_c_prime(x, z, c)));
627+
let c_elems = [
628+
c[x * 64 + z],
629+
c[((x + 4) % 5) * 64 + z],
630+
c[((x + 1) % 5) * 64 + (z + 63) % 64]
631+
];
632+
633+
compute_from(c_i, row, c_elems, |c_elems_fe| fe(int(c_elems_fe[0]) ^ int(c_elems_fe[1]) ^ int(c_elems_fe[2])));
636634
});
637635
};
638636

@@ -717,6 +715,7 @@ machine Keccakf32Memory(mem: Memory) with
717715
let x = (i / 2) % 5;
718716
let limb = i % 2;
719717

718+
// Seems to be faster to require all 5 * 5 * 64 elements of a_prime
720719
compute_from(a_i, row, a_prime, |a_prime| fe(query_a_prime_prime(x, y, limb, a_prime)));
721720
});
722721
};

0 commit comments

Comments
 (0)