1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef __INCLUDE_HASH_FUNC_H__
6 #define __INCLUDE_HASH_FUNC_H__
9 hash_xor_key8(void *key, void *mask, __rte_unused uint32_t key_size,
16 xor0 = seed ^ (k[0] & m[0]);
18 return (xor0 >> 32) ^ xor0;
21 static inline uint64_t
22 hash_xor_key16(void *key, void *mask, __rte_unused uint32_t key_size,
29 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
31 return (xor0 >> 32) ^ xor0;
34 static inline uint64_t
35 hash_xor_key24(void *key, void *mask, __rte_unused uint32_t key_size,
42 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
46 return (xor0 >> 32) ^ xor0;
49 static inline uint64_t
50 hash_xor_key32(void *key, void *mask, __rte_unused uint32_t key_size,
57 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
58 xor1 = (k[2] & m[2]) ^ (k[3] & m[3]);
62 return (xor0 >> 32) ^ xor0;
65 static inline uint64_t
66 hash_xor_key40(void *key, void *mask, __rte_unused uint32_t key_size,
73 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
74 xor1 = (k[2] & m[2]) ^ (k[3] & m[3]);
80 return (xor0 >> 32) ^ xor0;
83 static inline uint64_t
84 hash_xor_key48(void *key, void *mask, __rte_unused uint32_t key_size,
89 uint64_t xor0, xor1, xor2;
91 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
92 xor1 = (k[2] & m[2]) ^ (k[3] & m[3]);
93 xor2 = (k[4] & m[4]) ^ (k[5] & m[5]);
99 return (xor0 >> 32) ^ xor0;
102 static inline uint64_t
103 hash_xor_key56(void *key, void *mask, __rte_unused uint32_t key_size,
108 uint64_t xor0, xor1, xor2;
110 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
111 xor1 = (k[2] & m[2]) ^ (k[3] & m[3]);
112 xor2 = (k[4] & m[4]) ^ (k[5] & m[5]);
119 return (xor0 >> 32) ^ xor0;
122 static inline uint64_t
123 hash_xor_key64(void *key, void *mask, __rte_unused uint32_t key_size,
128 uint64_t xor0, xor1, xor2, xor3;
130 xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]);
131 xor1 = (k[2] & m[2]) ^ (k[3] & m[3]);
132 xor2 = (k[4] & m[4]) ^ (k[5] & m[5]);
133 xor3 = (k[6] & m[6]) ^ (k[7] & m[7]);
140 return (xor0 >> 32) ^ xor0;
143 #if defined(RTE_ARCH_X86_64)
145 #include <x86intrin.h>
147 static inline uint64_t
148 hash_crc_key8(void *key, void *mask, __rte_unused uint32_t key_size,
155 crc0 = _mm_crc32_u64(seed, k[0] & m[0]);
160 static inline uint64_t
161 hash_crc_key16(void *key, void *mask, __rte_unused uint32_t key_size,
166 uint64_t k0, crc0, crc1;
170 crc0 = _mm_crc32_u64(k0, seed);
171 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
178 static inline uint64_t
179 hash_crc_key24(void *key, void *mask, __rte_unused uint32_t key_size,
184 uint64_t k0, k2, crc0, crc1;
189 crc0 = _mm_crc32_u64(k0, seed);
190 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
192 crc0 = _mm_crc32_u64(crc0, k2);
199 static inline uint64_t
200 hash_crc_key32(void *key, void *mask, __rte_unused uint32_t key_size,
205 uint64_t k0, k2, crc0, crc1, crc2, crc3;
210 crc0 = _mm_crc32_u64(k0, seed);
211 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
213 crc2 = _mm_crc32_u64(k2, k[3] & m[3]);
216 crc0 = _mm_crc32_u64(crc0, crc1);
217 crc1 = _mm_crc32_u64(crc2, crc3);
224 static inline uint64_t
225 hash_crc_key40(void *key, void *mask, __rte_unused uint32_t key_size,
230 uint64_t k0, k2, crc0, crc1, crc2, crc3;
235 crc0 = _mm_crc32_u64(k0, seed);
236 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
238 crc2 = _mm_crc32_u64(k2, k[3] & m[3]);
239 crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]);
241 crc0 = _mm_crc32_u64(crc0, crc1);
242 crc1 = _mm_crc32_u64(crc2, crc3);
249 static inline uint64_t
250 hash_crc_key48(void *key, void *mask, __rte_unused uint32_t key_size,
255 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3;
261 crc0 = _mm_crc32_u64(k0, seed);
262 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
264 crc2 = _mm_crc32_u64(k2, k[3] & m[3]);
265 crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]);
267 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
268 crc1 = _mm_crc32_u64(crc3, k5);
275 static inline uint64_t
276 hash_crc_key56(void *key, void *mask, __rte_unused uint32_t key_size,
281 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
287 crc0 = _mm_crc32_u64(k0, seed);
288 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
290 crc2 = _mm_crc32_u64(k2, k[3] & m[3]);
291 crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]);
293 crc4 = _mm_crc32_u64(k5, k[6] & m[6]);
296 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
297 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
304 static inline uint64_t
305 hash_crc_key64(void *key, void *mask, __rte_unused uint32_t key_size,
310 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
316 crc0 = _mm_crc32_u64(k0, seed);
317 crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]);
319 crc2 = _mm_crc32_u64(k2, k[3] & m[3]);
320 crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]);
322 crc4 = _mm_crc32_u64(k5, k[6] & m[6]);
323 crc5 = _mm_crc32_u64(k5 >> 32, k[7] & m[7]);
325 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
326 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
333 #define hash_default_key8 hash_crc_key8
334 #define hash_default_key16 hash_crc_key16
335 #define hash_default_key24 hash_crc_key24
336 #define hash_default_key32 hash_crc_key32
337 #define hash_default_key40 hash_crc_key40
338 #define hash_default_key48 hash_crc_key48
339 #define hash_default_key56 hash_crc_key56
340 #define hash_default_key64 hash_crc_key64
342 #elif defined(RTE_ARCH_ARM64)
343 #include "hash_func_arm64.h"
346 #define hash_default_key8 hash_xor_key8
347 #define hash_default_key16 hash_xor_key16
348 #define hash_default_key24 hash_xor_key24
349 #define hash_default_key32 hash_xor_key32
350 #define hash_default_key40 hash_xor_key40
351 #define hash_default_key48 hash_xor_key48
352 #define hash_default_key56 hash_xor_key56
353 #define hash_default_key64 hash_xor_key64