2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 #ifndef __INCLUDE_HASH_FUNC_H__
17 #define __INCLUDE_HASH_FUNC_H__
19 static inline uint64_t
20 hash_xor_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed)
27 return (xor0 >> 32) ^ xor0;
30 static inline uint64_t
31 hash_xor_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed)
36 xor0 = (k[0] ^ seed) ^ k[1];
38 return (xor0 >> 32) ^ xor0;
41 static inline uint64_t
42 hash_xor_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed)
47 xor0 = (k[0] ^ seed) ^ k[1];
51 return (xor0 >> 32) ^ xor0;
54 static inline uint64_t
55 hash_xor_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed)
60 xor0 = (k[0] ^ seed) ^ k[1];
65 return (xor0 >> 32) ^ xor0;
68 static inline uint64_t
69 hash_xor_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed)
74 xor0 = (k[0] ^ seed) ^ k[1];
81 return (xor0 >> 32) ^ xor0;
84 static inline uint64_t
85 hash_xor_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed)
88 uint64_t xor0, xor1, xor2;
90 xor0 = (k[0] ^ seed) ^ k[1];
98 return (xor0 >> 32) ^ xor0;
101 static inline uint64_t
102 hash_xor_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed)
105 uint64_t xor0, xor1, xor2;
107 xor0 = (k[0] ^ seed) ^ k[1];
116 return (xor0 >> 32) ^ xor0;
119 static inline uint64_t
120 hash_xor_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed)
123 uint64_t xor0, xor1, xor2, xor3;
125 xor0 = (k[0] ^ seed) ^ k[1];
135 return (xor0 >> 32) ^ xor0;
138 #if defined(RTE_ARCH_X86_64) && defined(RTE_MACHINE_CPUFLAG_SSE4_2)
140 #include <x86intrin.h>
142 static inline uint64_t
143 hash_crc_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed)
148 crc0 = _mm_crc32_u64(seed, k[0]);
153 static inline uint64_t
154 hash_crc_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed)
157 uint64_t k0, crc0, crc1;
161 crc0 = _mm_crc32_u64(k0, seed);
162 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
169 static inline uint64_t
170 hash_crc_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed)
173 uint64_t k0, k2, crc0, crc1;
178 crc0 = _mm_crc32_u64(k0, seed);
179 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
181 crc0 = _mm_crc32_u64(crc0, k2);
188 static inline uint64_t
189 hash_crc_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed)
192 uint64_t k0, k2, crc0, crc1, crc2, crc3;
197 crc0 = _mm_crc32_u64(k0, seed);
198 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
200 crc2 = _mm_crc32_u64(k2, k[3]);
203 crc0 = _mm_crc32_u64(crc0, crc1);
204 crc1 = _mm_crc32_u64(crc2, crc3);
211 static inline uint64_t
212 hash_crc_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed)
215 uint64_t k0, k2, crc0, crc1, crc2, crc3;
220 crc0 = _mm_crc32_u64(k0, seed);
221 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
223 crc2 = _mm_crc32_u64(k2, k[3]);
224 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
226 crc0 = _mm_crc32_u64(crc0, crc1);
227 crc1 = _mm_crc32_u64(crc2, crc3);
234 static inline uint64_t
235 hash_crc_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed)
238 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3;
244 crc0 = _mm_crc32_u64(k0, seed);
245 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
247 crc2 = _mm_crc32_u64(k2, k[3]);
248 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
250 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
251 crc1 = _mm_crc32_u64(crc3, k5);
258 static inline uint64_t
259 hash_crc_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed)
262 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
268 crc0 = _mm_crc32_u64(k0, seed);
269 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
271 crc2 = _mm_crc32_u64(k2, k[3]);
272 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
274 crc4 = _mm_crc32_u64(k5, k[6]);
277 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
278 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
285 static inline uint64_t
286 hash_crc_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed)
289 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
295 crc0 = _mm_crc32_u64(k0, seed);
296 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
298 crc2 = _mm_crc32_u64(k2, k[3]);
299 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
301 crc4 = _mm_crc32_u64(k5, k[6]);
302 crc5 = _mm_crc32_u64(k5 >> 32, k[7]);
304 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
305 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
312 #define hash_default_key8 hash_crc_key8
313 #define hash_default_key16 hash_crc_key16
314 #define hash_default_key24 hash_crc_key24
315 #define hash_default_key32 hash_crc_key32
316 #define hash_default_key40 hash_crc_key40
317 #define hash_default_key48 hash_crc_key48
318 #define hash_default_key56 hash_crc_key56
319 #define hash_default_key64 hash_crc_key64
323 #define hash_default_key8 hash_xor_key8
324 #define hash_default_key16 hash_xor_key16
325 #define hash_default_key24 hash_xor_key24
326 #define hash_default_key32 hash_xor_key32
327 #define hash_default_key40 hash_xor_key40
328 #define hash_default_key48 hash_xor_key48
329 #define hash_default_key56 hash_xor_key56
330 #define hash_default_key64 hash_xor_key64