Commit 81ae18a
authored
Use the groestl-style T-table lookup for fast kupyna hashing (#778)
A lot of the galois-field ops were running on each and every column
load. I didn't do anything clever or original, aside from understanding
how the groestl implementation worked, and shamelessly copying as much
from that as possible. Once that cleaned out a big pile of intermediate
functions, I picked some low-hanging fruit with the new `const fn
compute_src_cols`.
Moving all the field xor ops into a groestl-esque T-table sees a
significant 8x speedup. One weird issue I hit was on the long-hashes,
LLVM stops automatically unrolling the loops once they're longer than 8
iterations, which was seeing a major dropoff in throughput. I could've
manually unrolled the whole thing, but chunking it into two separate
8-longs (for a 16-byte long chunk) gives me equivalent compiled code as
both will unroll it, even though it's a bit silly to read.
Benchmarks before this PR:
```
running 8 tests
test kupyna256_10 ... bench: 276.20 ns/iter (+/- 5.70) = 36 MB/s
test kupyna256_100 ... bench: 2,761.53 ns/iter (+/- 44.17) = 36 MB/s
test kupyna256_1000 ... bench: 27,618.72 ns/iter (+/- 235.44) = 36 MB/s
test kupyna256_10000 ... bench: 274,159.70 ns/iter (+/- 3,121.12) = 36 MB/s
test kupyna512_10 ... bench: 391.96 ns/iter (+/- 21.09) = 25 MB/s
test kupyna512_100 ... bench: 3,915.42 ns/iter (+/- 142.03) = 25 MB/s
test kupyna512_1000 ... bench: 39,039.71 ns/iter (+/- 182.78) = 25 MB/s
test kupyna512_10000 ... bench: 389,250.45 ns/iter (+/- 1,132.40) = 25 MB/s
```
After swapping the galois-field xor, subbytes loading, and shifting with
a quick lookup in the T-table:
```
running 8 tests
test kupyna256_10 ... bench: 38.17 ns/iter (+/- 3.66) = 263 MB/s
test kupyna256_100 ... bench: 370.85 ns/iter (+/- 5.36) = 270 MB/s
test kupyna256_1000 ... bench: 3,568.39 ns/iter (+/- 901.09) = 280 MB/s
test kupyna256_10000 ... bench: 36,356.67 ns/iter (+/- 1,409.35) = 275 MB/s
test kupyna512_10 ... bench: 48.18 ns/iter (+/- 0.31) = 208 MB/s
test kupyna512_100 ... bench: 462.74 ns/iter (+/- 21.66) = 216 MB/s
test kupyna512_1000 ... bench: 4,738.49 ns/iter (+/- 250.94) = 211 MB/s
test kupyna512_10000 ... bench: 47,398.92 ns/iter (+/- 1,137.88) = 210 MB/s
```
Then the `const fn computer_src_cols` instead of computing at runtime:
```
running 8 tests
test kupyna256_10 ... bench: 33.61 ns/iter (+/- 0.35) = 303 MB/s
test kupyna256_100 ... bench: 338.50 ns/iter (+/- 24.91) = 295 MB/s
test kupyna256_1000 ... bench: 3,369.35 ns/iter (+/- 85.24) = 296 MB/s
test kupyna256_10000 ... bench: 32,791.09 ns/iter (+/- 315.57) = 304 MB/s
test kupyna512_10 ... bench: 45.69 ns/iter (+/- 2.19) = 222 MB/s
test kupyna512_100 ... bench: 442.11 ns/iter (+/- 26.73) = 226 MB/s
test kupyna512_1000 ... bench: 4,370.52 ns/iter (+/- 55.67) = 228 MB/s
test kupyna512_10000 ... bench: 43,252.35 ns/iter (+/- 252.63) = 231 MB/s
```
Overall a ~8.5x speedup for the 256 hashes, and >9x for the 512!1 parent a478ace commit 81ae18a
5 files changed
Lines changed: 196 additions & 155 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
5 | 3 | | |
6 | 4 | | |
7 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
8 | 28 | | |
9 | 29 | | |
10 | | - | |
11 | 30 | | |
12 | 31 | | |
13 | 32 | | |
14 | 33 | | |
15 | 34 | | |
16 | 35 | | |
17 | 36 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
25 | 44 | | |
26 | | - | |
| 45 | + | |
27 | 46 | | |
28 | 47 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
42 | 69 | | |
43 | 70 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
51 | 86 | | |
52 | 87 | | |
53 | 88 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
5 | 3 | | |
6 | 4 | | |
7 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
8 | 26 | | |
9 | 27 | | |
10 | | - | |
11 | 28 | | |
12 | 29 | | |
13 | 30 | | |
14 | 31 | | |
15 | 32 | | |
16 | 33 | | |
17 | 34 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
25 | 42 | | |
26 | | - | |
| 43 | + | |
27 | 44 | | |
28 | 45 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
42 | 64 | | |
43 | 65 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
51 | 78 | | |
52 | 79 | | |
53 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
0 commit comments