78 | 78 |
xxh.bufused += len(input) - r
|
79 | 79 |
|
80 | 80 |
// fast rotl(31)
|
81 | |
p64 := xxh.v1 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
|
82 | |
xxh.v1 = (p64<<31 | p64>>33) * prime64_1
|
83 | |
p += 8
|
84 | |
p64 = xxh.v2 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
|
85 | |
xxh.v2 = (p64<<31 | p64>>33) * prime64_1
|
86 | |
p += 8
|
87 | |
p64 = xxh.v3 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
|
88 | |
xxh.v3 = (p64<<31 | p64>>33) * prime64_1
|
89 | |
p += 8
|
90 | |
p64 = xxh.v4 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
|
91 | |
xxh.v4 = (p64<<31 | p64>>33) * prime64_1
|
92 | |
|
|
81 |
xxh.v1 = rol31(xxh.v1+u64(xxh.buf[:])*prime64_2) * prime64_1
|
|
82 |
xxh.v2 = rol31(xxh.v2+u64(xxh.buf[8:])*prime64_2) * prime64_1
|
|
83 |
xxh.v3 = rol31(xxh.v3+u64(xxh.buf[16:])*prime64_2) * prime64_1
|
|
84 |
xxh.v4 = rol31(xxh.v4+u64(xxh.buf[24:])*prime64_2) * prime64_1
|
93 | 85 |
p = r
|
94 | 86 |
xxh.bufused = 0
|
95 | 87 |
}
|
96 | 88 |
|
97 | |
for n := n - 32; p <= n; {
|
98 | |
p64 := xxh.v1 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
99 | |
xxh.v1 = (p64<<31 | p64>>33) * prime64_1
|
100 | |
p += 8
|
101 | |
p64 = xxh.v2 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
102 | |
xxh.v2 = (p64<<31 | p64>>33) * prime64_1
|
103 | |
p += 8
|
104 | |
p64 = xxh.v3 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
105 | |
xxh.v3 = (p64<<31 | p64>>33) * prime64_1
|
106 | |
p += 8
|
107 | |
p64 = xxh.v4 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
108 | |
xxh.v4 = (p64<<31 | p64>>33) * prime64_1
|
109 | |
p += 8
|
110 | |
}
|
|
89 |
// Causes compiler to work directly from registers instead of stack:
|
|
90 |
v1, v2, v3, v4 := xxh.v1, xxh.v2, xxh.v3, xxh.v4
|
|
91 |
for n := n - 32; p <= n; p += 32 {
|
|
92 |
sub := input[p:][:32] //BCE hint for compiler
|
|
93 |
v1 = rol31(v1+u64(sub[:])*prime64_2) * prime64_1
|
|
94 |
v2 = rol31(v2+u64(sub[8:])*prime64_2) * prime64_1
|
|
95 |
v3 = rol31(v3+u64(sub[16:])*prime64_2) * prime64_1
|
|
96 |
v4 = rol31(v4+u64(sub[24:])*prime64_2) * prime64_1
|
|
97 |
}
|
|
98 |
xxh.v1, xxh.v2, xxh.v3, xxh.v4 = v1, v2, v3, v4
|
111 | 99 |
|
112 | 100 |
copy(xxh.buf[xxh.bufused:], input[p:])
|
113 | 101 |
xxh.bufused += len(input) - p
|
|
119 | 107 |
func (xxh *xxHash) Sum64() uint64 {
|
120 | 108 |
var h64 uint64
|
121 | 109 |
if xxh.totalLen >= 32 {
|
122 | |
h64 = ((xxh.v1 << 1) | (xxh.v1 >> 63)) +
|
123 | |
((xxh.v2 << 7) | (xxh.v2 >> 57)) +
|
124 | |
((xxh.v3 << 12) | (xxh.v3 >> 52)) +
|
125 | |
((xxh.v4 << 18) | (xxh.v4 >> 46))
|
|
110 |
h64 = rol1(xxh.v1) + rol7(xxh.v2) + rol12(xxh.v3) + rol18(xxh.v4)
|
126 | 111 |
|
127 | 112 |
xxh.v1 *= prime64_2
|
128 | |
h64 ^= ((xxh.v1 << 31) | (xxh.v1 >> 33)) * prime64_1
|
129 | |
h64 = h64*prime64_1 + prime64_4
|
130 | |
|
131 | 113 |
xxh.v2 *= prime64_2
|
132 | |
h64 ^= ((xxh.v2 << 31) | (xxh.v2 >> 33)) * prime64_1
|
133 | |
h64 = h64*prime64_1 + prime64_4
|
134 | |
|
135 | 114 |
xxh.v3 *= prime64_2
|
136 | |
h64 ^= ((xxh.v3 << 31) | (xxh.v3 >> 33)) * prime64_1
|
137 | |
h64 = h64*prime64_1 + prime64_4
|
138 | |
|
139 | 115 |
xxh.v4 *= prime64_2
|
140 | |
h64 ^= ((xxh.v4 << 31) | (xxh.v4 >> 33)) * prime64_1
|
141 | |
h64 = h64*prime64_1 + prime64_4 + xxh.totalLen
|
|
116 |
|
|
117 |
h64 = (h64^(rol31(xxh.v1)*prime64_1))*prime64_1 + prime64_4
|
|
118 |
h64 = (h64^(rol31(xxh.v2)*prime64_1))*prime64_1 + prime64_4
|
|
119 |
h64 = (h64^(rol31(xxh.v3)*prime64_1))*prime64_1 + prime64_4
|
|
120 |
h64 = (h64^(rol31(xxh.v4)*prime64_1))*prime64_1 + prime64_4
|
|
121 |
|
|
122 |
h64 += xxh.totalLen
|
142 | 123 |
} else {
|
143 | 124 |
h64 = xxh.seed + prime64_5 + xxh.totalLen
|
144 | 125 |
}
|
|
146 | 127 |
p := 0
|
147 | 128 |
n := xxh.bufused
|
148 | 129 |
for n := n - 8; p <= n; p += 8 {
|
149 | |
p64 := (uint64(xxh.buf[p+7])<<56 | uint64(xxh.buf[p+6])<<48 | uint64(xxh.buf[p+5])<<40 | uint64(xxh.buf[p+4])<<32 | uint64(xxh.buf[p+3])<<24 | uint64(xxh.buf[p+2])<<16 | uint64(xxh.buf[p+1])<<8 | uint64(xxh.buf[p])) * prime64_2
|
150 | |
h64 ^= ((p64 << 31) | (p64 >> 33)) * prime64_1
|
151 | |
h64 = ((h64<<27)|(h64>>37))*prime64_1 + prime64_4
|
|
130 |
h64 ^= rol31(u64(xxh.buf[p:p+8])*prime64_2) * prime64_1
|
|
131 |
h64 = rol27(h64)*prime64_1 + prime64_4
|
152 | 132 |
}
|
153 | 133 |
if p+4 <= n {
|
154 | |
h64 ^= (uint64(xxh.buf[p+3])<<24 | uint64(xxh.buf[p+2])<<16 | uint64(xxh.buf[p+1])<<8 | uint64(xxh.buf[p])) * prime64_1
|
155 | |
h64 = ((h64<<23)|(h64>>41))*prime64_2 + prime64_3
|
|
134 |
sub := xxh.buf[p : p+4]
|
|
135 |
h64 ^= uint64(u32(sub)) * prime64_1
|
|
136 |
h64 = rol23(h64)*prime64_2 + prime64_3
|
156 | 137 |
p += 4
|
157 | 138 |
}
|
158 | 139 |
for ; p < n; p++ {
|
159 | 140 |
h64 ^= uint64(xxh.buf[p]) * prime64_5
|
160 | |
h64 = ((h64 << 11) | (h64 >> 53)) * prime64_1
|
|
141 |
h64 = rol11(h64) * prime64_1
|
161 | 142 |
}
|
162 | 143 |
|
163 | 144 |
h64 ^= h64 >> 33
|
|
180 | 161 |
v3 := seed
|
181 | 162 |
v4 := seed - prime64_1
|
182 | 163 |
p := 0
|
183 | |
for n := n - 32; p <= n; {
|
184 | |
p64 := v1 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
185 | |
v1 = (p64<<31 | p64>>33) * prime64_1
|
186 | |
p += 8
|
187 | |
p64 = v2 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
188 | |
v2 = (p64<<31 | p64>>33) * prime64_1
|
189 | |
p += 8
|
190 | |
p64 = v3 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
191 | |
v3 = (p64<<31 | p64>>33) * prime64_1
|
192 | |
p += 8
|
193 | |
p64 = v4 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
|
194 | |
v4 = (p64<<31 | p64>>33) * prime64_1
|
195 | |
p += 8
|
|
164 |
for n := n - 32; p <= n; p += 32 {
|
|
165 |
sub := input[p:][:32] //BCE hint for compiler
|
|
166 |
v1 = rol31(v1+u64(sub[:])*prime64_2) * prime64_1
|
|
167 |
v2 = rol31(v2+u64(sub[8:])*prime64_2) * prime64_1
|
|
168 |
v3 = rol31(v3+u64(sub[16:])*prime64_2) * prime64_1
|
|
169 |
v4 = rol31(v4+u64(sub[24:])*prime64_2) * prime64_1
|
196 | 170 |
}
|
197 | 171 |
|
198 | |
h64 = ((v1 << 1) | (v1 >> 63)) +
|
199 | |
((v2 << 7) | (v2 >> 57)) +
|
200 | |
((v3 << 12) | (v3 >> 52)) +
|
201 | |
((v4 << 18) | (v4 >> 46))
|
|
172 |
h64 = rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
|
202 | 173 |
|
203 | 174 |
v1 *= prime64_2
|
204 | |
h64 ^= ((v1 << 31) | (v1 >> 33)) * prime64_1
|
205 | |
h64 = h64*prime64_1 + prime64_4
|
206 | |
|
207 | 175 |
v2 *= prime64_2
|
208 | |
h64 ^= ((v2 << 31) | (v2 >> 33)) * prime64_1
|
209 | |
h64 = h64*prime64_1 + prime64_4
|
210 | |
|
211 | 176 |
v3 *= prime64_2
|
212 | |
h64 ^= ((v3 << 31) | (v3 >> 33)) * prime64_1
|
213 | |
h64 = h64*prime64_1 + prime64_4
|
214 | |
|
215 | 177 |
v4 *= prime64_2
|
216 | |
h64 ^= ((v4 << 31) | (v4 >> 33)) * prime64_1
|
217 | |
h64 = h64*prime64_1 + prime64_4 + uint64(n)
|
|
178 |
|
|
179 |
h64 = (h64^(rol31(v1)*prime64_1))*prime64_1 + prime64_4
|
|
180 |
h64 = (h64^(rol31(v2)*prime64_1))*prime64_1 + prime64_4
|
|
181 |
h64 = (h64^(rol31(v3)*prime64_1))*prime64_1 + prime64_4
|
|
182 |
h64 = (h64^(rol31(v4)*prime64_1))*prime64_1 + prime64_4
|
|
183 |
|
|
184 |
h64 += uint64(n)
|
218 | 185 |
|
219 | 186 |
input = input[p:]
|
220 | 187 |
n -= p
|
|
224 | 191 |
|
225 | 192 |
p := 0
|
226 | 193 |
for n := n - 8; p <= n; p += 8 {
|
227 | |
p64 := (uint64(input[p+7])<<56 | uint64(input[p+6])<<48 | uint64(input[p+5])<<40 | uint64(input[p+4])<<32 | uint64(input[p+3])<<24 | uint64(input[p+2])<<16 | uint64(input[p+1])<<8 | uint64(input[p])) * prime64_2
|
228 | |
h64 ^= ((p64 << 31) | (p64 >> 33)) * prime64_1
|
229 | |
h64 = ((h64<<27)|(h64>>37))*prime64_1 + prime64_4
|
|
194 |
sub := input[p : p+8]
|
|
195 |
h64 ^= rol31(u64(sub)*prime64_2) * prime64_1
|
|
196 |
h64 = rol27(h64)*prime64_1 + prime64_4
|
230 | 197 |
}
|
231 | 198 |
if p+4 <= n {
|
232 | |
h64 ^= (uint64(input[p+3])<<24 | uint64(input[p+2])<<16 | uint64(input[p+1])<<8 | uint64(input[p])) * prime64_1
|
233 | |
h64 = ((h64<<23)|(h64>>41))*prime64_2 + prime64_3
|
|
199 |
sub := input[p : p+4]
|
|
200 |
h64 ^= uint64(u32(sub)) * prime64_1
|
|
201 |
h64 = rol23(h64)*prime64_2 + prime64_3
|
234 | 202 |
p += 4
|
235 | 203 |
}
|
236 | 204 |
for ; p < n; p++ {
|
237 | 205 |
h64 ^= uint64(input[p]) * prime64_5
|
238 | |
h64 = ((h64 << 11) | (h64 >> 53)) * prime64_1
|
|
206 |
h64 = rol11(h64) * prime64_1
|
239 | 207 |
}
|
240 | 208 |
|
241 | 209 |
h64 ^= h64 >> 33
|
|
246 | 214 |
|
247 | 215 |
return h64
|
248 | 216 |
}
|
|
217 |
|
|
218 |
func u64(buf []byte) uint64 {
|
|
219 |
// go compiler recognizes this pattern and optimizes it on little endian platforms
|
|
220 |
return uint64(buf[0]) | uint64(buf[1])<<8 | uint64(buf[2])<<16 | uint64(buf[3])<<24 | uint64(buf[4])<<32 | uint64(buf[5])<<40 | uint64(buf[6])<<48 | uint64(buf[7])<<56
|
|
221 |
}
|
|
222 |
|
|
223 |
func u32(buf []byte) uint32 {
|
|
224 |
return uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24
|
|
225 |
}
|
|
226 |
|
|
227 |
func rol1(u uint64) uint64 {
|
|
228 |
return u<<1 | u>>63
|
|
229 |
}
|
|
230 |
|
|
231 |
func rol7(u uint64) uint64 {
|
|
232 |
return u<<7 | u>>57
|
|
233 |
}
|
|
234 |
|
|
235 |
func rol11(u uint64) uint64 {
|
|
236 |
return u<<11 | u>>53
|
|
237 |
}
|
|
238 |
|
|
239 |
func rol12(u uint64) uint64 {
|
|
240 |
return u<<12 | u>>52
|
|
241 |
}
|
|
242 |
|
|
243 |
func rol18(u uint64) uint64 {
|
|
244 |
return u<<18 | u>>46
|
|
245 |
}
|
|
246 |
|
|
247 |
func rol23(u uint64) uint64 {
|
|
248 |
return u<<23 | u>>41
|
|
249 |
}
|
|
250 |
|
|
251 |
func rol27(u uint64) uint64 {
|
|
252 |
return u<<27 | u>>37
|
|
253 |
}
|
|
254 |
func rol31(u uint64) uint64 {
|
|
255 |
return u<<31 | u>>33
|
|
256 |
}
|