9 template <
class keyType>
15 std::hash<keyType> fallback;
24 template <
class T = keyType>
25 typename std::enable_if<std::is_integral<T>::value, uint32_t>::type
26 operator()(
const keyType& k0)
const {
27 #if defined(__SSE4_2__)
28 #pragma message("Hasher CRC32c")
33 if (
sizeof(keyType)>=8)
34 asm (
".byte 0xf2, 0x48, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" ((*k)+s1) );
36 if (
sizeof(keyType)>=16) {
37 s1 = ((((uint64_t) s1) * s1 >> 16) ^ (s1 << 2));
39 asm (
".byte 0xf2, 0x48, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" ((*k)+s1) );
41 if (
sizeof(keyType)>=24) {
42 s1 = ((((uint64_t) s1) * s1 >> 16) ^ (s1 << 2));
44 asm (
".byte 0xf2, 0x48, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" ((*k)+s1) );
46 if (
sizeof(keyType)>=32) {
47 s1 = ((((uint64_t) s1) * s1 >> 16) ^ (s1 << 2));
49 asm (
".byte 0xf2, 0x48, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" ((*k)+s1) );
51 if (
sizeof(keyType) & 4) {
53 k32 = ((*k)) & 0xFFFFFFFFULL;
54 asm (
".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" ((k32)+s1) );
58 asm (
".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;" :
"=S" (crc1) :
"0" (crc1),
"c" (s1) );
60 crc1 ^= (crc1 >> (hashshr));
61 if (
sizeof(keyType)==4)
62 return mask & (crc1 ^ ((uint32_t) *k));
64 return mask & (crc1 ^ (*k >> 32) ^ ((uint32_t) *k));
66 #pragma message("Build without SSE4.2 support ")
67 return mask & fallback(k0);
71 template <
class T = keyType>
72 typename std::enable_if<!std::is_integral<T>::value, uint32_t>::type
73 operator()(
const keyType& k0)
const {
74 return mask & fallback(k0^
s ^ (
s <<(8+hashshr)));
A hash function that hashes keyType to uint32_t. When SSE4.2 support is found, use sse4...
Definition: hash.h:10
void setMaskSeed(uint32_t _mask, uint32_t _seed)
set bitmask and seed
Definition: hash.h:19
uint32_t s
hash seed.
Definition: hash.h:13
uint32_t mask
a bitmask for the return value. return value must be within [0..mask]
Definition: hash.h:12