4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef __INCLUDE_HASH_FUNC_H__
34 #define __INCLUDE_HASH_FUNC_H__
36 static inline uint64_t
37 hash_xor_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed)
44 return (xor0 >> 32) ^ xor0;
47 static inline uint64_t
48 hash_xor_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed)
53 xor0 = (k[0] ^ seed) ^ k[1];
55 return (xor0 >> 32) ^ xor0;
58 static inline uint64_t
59 hash_xor_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed)
64 xor0 = (k[0] ^ seed) ^ k[1];
68 return (xor0 >> 32) ^ xor0;
71 static inline uint64_t
72 hash_xor_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed)
77 xor0 = (k[0] ^ seed) ^ k[1];
82 return (xor0 >> 32) ^ xor0;
85 static inline uint64_t
86 hash_xor_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed)
91 xor0 = (k[0] ^ seed) ^ k[1];
98 return (xor0 >> 32) ^ xor0;
101 static inline uint64_t
102 hash_xor_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed)
105 uint64_t xor0, xor1, xor2;
107 xor0 = (k[0] ^ seed) ^ k[1];
115 return (xor0 >> 32) ^ xor0;
118 static inline uint64_t
119 hash_xor_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed)
122 uint64_t xor0, xor1, xor2;
124 xor0 = (k[0] ^ seed) ^ k[1];
133 return (xor0 >> 32) ^ xor0;
136 static inline uint64_t
137 hash_xor_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed)
140 uint64_t xor0, xor1, xor2, xor3;
142 xor0 = (k[0] ^ seed) ^ k[1];
152 return (xor0 >> 32) ^ xor0;
155 #if defined(RTE_ARCH_X86_64)
157 #include <x86intrin.h>
159 static inline uint64_t
160 hash_crc_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed)
165 crc0 = _mm_crc32_u64(seed, k[0]);
170 static inline uint64_t
171 hash_crc_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed)
174 uint64_t k0, crc0, crc1;
178 crc0 = _mm_crc32_u64(k0, seed);
179 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
186 static inline uint64_t
187 hash_crc_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed)
190 uint64_t k0, k2, crc0, crc1;
195 crc0 = _mm_crc32_u64(k0, seed);
196 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
198 crc0 = _mm_crc32_u64(crc0, k2);
205 static inline uint64_t
206 hash_crc_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed)
209 uint64_t k0, k2, crc0, crc1, crc2, crc3;
214 crc0 = _mm_crc32_u64(k0, seed);
215 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
217 crc2 = _mm_crc32_u64(k2, k[3]);
220 crc0 = _mm_crc32_u64(crc0, crc1);
221 crc1 = _mm_crc32_u64(crc2, crc3);
228 static inline uint64_t
229 hash_crc_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed)
232 uint64_t k0, k2, crc0, crc1, crc2, crc3;
237 crc0 = _mm_crc32_u64(k0, seed);
238 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
240 crc2 = _mm_crc32_u64(k2, k[3]);
241 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
243 crc0 = _mm_crc32_u64(crc0, crc1);
244 crc1 = _mm_crc32_u64(crc2, crc3);
251 static inline uint64_t
252 hash_crc_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed)
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]);
264 crc2 = _mm_crc32_u64(k2, k[3]);
265 crc3 = _mm_crc32_u64(k2 >> 32, k[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, __rte_unused uint32_t key_size, uint64_t seed)
279 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
285 crc0 = _mm_crc32_u64(k0, seed);
286 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
288 crc2 = _mm_crc32_u64(k2, k[3]);
289 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
291 crc4 = _mm_crc32_u64(k5, k[6]);
294 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
295 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
302 static inline uint64_t
303 hash_crc_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed)
306 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
312 crc0 = _mm_crc32_u64(k0, seed);
313 crc1 = _mm_crc32_u64(k0 >> 32, k[1]);
315 crc2 = _mm_crc32_u64(k2, k[3]);
316 crc3 = _mm_crc32_u64(k2 >> 32, k[4]);
318 crc4 = _mm_crc32_u64(k5, k[6]);
319 crc5 = _mm_crc32_u64(k5 >> 32, k[7]);
321 crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2);
322 crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5);
329 #define hash_default_key8 hash_crc_key8
330 #define hash_default_key16 hash_crc_key16
331 #define hash_default_key24 hash_crc_key24
332 #define hash_default_key32 hash_crc_key32
333 #define hash_default_key40 hash_crc_key40
334 #define hash_default_key48 hash_crc_key48
335 #define hash_default_key56 hash_crc_key56
336 #define hash_default_key64 hash_crc_key64
340 #define hash_default_key8 hash_xor_key8
341 #define hash_default_key16 hash_xor_key16
342 #define hash_default_key24 hash_xor_key24
343 #define hash_default_key32 hash_xor_key32
344 #define hash_default_key40 hash_xor_key40
345 #define hash_default_key48 hash_xor_key48
346 #define hash_default_key56 hash_xor_key56
347 #define hash_default_key64 hash_xor_key64