1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NH - ε-almost-universal hash function, ARM64 NEON accelerated version
5 * Copyright 2018 Google LLC
7 * Author: Eric Biggers <ebiggers@google.com>
10 #include <linux/linkage.h>
34 .macro _nh_stride k0, k1, k2, k3
36 // Load next message stride
37 ld1 {T3.16b}, [MESSAGE], #16
39 // Load next key stride
40 ld1 {\k3\().4s}, [KEY], #16
42 // Add message words to key words
43 add T0.4s, T3.4s, \k0\().4s
44 add T1.4s, T3.4s, \k1\().4s
45 add T2.4s, T3.4s, \k2\().4s
46 add T3.4s, T3.4s, \k3\().4s
48 // Multiply 32x32 => 64 and accumulate
53 umlal PASS0_SUMS.2d, T0.2s, T4.2s
54 umlal PASS1_SUMS.2d, T1.2s, T5.2s
55 umlal PASS2_SUMS.2d, T2.2s, T6.2s
56 umlal PASS3_SUMS.2d, T3.2s, T7.2s
60 * void nh_neon(const u32 *key, const u8 *message, size_t message_len,
61 * u8 hash[NH_HASH_BYTES])
63 * It's guaranteed that message_len % 16 == 0.
67 ld1 {K0.4s,K1.4s}, [KEY], #32
68 movi PASS0_SUMS.2d, #0
69 movi PASS1_SUMS.2d, #0
70 ld1 {K2.4s}, [KEY], #16
71 movi PASS2_SUMS.2d, #0
72 movi PASS3_SUMS.2d, #0
74 subs MESSAGE_LEN, MESSAGE_LEN, #64
77 _nh_stride K0, K1, K2, K3
78 _nh_stride K1, K2, K3, K0
79 _nh_stride K2, K3, K0, K1
80 _nh_stride K3, K0, K1, K2
81 subs MESSAGE_LEN, MESSAGE_LEN, #64
85 ands MESSAGE_LEN, MESSAGE_LEN, #63
87 _nh_stride K0, K1, K2, K3
89 subs MESSAGE_LEN, MESSAGE_LEN, #16
91 _nh_stride K1, K2, K3, K0
93 subs MESSAGE_LEN, MESSAGE_LEN, #16
95 _nh_stride K2, K3, K0, K1
98 // Sum the accumulators for each pass, then store the sums to 'hash'
99 addp T0.2d, PASS0_SUMS.2d, PASS1_SUMS.2d
100 addp T1.2d, PASS2_SUMS.2d, PASS3_SUMS.2d
101 st1 {T0.16b,T1.16b}, [HASH]