20 #ifdef WORDS_BIGENDIAN
21 # define HASH_LITTLE_ENDIAN 0
22 # define HASH_BIG_ENDIAN 1
24 # define HASH_LITTLE_ENDIAN 1
25 # define HASH_BIG_ENDIAN 0
28 #define rot(x,k) (((x)<<(k)) ^ ((x)>>(32-(k))))
76 a -= c; a ^= rot(c, 4); c += b; \
77 b -= a; b ^= rot(a, 6); a += c; \
78 c -= b; c ^= rot(b, 8); b += a; \
79 a -= c; a ^= rot(c,16); c += b; \
80 b -= a; b ^= rot(a,19); a += c; \
81 c -= b; c ^= rot(b, 4); b += a; \
109 #define final(a,b,c) \
111 c ^= b; c -= rot(b,14); \
112 a ^= c; a -= rot(c,11); \
113 b ^= a; b -= rot(a,25); \
114 c ^= b; c -= rot(b,16); \
115 a ^= c; a -= rot(c,4); \
116 b ^= a; b -= rot(a,14); \
117 c ^= b; c -= rot(b,24); \
120 #if HASH_LITTLE_ENDIAN == 1
124 const uint32_t initval)
127 union {
const void *ptr;
size_t i; } u;
130 a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
133 if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
134 const uint32_t *k = key;
164 case 12: c+=k[2]; b+=k[1]; a+=k[0];
break;
165 case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0];
break;
166 case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0];
break;
167 case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0];
break;
168 case 8 : b+=k[1]; a+=k[0];
break;
169 case 7 : b+=k[1]&0xffffff; a+=k[0];
break;
170 case 6 : b+=k[1]&0xffff; a+=k[0];
break;
171 case 5 : b+=k[1]&0xff; a+=k[0];
break;
172 case 4 : a+=k[0];
break;
173 case 3 : a+=k[0]&0xffffff;
break;
174 case 2 : a+=k[0]&0xffff;
break;
175 case 1 : a+=k[0]&0xff;
break;
181 k8 = (
const uint8_t *)k;
184 case 12: c+=k[2]; b+=k[1]; a+=k[0];
break;
185 case 11: c+=((uint32_t)k8[10])<<16;
186 case 10: c+=((uint32_t)k8[9])<<8;
188 case 8 : b+=k[1]; a+=k[0];
break;
189 case 7 : b+=((uint32_t)k8[6])<<16;
190 case 6 : b+=((uint32_t)k8[5])<<8;
192 case 4 : a+=k[0];
break;
193 case 3 : a+=((uint32_t)k8[2])<<16;
194 case 2 : a+=((uint32_t)k8[1])<<8;
195 case 1 : a+=k8[0];
break;
201 }
else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
202 const uint16_t *k = key;
208 a += k[0] + (((uint32_t)k[1])<<16);
209 b += k[2] + (((uint32_t)k[3])<<16);
210 c += k[4] + (((uint32_t)k[5])<<16);
217 k8 = (
const uint8_t *)k;
220 case 12: c+=k[4]+(((uint32_t)k[5])<<16);
221 b+=k[2]+(((uint32_t)k[3])<<16);
222 a+=k[0]+(((uint32_t)k[1])<<16);
224 case 11: c+=((uint32_t)k8[10])<<16;
226 b+=k[2]+(((uint32_t)k[3])<<16);
227 a+=k[0]+(((uint32_t)k[1])<<16);
230 case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
231 a+=k[0]+(((uint32_t)k[1])<<16);
233 case 7 : b+=((uint32_t)k8[6])<<16;
235 a+=k[0]+(((uint32_t)k[1])<<16);
238 case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
240 case 3 : a+=((uint32_t)k8[2])<<16;
249 const uint8_t *k = key;
255 a += ((uint32_t)k[1])<<8;
256 a += ((uint32_t)k[2])<<16;
257 a += ((uint32_t)k[3])<<24;
259 b += ((uint32_t)k[5])<<8;
260 b += ((uint32_t)k[6])<<16;
261 b += ((uint32_t)k[7])<<24;
263 c += ((uint32_t)k[9])<<8;
264 c += ((uint32_t)k[10])<<16;
265 c += ((uint32_t)k[11])<<24;
274 case 12: c+=((uint32_t)k[11])<<24;
275 case 11: c+=((uint32_t)k[10])<<16;
276 case 10: c+=((uint32_t)k[9])<<8;
278 case 8 : b+=((uint32_t)k[7])<<24;
279 case 7 : b+=((uint32_t)k[6])<<16;
280 case 6 : b+=((uint32_t)k[5])<<8;
282 case 4 : a+=((uint32_t)k[3])<<24;
283 case 3 : a+=((uint32_t)k[2])<<16;
284 case 2 : a+=((uint32_t)k[1])<<8;
295 #elif HASH_BIG_ENDIAN == 1
302 uint32_t hash(
const void *key,
size_t length,
const uint32_t initval)
305 union {
const void *ptr;
size_t i; } u;
308 a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
311 if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) {
312 const uint32_t *k = key;
342 case 12: c+=k[2]; b+=k[1]; a+=k[0];
break;
343 case 11: c+=k[2]&0xffffff00; b+=k[1]; a+=k[0];
break;
344 case 10: c+=k[2]&0xffff0000; b+=k[1]; a+=k[0];
break;
345 case 9 : c+=k[2]&0xff000000; b+=k[1]; a+=k[0];
break;
346 case 8 : b+=k[1]; a+=k[0];
break;
347 case 7 : b+=k[1]&0xffffff00; a+=k[0];
break;
348 case 6 : b+=k[1]&0xffff0000; a+=k[0];
break;
349 case 5 : b+=k[1]&0xff000000; a+=k[0];
break;
350 case 4 : a+=k[0];
break;
351 case 3 : a+=k[0]&0xffffff00;
break;
352 case 2 : a+=k[0]&0xffff0000;
break;
353 case 1 : a+=k[0]&0xff000000;
break;
359 k8 = (
const uint8_t *)k;
362 case 12: c+=k[2]; b+=k[1]; a+=k[0];
break;
363 case 11: c+=((uint32_t)k8[10])<<8;
364 case 10: c+=((uint32_t)k8[9])<<16;
365 case 9 : c+=((uint32_t)k8[8])<<24;
366 case 8 : b+=k[1]; a+=k[0];
break;
367 case 7 : b+=((uint32_t)k8[6])<<8;
368 case 6 : b+=((uint32_t)k8[5])<<16;
369 case 5 : b+=((uint32_t)k8[4])<<24;
370 case 4 : a+=k[0];
break;
371 case 3 : a+=((uint32_t)k8[2])<<8;
372 case 2 : a+=((uint32_t)k8[1])<<16;
373 case 1 : a+=((uint32_t)k8[0])<<24;
break;
380 const uint8_t *k = key;
385 a += ((uint32_t)k[0])<<24;
386 a += ((uint32_t)k[1])<<16;
387 a += ((uint32_t)k[2])<<8;
388 a += ((uint32_t)k[3]);
389 b += ((uint32_t)k[4])<<24;
390 b += ((uint32_t)k[5])<<16;
391 b += ((uint32_t)k[6])<<8;
392 b += ((uint32_t)k[7]);
393 c += ((uint32_t)k[8])<<24;
394 c += ((uint32_t)k[9])<<16;
395 c += ((uint32_t)k[10])<<8;
396 c += ((uint32_t)k[11]);
406 case 11: c+=((uint32_t)k[10])<<8;
407 case 10: c+=((uint32_t)k[9])<<16;
408 case 9 : c+=((uint32_t)k[8])<<24;
410 case 7 : b+=((uint32_t)k[6])<<8;
411 case 6 : b+=((uint32_t)k[5])<<16;
412 case 5 : b+=((uint32_t)k[4])<<24;
414 case 3 : a+=((uint32_t)k[2])<<8;
415 case 2 : a+=((uint32_t)k[1])<<16;
416 case 1 : a+=((uint32_t)k[0])<<24;
426 #error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN