4 * Copyright(c) 2017 Linaro Limited. 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 __HASH_FUNC_ARM64_H__
34 #define __HASH_FUNC_ARM64_H__
36 #define _CRC32CX(crc, val) \
37 __asm__("crc32cx %w[c], %w[c], %x[v]":[c] "+r" (crc):[v] "r" (val))
39 static inline uint64_t
40 hash_crc_key8(void *key, void *mask, __rte_unused uint32_t key_size,
48 _CRC32CX(crc0, k[0] & m[0]);
53 static inline uint64_t
54 hash_crc_key16(void *key, void *mask, __rte_unused uint32_t key_size,
57 uint64_t *k = key, k0;
66 _CRC32CX(crc1, k[1] & m[1]);
73 static inline uint64_t
74 hash_crc_key24(void *key, void *mask, __rte_unused uint32_t key_size,
77 uint64_t *k = key, k0, k2;
87 _CRC32CX(crc1, k[1] & m[1]);
96 static inline uint64_t
97 hash_crc_key32(void *key, void *mask, __rte_unused uint32_t key_size,
100 uint64_t *k = key, k0, k2;
102 uint32_t crc0, crc1, crc2, crc3;
108 _CRC32CX(crc0, seed);
110 _CRC32CX(crc1, k[1] & m[1]);
113 _CRC32CX(crc2, k[3] & m[3]);
116 _CRC32CX(crc0, crc1);
117 _CRC32CX(crc2, crc3);
124 static inline uint64_t
125 hash_crc_key40(void *key, void *mask, __rte_unused uint32_t key_size,
128 uint64_t *k = key, k0, k2;
130 uint32_t crc0, crc1, crc2, crc3;
136 _CRC32CX(crc0, seed);
138 _CRC32CX(crc1, k[1] & m[1]);
141 _CRC32CX(crc2, k[3] & m[3]);
143 _CRC32CX(crc3, k[4] & m[4]);
145 _CRC32CX(crc0, crc1);
146 _CRC32CX(crc2, crc3);
153 static inline uint64_t
154 hash_crc_key48(void *key, void *mask, __rte_unused uint32_t key_size,
157 uint64_t *k = key, k0, k2, k5;
159 uint32_t crc0, crc1, crc2, crc3;
166 _CRC32CX(crc0, seed);
168 _CRC32CX(crc1, k[1] & m[1]);
171 _CRC32CX(crc2, k[3] & m[3]);
173 _CRC32CX(crc3, k[4] & m[4]);
175 _CRC32CX(crc0, ((uint64_t)crc1 << 32) ^ crc2);
183 static inline uint64_t
184 hash_crc_key56(void *key, void *mask, __rte_unused uint32_t key_size,
187 uint64_t *k = key, k0, k2, k5;
189 uint32_t crc0, crc1, crc2, crc3, crc4, crc5;
196 _CRC32CX(crc0, seed);
198 _CRC32CX(crc1, k[1] & m[1]);
201 _CRC32CX(crc2, k[3] & m[3]);
203 _CRC32CX(crc3, k[4] & m[4]);
206 _CRC32CX(crc4, k[6] & m[6]);
209 _CRC32CX(crc0, ((uint64_t)crc1 << 32) ^ crc2);
210 _CRC32CX(crc3, ((uint64_t)crc4 << 32) ^ crc5);
217 static inline uint64_t
218 hash_crc_key64(void *key, void *mask, __rte_unused uint32_t key_size,
221 uint64_t *k = key, k0, k2, k5;
223 uint32_t crc0, crc1, crc2, crc3, crc4, crc5;
230 _CRC32CX(crc0, seed);
232 _CRC32CX(crc1, k[1] & m[1]);
235 _CRC32CX(crc2, k[3] & m[3]);
237 _CRC32CX(crc3, k[4] & m[4]);
240 _CRC32CX(crc4, k[6] & m[6]);
242 _CRC32CX(crc5, k[7] & m[7]);
244 _CRC32CX(crc0, ((uint64_t)crc1 << 32) ^ crc2);
245 _CRC32CX(crc3, ((uint64_t)crc4 << 32) ^ crc5);
252 #define hash_default_key8 hash_crc_key8
253 #define hash_default_key16 hash_crc_key16
254 #define hash_default_key24 hash_crc_key24
255 #define hash_default_key32 hash_crc_key32
256 #define hash_default_key40 hash_crc_key40
257 #define hash_default_key48 hash_crc_key48
258 #define hash_default_key56 hash_crc_key56
259 #define hash_default_key64 hash_crc_key64