1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NH - ε-almost-universal hash function, x86_64 SSE2 accelerated
5 * Copyright 2018 Google LLC
7 * Author: Eric Biggers <ebiggers@google.com>
10 #include <linux/linkage.h>
12 #define PASS0_SUMS %xmm0
13 #define PASS1_SUMS %xmm1
14 #define PASS2_SUMS %xmm2
15 #define PASS3_SUMS %xmm3
30 #define MESSAGE_LEN %rdx
33 .macro _nh_stride k0, k1, k2, k3, offset
35 // Load next message stride
36 movdqu \offset(MESSAGE), T1
38 // Load next key stride
39 movdqu \offset(KEY), \k3
41 // Add message words to key words
44 paddd T1, \k0 // reuse k0 to avoid a move
49 // Multiply 32x32 => 64 and accumulate
51 pshufd $0x32, \k0, \k0
69 * void nh_sse2(const u32 *key, const u8 *message, size_t message_len,
70 * u8 hash[NH_HASH_BYTES])
72 * It's guaranteed that message_len % 16 == 0.
74 SYM_FUNC_START(nh_sse2)
80 pxor PASS0_SUMS, PASS0_SUMS
81 pxor PASS1_SUMS, PASS1_SUMS
82 pxor PASS2_SUMS, PASS2_SUMS
83 pxor PASS3_SUMS, PASS3_SUMS
85 sub $0x40, MESSAGE_LEN
88 _nh_stride K0, K1, K2, K3, 0x00
89 _nh_stride K1, K2, K3, K0, 0x10
90 _nh_stride K2, K3, K0, K1, 0x20
91 _nh_stride K3, K0, K1, K2, 0x30
94 sub $0x40, MESSAGE_LEN
98 and $0x3f, MESSAGE_LEN
100 _nh_stride K0, K1, K2, K3, 0x00
102 sub $0x10, MESSAGE_LEN
104 _nh_stride K1, K2, K3, K0, 0x10
106 sub $0x10, MESSAGE_LEN
108 _nh_stride K2, K3, K0, K1, 0x20
111 // Sum the accumulators for each pass, then store the sums to 'hash'
112 movdqa PASS0_SUMS, T0
113 movdqa PASS2_SUMS, T1
114 punpcklqdq PASS1_SUMS, T0 // => (PASS0_SUM_A PASS1_SUM_A)
115 punpcklqdq PASS3_SUMS, T1 // => (PASS2_SUM_A PASS3_SUM_A)
116 punpckhqdq PASS1_SUMS, PASS0_SUMS // => (PASS0_SUM_B PASS1_SUM_B)
117 punpckhqdq PASS3_SUMS, PASS2_SUMS // => (PASS2_SUM_B PASS3_SUM_B)
120 movdqu T0, 0x00(HASH)
121 movdqu T1, 0x10(HASH)
123 SYM_FUNC_END(nh_sse2)