github.com/songzhibin97/gkit@v1.2.13/sys/xxhash3/util.go (about) 1 // Package xxhash3 implements https://github.com/Cyan4973/xxHash/blob/dev/xxhash.h 2 package xxhash3 3 4 import ( 5 "math/bits" 6 "unsafe" 7 8 "golang.org/x/sys/cpu" 9 ) 10 11 var ( 12 avx2 = cpu.X86.HasAVX2 13 sse2 = cpu.X86.HasSSE2 14 hashfunc = [2]func(unsafe.Pointer, int) uint64{xxh3HashSmall, xxh3HashLarge} 15 hashfunc128 = [2]func(unsafe.Pointer, int) [2]uint64{xxh3HashSmall128, xxh3HashLarge128} 16 ) 17 18 type funcUnsafe int 19 20 const ( 21 hashSmall funcUnsafe = iota 22 hashLarge 23 ) 24 25 func mix(a, b uint64) uint64 { 26 hi, lo := bits.Mul64(a, b) 27 return hi ^ lo 28 } 29 func xxh3RRMXMX(h64 uint64, length uint64) uint64 { 30 h64 ^= bits.RotateLeft64(h64, 49) ^ bits.RotateLeft64(h64, 24) 31 h64 *= 0x9fb21c651e98df25 32 h64 ^= (h64 >> 35) + length 33 h64 *= 0x9fb21c651e98df25 34 h64 ^= (h64 >> 28) 35 return h64 36 } 37 38 func xxh64Avalanche(h64 uint64) uint64 { 39 h64 *= prime64_2 40 h64 ^= h64 >> 29 41 h64 *= prime64_3 42 h64 ^= h64 >> 32 43 return h64 44 } 45 46 func xxh3Avalanche(x uint64) uint64 { 47 x ^= x >> 37 48 x *= 0x165667919e3779f9 49 x ^= x >> 32 50 return x 51 }