1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef __INCLUDE_RTE_TABLE_HASH_FUNC_H__
6 #define __INCLUDE_RTE_TABLE_HASH_FUNC_H__
14 #include <rte_compat.h>
15 #include <rte_common.h>
18 static inline uint64_t
19 rte_crc32_u64_generic(uint64_t crc, uint64_t value)
23 crc = (crc & 0xFFFFFFFFLLU) ^ value;
24 for (i = 63; i >= 0; i--) {
28 crc = (crc >> 1LLU) ^ (0x82F63B78LLU & mask);
34 #if defined(RTE_ARCH_X86_64)
36 #include <x86intrin.h>
38 static inline uint64_t
39 rte_crc32_u64(uint64_t crc, uint64_t v)
41 return _mm_crc32_u64(crc, v);
44 #elif defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32)
45 #include "rte_table_hash_func_arm64.h"
48 static inline uint64_t
49 rte_crc32_u64(uint64_t crc, uint64_t v)
51 return rte_crc32_u64_generic(crc, v);
57 static inline uint64_t
58 rte_table_hash_crc_key8(void *key, void *mask, __rte_unused uint32_t key_size,
65 crc0 = rte_crc32_u64(seed, k[0] & m[0]);
71 static inline uint64_t
72 rte_table_hash_crc_key16(void *key, void *mask, __rte_unused uint32_t key_size,
77 uint64_t k0, crc0, crc1;
81 crc0 = rte_crc32_u64(k0, seed);
82 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
90 static inline uint64_t
91 rte_table_hash_crc_key24(void *key, void *mask, __rte_unused uint32_t key_size,
96 uint64_t k0, k2, crc0, crc1;
101 crc0 = rte_crc32_u64(k0, seed);
102 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
104 crc0 = rte_crc32_u64(crc0, k2);
112 static inline uint64_t
113 rte_table_hash_crc_key32(void *key, void *mask, __rte_unused uint32_t key_size,
118 uint64_t k0, k2, crc0, crc1, crc2, crc3;
123 crc0 = rte_crc32_u64(k0, seed);
124 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
126 crc2 = rte_crc32_u64(k2, k[3] & m[3]);
129 crc0 = rte_crc32_u64(crc0, crc1);
130 crc1 = rte_crc32_u64(crc2, crc3);
138 static inline uint64_t
139 rte_table_hash_crc_key40(void *key, void *mask, __rte_unused uint32_t key_size,
144 uint64_t k0, k2, crc0, crc1, crc2, crc3;
149 crc0 = rte_crc32_u64(k0, seed);
150 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
152 crc2 = rte_crc32_u64(k2, k[3] & m[3]);
153 crc3 = rte_crc32_u64(k2 >> 32, k[4] & m[4]);
155 crc0 = rte_crc32_u64(crc0, crc1);
156 crc1 = rte_crc32_u64(crc2, crc3);
164 static inline uint64_t
165 rte_table_hash_crc_key48(void *key, void *mask, __rte_unused uint32_t key_size,
170 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3;
176 crc0 = rte_crc32_u64(k0, seed);
177 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
179 crc2 = rte_crc32_u64(k2, k[3] & m[3]);
180 crc3 = rte_crc32_u64(k2 >> 32, k[4] & m[4]);
182 crc0 = rte_crc32_u64(crc0, (crc1 << 32) ^ crc2);
183 crc1 = rte_crc32_u64(crc3, k5);
191 static inline uint64_t
192 rte_table_hash_crc_key56(void *key, void *mask, __rte_unused uint32_t key_size,
197 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
203 crc0 = rte_crc32_u64(k0, seed);
204 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
206 crc2 = rte_crc32_u64(k2, k[3] & m[3]);
207 crc3 = rte_crc32_u64(k2 >> 32, k[4] & m[4]);
209 crc4 = rte_crc32_u64(k5, k[6] & m[6]);
212 crc0 = rte_crc32_u64(crc0, (crc1 << 32) ^ crc2);
213 crc1 = rte_crc32_u64(crc3, (crc4 << 32) ^ crc5);
221 static inline uint64_t
222 rte_table_hash_crc_key64(void *key, void *mask, __rte_unused uint32_t key_size,
227 uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;
233 crc0 = rte_crc32_u64(k0, seed);
234 crc1 = rte_crc32_u64(k0 >> 32, k[1] & m[1]);
236 crc2 = rte_crc32_u64(k2, k[3] & m[3]);
237 crc3 = rte_crc32_u64(k2 >> 32, k[4] & m[4]);
239 crc4 = rte_crc32_u64(k5, k[6] & m[6]);
240 crc5 = rte_crc32_u64(k5 >> 32, k[7] & m[7]);
242 crc0 = rte_crc32_u64(crc0, (crc1 << 32) ^ crc2);
243 crc1 = rte_crc32_u64(crc3, (crc4 << 32) ^ crc5);