44 #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
48 #define __cne_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 __cne_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); \
69 #define CNE_JHASH_GOLDEN_RATIO 0xdeadbeef
71 #if BYTE_ORDER == LITTLE_ENDIAN
72 #define BIT_SHIFT(x, y, k) (((x) >> (k)) | ((uint64_t)(y) << (32 - (k))))
74 #define BIT_SHIFT(x, y, k) (((uint64_t)(x) << (k)) | ((y) >> (32 - (k))))
77 #define LOWER8b_MASK le32toh(0xff)
78 #define LOWER16b_MASK le32toh(0xffff)
79 #define LOWER24b_MASK le32toh(0xffffff)
82 __cne_jhash_2hashes(
const void *key, uint32_t length, uint32_t *pc, uint32_t *pb,
95 const uint32_t *k = (
const uint32_t *)key;
97 if (!check_align || s == 0) {
103 __cne_jhash_mix(a, b, c);
111 c += k[2]; b += k[1]; a += k[0];
break;
113 c += k[2] & LOWER24b_MASK; b += k[1]; a += k[0];
break;
115 c += k[2] & LOWER16b_MASK; b += k[1]; a += k[0];
break;
117 c += k[2] & LOWER8b_MASK; b += k[1]; a += k[0];
break;
119 b += k[1]; a += k[0];
break;
121 b += k[1] & LOWER24b_MASK; a += k[0];
break;
123 b += k[1] & LOWER16b_MASK; a += k[0];
break;
125 b += k[1] & LOWER8b_MASK; a += k[0];
break;
129 a += k[0] & LOWER24b_MASK;
break;
131 a += k[0] & LOWER16b_MASK;
break;
133 a += k[0] & LOWER8b_MASK;
break;
143 while (length > 12) {
144 a += BIT_SHIFT(k[0], k[1], s);
145 b += BIT_SHIFT(k[1], k[2], s);
146 c += BIT_SHIFT(k[2], k[3], s);
147 __cne_jhash_mix(a, b, c);
156 a += BIT_SHIFT(k[0], k[1], s);
157 b += BIT_SHIFT(k[1], k[2], s);
158 c += BIT_SHIFT(k[2], k[3], s);
161 a += BIT_SHIFT(k[0], k[1], s);
162 b += BIT_SHIFT(k[1], k[2], s);
163 c += BIT_SHIFT(k[2], k[3], s) & LOWER24b_MASK;
166 a += BIT_SHIFT(k[0], k[1], s);
167 b += BIT_SHIFT(k[1], k[2], s);
168 c += BIT_SHIFT(k[2], k[3], s) & LOWER16b_MASK;
171 a += BIT_SHIFT(k[0], k[1], s);
172 b += BIT_SHIFT(k[1], k[2], s);
173 c += BIT_SHIFT(k[2], k[3], s) & LOWER8b_MASK;
176 a += BIT_SHIFT(k[0], k[1], s);
177 b += BIT_SHIFT(k[1], k[2], s);
180 a += BIT_SHIFT(k[0], k[1], s);
181 b += BIT_SHIFT(k[1], k[2], s) & LOWER24b_MASK;
184 a += BIT_SHIFT(k[0], k[1], s);
185 b += BIT_SHIFT(k[1], k[2], s) & LOWER16b_MASK;
188 a += BIT_SHIFT(k[0], k[1], s);
189 b += BIT_SHIFT(k[1], k[2], s) & LOWER8b_MASK;
192 a += BIT_SHIFT(k[0], k[1], s);
195 a += BIT_SHIFT(k[0], k[1], s) & LOWER24b_MASK;
198 a += BIT_SHIFT(k[0], k[1], s) & LOWER16b_MASK;
201 a += BIT_SHIFT(k[0], k[1], s) & LOWER8b_MASK;
211 __cne_jhash_final(a, b, c);
235 __cne_jhash_2hashes(key, length, pc, pb, 1);
256 __cne_jhash_2hashes((
const void *)k, (length << 2), pc, pb, 0);
276 static inline uint32_t
277 cne_jhash(
const void *key, uint32_t length, uint32_t initval)
279 uint32_t initval2 = 0;
299 static inline uint32_t
302 uint32_t initval2 = 0;
309 static inline uint32_t
310 __cne_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)
316 __cne_jhash_final(a, b, c);
336 static inline uint32_t
339 return __cne_jhash_3words(a + 12, b + 12, c + 12, initval);
355 static inline uint32_t
358 return __cne_jhash_3words(a + 8, b + 8, 8, initval);
372 static inline uint32_t
375 return __cne_jhash_3words(a + 4, 4, 4, initval);
static uint32_t cne_jhash_1word(uint32_t a, uint32_t initval)
#define CNE_JHASH_GOLDEN_RATIO
static uint32_t cne_jhash(const void *key, uint32_t length, uint32_t initval)
static uint32_t cne_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)
static uint32_t cne_jhash_32b(const uint32_t *k, uint32_t length, uint32_t initval)
static void cne_jhash_32b_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
static uint32_t cne_jhash_2words(uint32_t a, uint32_t b, uint32_t initval)
static void cne_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, uint32_t *pb)