51 #include <rte_config.h>
74 #define rot(x, k) (((x) << (k)) | ((x) >> (32-(k))))
77 #define __rte_jhash_mix(a, b, c) do { \
78 a -= c; a ^= rot(c, 4); c += b; \
79 b -= a; b ^= rot(a, 6); a += c; \
80 c -= b; c ^= rot(b, 8); b += a; \
81 a -= c; a ^= rot(c, 16); c += b; \
82 b -= a; b ^= rot(a, 19); a += c; \
83 c -= b; c ^= rot(b, 4); b += a; \
86 #define __rte_jhash_final(a, b, c) do { \
87 c ^= b; c -= rot(b, 14); \
88 a ^= c; a -= rot(c, 11); \
89 b ^= a; b -= rot(a, 25); \
90 c ^= b; c -= rot(b, 16); \
91 a ^= c; a -= rot(c, 4); \
92 b ^= a; b -= rot(a, 14); \
93 c ^= b; c -= rot(b, 24); \
97 #define RTE_JHASH_GOLDEN_RATIO 0xdeadbeef
99 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
100 #define BIT_SHIFT(x, y, k) (((x) >> (k)) | ((uint64_t)(y) << (32-(k))))
102 #define BIT_SHIFT(x, y, k) (((uint64_t)(x) << (k)) | ((y) >> (32-(k))))
105 #define LOWER8b_MASK rte_le_to_cpu_32(0xff)
106 #define LOWER16b_MASK rte_le_to_cpu_32(0xffff)
107 #define LOWER24b_MASK rte_le_to_cpu_32(0xffffff)
110 __rte_jhash_2hashes(
const void *key, uint32_t length, uint32_t *pc,
111 uint32_t *pb,
unsigned check_align)
123 #if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) || defined(RTE_ARCH_X86_X32)
124 const uint32_t *k = (
const uint32_t *)key;
125 const uint32_t s = 0;
127 const uint32_t *k = (uint32_t *)((uintptr_t)key & (uintptr_t)~3);
128 const uint32_t s = ((uintptr_t)key & 3) * CHAR_BIT;
130 if (!check_align || s == 0) {
131 while (length > 12) {
136 __rte_jhash_mix(a, b, c);
144 c += k[2]; b += k[1]; a += k[0];
break;
146 c += k[2] & LOWER24b_MASK; b += k[1]; a += k[0];
break;
148 c += k[2] & LOWER16b_MASK; b += k[1]; a += k[0];
break;
150 c += k[2] & LOWER8b_MASK; b += k[1]; a += k[0];
break;
152 b += k[1]; a += k[0];
break;
154 b += k[1] & LOWER24b_MASK; a += k[0];
break;
156 b += k[1] & LOWER16b_MASK; a += k[0];
break;
158 b += k[1] & LOWER8b_MASK; a += k[0];
break;
162 a += k[0] & LOWER24b_MASK;
break;
164 a += k[0] & LOWER16b_MASK;
break;
166 a += k[0] & LOWER8b_MASK;
break;
175 while (length > 12) {
176 a += BIT_SHIFT(k[0], k[1], s);
177 b += BIT_SHIFT(k[1], k[2], s);
178 c += BIT_SHIFT(k[2], k[3], s);
179 __rte_jhash_mix(a, b, c);
188 a += BIT_SHIFT(k[0], k[1], s);
189 b += BIT_SHIFT(k[1], k[2], s);
190 c += BIT_SHIFT(k[2], k[3], s);
193 a += BIT_SHIFT(k[0], k[1], s);
194 b += BIT_SHIFT(k[1], k[2], s);
195 c += BIT_SHIFT(k[2], k[3], s) & LOWER24b_MASK;
198 a += BIT_SHIFT(k[0], k[1], s);
199 b += BIT_SHIFT(k[1], k[2], s);
200 c += BIT_SHIFT(k[2], k[3], s) & LOWER16b_MASK;
203 a += BIT_SHIFT(k[0], k[1], s);
204 b += BIT_SHIFT(k[1], k[2], s);
205 c += BIT_SHIFT(k[2], k[3], s) & LOWER8b_MASK;
208 a += BIT_SHIFT(k[0], k[1], s);
209 b += BIT_SHIFT(k[1], k[2], s);
212 a += BIT_SHIFT(k[0], k[1], s);
213 b += BIT_SHIFT(k[1], k[2], s) & LOWER24b_MASK;
216 a += BIT_SHIFT(k[0], k[1], s);
217 b += BIT_SHIFT(k[1], k[2], s) & LOWER16b_MASK;
220 a += BIT_SHIFT(k[0], k[1], s);
221 b += BIT_SHIFT(k[1], k[2], s) & LOWER8b_MASK;
224 a += BIT_SHIFT(k[0], k[1], s);
227 a += BIT_SHIFT(k[0], k[1], s) & LOWER24b_MASK;
230 a += BIT_SHIFT(k[0], k[1], s) & LOWER16b_MASK;
233 a += BIT_SHIFT(k[0], k[1], s) & LOWER8b_MASK;
243 __rte_jhash_final(a, b, c);
267 __rte_jhash_2hashes(key, length, pc, pb, 1);
288 __rte_jhash_2hashes((
const void *) k, (length << 2), pc, pb, 0);
308 static inline uint32_t
309 rte_jhash(
const void *key, uint32_t length, uint32_t initval)
311 uint32_t initval2 = 0;
331 static inline uint32_t
334 uint32_t initval2 = 0;
341 static inline uint32_t
342 __rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)
348 __rte_jhash_final(a, b, c);
368 static inline uint32_t
371 return __rte_jhash_3words(a + 12, b + 12, c + 12, initval);
387 static inline uint32_t
390 return __rte_jhash_3words(a + 8, b + 8, 8, initval);
404 static inline uint32_t
407 return __rte_jhash_3words(a + 4, 4, 4, initval);
static void rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, uint32_t *pb)
static uint32_t rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)
static void rte_jhash_32b_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
static uint32_t rte_jhash_32b(const uint32_t *k, uint32_t length, uint32_t initval)
static uint32_t rte_jhash_1word(uint32_t a, uint32_t initval)
#define RTE_JHASH_GOLDEN_RATIO
static uint32_t rte_jhash(const void *key, uint32_t length, uint32_t initval)
static uint32_t rte_jhash_2words(uint32_t a, uint32_t b, uint32_t initval)