22 #include <rte_config.h> 45 #define rot(x, k) (((x) << (k)) | ((x) >> (32-(k)))) 48 #define __rte_jhash_mix(a, b, c) do { \ 49 a -= c; a ^= rot(c, 4); c += b; \ 50 b -= a; b ^= rot(a, 6); a += c; \ 51 c -= b; c ^= rot(b, 8); b += a; \ 52 a -= c; a ^= rot(c, 16); c += b; \ 53 b -= a; b ^= rot(a, 19); a += c; \ 54 c -= b; c ^= rot(b, 4); b += a; \ 57 #define __rte_jhash_final(a, b, c) do { \ 58 c ^= b; c -= rot(b, 14); \ 59 a ^= c; a -= rot(c, 11); \ 60 b ^= a; b -= rot(a, 25); \ 61 c ^= b; c -= rot(b, 16); \ 62 a ^= c; a -= rot(c, 4); \ 63 b ^= a; b -= rot(a, 14); \ 64 c ^= b; c -= rot(b, 24); \ 68 #define RTE_JHASH_GOLDEN_RATIO 0xdeadbeef 70 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN 71 #define BIT_SHIFT(x, y, k) (((x) >> (k)) | ((uint64_t)(y) << (32-(k)))) 73 #define BIT_SHIFT(x, y, k) (((uint64_t)(x) << (k)) | ((y) >> (32-(k)))) 76 #define LOWER8b_MASK rte_le_to_cpu_32(0xff) 77 #define LOWER16b_MASK rte_le_to_cpu_32(0xffff) 78 #define LOWER24b_MASK rte_le_to_cpu_32(0xffffff) 81 __rte_jhash_2hashes(
const void *key, uint32_t length, uint32_t *pc,
82 uint32_t *pb,
unsigned check_align)
94 #if defined(RTE_ARCH_X86) 95 const uint32_t *k = (
const uint32_t *)key;
98 const uint32_t *k = (uint32_t *)((uintptr_t)key & (uintptr_t)~3);
99 const uint32_t s = ((uintptr_t)key & 3) * CHAR_BIT;
101 if (!check_align || s == 0) {
102 while (length > 12) {
107 __rte_jhash_mix(a, b, c);
115 c += k[2]; b += k[1]; a += k[0];
break;
117 c += k[2] & LOWER24b_MASK; b += k[1]; a += k[0];
break;
119 c += k[2] & LOWER16b_MASK; b += k[1]; a += k[0];
break;
121 c += k[2] & LOWER8b_MASK; b += k[1]; a += k[0];
break;
123 b += k[1]; a += k[0];
break;
125 b += k[1] & LOWER24b_MASK; a += k[0];
break;
127 b += k[1] & LOWER16b_MASK; a += k[0];
break;
129 b += k[1] & LOWER8b_MASK; a += k[0];
break;
133 a += k[0] & LOWER24b_MASK;
break;
135 a += k[0] & LOWER16b_MASK;
break;
137 a += k[0] & LOWER8b_MASK;
break;
146 while (length > 12) {
147 a += BIT_SHIFT(k[0], k[1], s);
148 b += BIT_SHIFT(k[1], k[2], s);
149 c += BIT_SHIFT(k[2], k[3], s);
150 __rte_jhash_mix(a, b, c);
159 a += BIT_SHIFT(k[0], k[1], s);
160 b += BIT_SHIFT(k[1], k[2], s);
161 c += BIT_SHIFT(k[2], k[3], s);
164 a += BIT_SHIFT(k[0], k[1], s);
165 b += BIT_SHIFT(k[1], k[2], s);
166 c += BIT_SHIFT(k[2], k[3], s) & LOWER24b_MASK;
169 a += BIT_SHIFT(k[0], k[1], s);
170 b += BIT_SHIFT(k[1], k[2], s);
171 c += BIT_SHIFT(k[2], k[3], s) & LOWER16b_MASK;
174 a += BIT_SHIFT(k[0], k[1], s);
175 b += BIT_SHIFT(k[1], k[2], s);
176 c += BIT_SHIFT(k[2], k[3], s) & LOWER8b_MASK;
179 a += BIT_SHIFT(k[0], k[1], s);
180 b += BIT_SHIFT(k[1], k[2], s);
183 a += BIT_SHIFT(k[0], k[1], s);
184 b += BIT_SHIFT(k[1], k[2], s) & LOWER24b_MASK;
187 a += BIT_SHIFT(k[0], k[1], s);
188 b += BIT_SHIFT(k[1], k[2], s) & LOWER16b_MASK;
191 a += BIT_SHIFT(k[0], k[1], s);
192 b += BIT_SHIFT(k[1], k[2], s) & LOWER8b_MASK;
195 a += BIT_SHIFT(k[0], k[1], s);
198 a += BIT_SHIFT(k[0], k[1], s) & LOWER24b_MASK;
201 a += BIT_SHIFT(k[0], k[1], s) & LOWER16b_MASK;
204 a += BIT_SHIFT(k[0], k[1], s) & LOWER8b_MASK;
214 __rte_jhash_final(a, b, c);
238 __rte_jhash_2hashes(key, length, pc, pb, 1);
259 __rte_jhash_2hashes((
const void *) k, (length << 2), pc, pb, 0);
279 static inline uint32_t
280 rte_jhash(
const void *key, uint32_t length, uint32_t initval)
282 uint32_t initval2 = 0;
302 static inline uint32_t
305 uint32_t initval2 = 0;
312 static inline uint32_t
313 __rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)
319 __rte_jhash_final(a, b, c);
339 static inline uint32_t
342 return __rte_jhash_3words(a + 12, b + 12, c + 12, initval);
358 static inline uint32_t
361 return __rte_jhash_3words(a + 8, b + 8, 8, initval);
375 static inline uint32_t
378 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)