Skip to content

Instantly share code, notes, and snippets.

@vstakhov
Created December 3, 2016 23:57
Show Gist options
  • Save vstakhov/3e47efcde1fdd808228a7062886194cb to your computer and use it in GitHub Desktop.
Save vstakhov/3e47efcde1fdd808228a7062886194cb to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <string.h>
#include <assert.h>
static inline uint64_t
diffuse(uint64_t val)
{
uint64_t a, b;
val *= 0x6eed0e9da4d94a4fULL;
//a = val >> 32;
//b = val >> 60;
//val ^= a >> b;
val ^= (val << 17) | (val >> (64 - 17));
val *= 0x6eed0e9da4d94a4fULL;
return val;
}
void sea_hash_test(const void *key, int len, uint32_t seed, void *out) {
uint64_t a, b, c, d;
uint64_t s = seed;
uint64_t *p;
unsigned char pad[8] = {0};
a = 0x16f11fe89b0d677cULL ^ s;
b = 0xb480a793d8e6c86cULL;
c = 0x6fe2e5aaf078ebc9ULL;
d = 0x14f994a4c5259381ULL;
p = (uint64_t *)key;
while (len >= 32) {
a ^= *p++;
b ^= *p++;
c ^= *p++;
d ^= *p++;
a = diffuse(a);
b = diffuse(b);
c = diffuse(c);
d = diffuse(d);
len -= 32;
}
switch (len) {
case 25 ... 31:
a ^= *p++;
b ^= *p++;
c ^= *p++;
memcpy(pad, p, len - 24);
d ^= *(uint64_t *)pad;
a = diffuse(a);
b = diffuse(b);
c = diffuse(c);
d = diffuse(d);
break;
case 24:
a ^= *p++;
b ^= *p++;
c ^= *p++;
a = diffuse(a);
b = diffuse(b);
c = diffuse(c);
break;
case 17 ... 23:
a ^= *p++;
b ^= *p++;
memcpy(pad, p, len - 16);
c ^= *(uint64_t *)pad;
a = diffuse(a);
b = diffuse(b);
c = diffuse(c);
break;
case 16:
a ^= *p++;
b ^= *p++;
a = diffuse(a);
b = diffuse(b);
break;
case 9 ... 15:
a ^= *p++;
memcpy(pad, p, len - 8);
b ^= *(uint64_t *)pad;
a = diffuse(a);
b = diffuse(b);
break;
case 8:
a ^= *p++;
a = diffuse(a);
break;
case 1 ... 7:
memcpy(pad, p, len);
a ^= *(uint64_t *)pad;
a = diffuse(a);
break;
case 0:
break;
default:
assert(0);
}
a ^= b;
c ^= d;
a ^= c;
a ^= (uint64_t)len;
uint64_t r = diffuse(a);
memcpy(out, &r, 8);
}
@vstakhov
Copy link
Author

vstakhov commented Dec 3, 2016


--- Testing seahash "seahash"

[[[ Sanity Tests ]]]

Verification value 0xD7A31648 : PASS
Running sanity check 1 ..........PASS
Running AppendedZeroesTest..........PASS

[[[ Speed Tests ]]]

Bulk speed test - 262144-byte keys
Alignment 7 - 4.453 bytes/cycle - 12740.43 MiB/sec @ 3 ghz
Alignment 6 - 4.022 bytes/cycle - 11507.37 MiB/sec @ 3 ghz
Alignment 5 - 4.274 bytes/cycle - 12226.84 MiB/sec @ 3 ghz
Alignment 4 - 4.378 bytes/cycle - 12526.45 MiB/sec @ 3 ghz
Alignment 3 - 5.179 bytes/cycle - 14816.11 MiB/sec @ 3 ghz
Alignment 2 - 5.019 bytes/cycle - 14360.09 MiB/sec @ 3 ghz
Alignment 1 - 4.977 bytes/cycle - 14240.02 MiB/sec @ 3 ghz
Alignment 0 - 5.250 bytes/cycle - 15019.42 MiB/sec @ 3 ghz
Average - 4.694 bytes/cycle - 13429.59 MiB/sec @ 3 ghz

Small key speed test - 1-byte keys - 33.39 cycles/hash
Small key speed test - 2-byte keys - 34.00 cycles/hash
Small key speed test - 3-byte keys - 42.70 cycles/hash
Small key speed test - 4-byte keys - 37.14 cycles/hash
Small key speed test - 5-byte keys - 42.76 cycles/hash
Small key speed test - 6-byte keys - 42.76 cycles/hash
Small key speed test - 7-byte keys - 39.00 cycles/hash
Small key speed test - 8-byte keys - 27.00 cycles/hash
Small key speed test - 9-byte keys - 42.66 cycles/hash
Small key speed test - 10-byte keys - 43.55 cycles/hash
Small key speed test - 11-byte keys - 40.96 cycles/hash
Small key speed test - 12-byte keys - 42.02 cycles/hash
Small key speed test - 13-byte keys - 44.44 cycles/hash
Small key speed test - 14-byte keys - 44.00 cycles/hash
Small key speed test - 15-byte keys - 45.51 cycles/hash
Small key speed test - 16-byte keys - 29.96 cycles/hash
Small key speed test - 17-byte keys - 39.58 cycles/hash
Small key speed test - 18-byte keys - 40.51 cycles/hash
Small key speed test - 19-byte keys - 41.53 cycles/hash
Small key speed test - 20-byte keys - 45.27 cycles/hash
Small key speed test - 21-byte keys - 44.08 cycles/hash
Small key speed test - 22-byte keys - 44.66 cycles/hash
Small key speed test - 23-byte keys - 46.92 cycles/hash
Small key speed test - 24-byte keys - 27.86 cycles/hash
Small key speed test - 25-byte keys - 38.26 cycles/hash
Small key speed test - 26-byte keys - 39.59 cycles/hash
Small key speed test - 27-byte keys - 39.90 cycles/hash
Small key speed test - 28-byte keys - 41.42 cycles/hash
Small key speed test - 29-byte keys - 42.00 cycles/hash
Small key speed test - 30-byte keys - 42.00 cycles/hash
Small key speed test - 31-byte keys - 43.20 cycles/hash
Average 40.278 cycles/hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment