107 {
108 const uint8_t*
data = (
const uint8_t*)key;
109 const int32_t nblocks = len / 16;
110
111 uint32_t h1 = seed;
112 uint32_t h2 = seed;
113 uint32_t h3 = seed;
114 uint32_t h4 = seed;
115
116 const uint32_t c1 = 0x239b961b;
117 const uint32_t c2 = 0xab0e9789;
118 const uint32_t c3 = 0x38b34ae5;
119 const uint32_t c4 = 0xa1e38b93;
120
121
122
123 const uint8_t* blocks =
data + (ptrdiff_t)(nblocks * 16);
124
125 for (int i = -nblocks; i; i++) {
130
131 k1 *= c1;
133 k1 *= c2;
134 h1 ^= k1;
135
137 h1 += h2;
138 h1 = h1 * 5 + 0x561ccd1b;
139
140 k2 *= c2;
142 k2 *= c3;
143 h2 ^= k2;
144
146 h2 += h3;
147 h2 = h2 * 5 + 0x0bcaa747;
148
149 k3 *= c3;
151 k3 *= c4;
152 h3 ^= k3;
153
155 h3 += h4;
156 h3 = h3 * 5 + 0x96cd1c35;
157
158 k4 *= c4;
160 k4 *= c1;
161 h4 ^= k4;
162
164 h4 += h1;
165 h4 = h4 * 5 + 0x32ac3b17;
166 }
167
168
169
170 const uint8_t* tail = (
const uint8_t*)(
data + (ptrdiff_t)(nblocks * 16));
171
172 uint32_t k1 = 0;
173 uint32_t k2 = 0;
174 uint32_t k3 = 0;
175 uint32_t k4 = 0;
176
177 switch (len & 15) {
178 case 15:
179 k4 ^= ((uint32_t)tail[14]) << 16;
180 [[fallthrough]];
181 case 14:
182 k4 ^= ((uint32_t)tail[13]) << 8;
183 [[fallthrough]];
184 case 13:
185 k4 ^= ((uint32_t)tail[12]) << 0;
186 k4 *= c4;
188 k4 *= c1;
189 h4 ^= k4;
190
191 [[fallthrough]];
192 case 12:
193 k3 ^= ((uint32_t)tail[11]) << 24;
194 [[fallthrough]];
195 case 11:
196 k3 ^= ((uint32_t)tail[10]) << 16;
197 [[fallthrough]];
198 case 10:
199 k3 ^= ((uint32_t)tail[9]) << 8;
200 [[fallthrough]];
201 case 9:
202 k3 ^= ((uint32_t)tail[8]) << 0;
203 k3 *= c3;
205 k3 *= c4;
206 h3 ^= k3;
207
208 [[fallthrough]];
209 case 8:
210 k2 ^= ((uint32_t)tail[7]) << 24;
211 [[fallthrough]];
212 case 7:
213 k2 ^= ((uint32_t)tail[6]) << 16;
214 [[fallthrough]];
215 case 6:
216 k2 ^= ((uint32_t)tail[5]) << 8;
217 [[fallthrough]];
218 case 5:
219 k2 ^= ((uint32_t)tail[4]) << 0;
220 k2 *= c2;
222 k2 *= c3;
223 h2 ^= k2;
224
225 [[fallthrough]];
226 case 4:
227 k1 ^= ((uint32_t)tail[3]) << 24;
228 [[fallthrough]];
229 case 3:
230 k1 ^= ((uint32_t)tail[2]) << 16;
231 [[fallthrough]];
232 case 2:
233 k1 ^= ((uint32_t)tail[1]) << 8;
234 [[fallthrough]];
235 case 1:
236 k1 ^= ((uint32_t)tail[0]) << 0;
237 k1 *= c1;
239 k1 *= c2;
240 h1 ^= k1;
241 [[fallthrough]];
242 default:
243 };
244
245
246
247 h1 ^= (uint32_t)len;
248 h2 ^= (uint32_t)len;
249 h3 ^= (uint32_t)len;
250 h4 ^= (uint32_t)len;
251
252 h1 += h2;
253 h1 += h3;
254 h1 += h4;
255 h2 += h1;
256 h3 += h1;
257 h4 += h1;
258
263
264 h1 += h2;
265 h1 += h3;
266 h1 += h4;
267 h2 += h1;
268 h3 += h1;
269 h4 += h1;
270
271 ((uint32_t*)out)[0] = h1;
272 ((uint32_t*)out)[1] = h2;
273 ((uint32_t*)out)[2] = h3;
274 ((uint32_t*)out)[3] = h4;
275}
DC_INLINE uint32_t PRIV murmur_getblock32(const uint8_t *p, int32_t i)
DC_INLINE uint32_t PRIV murmur_fmix32(uint32_t h)
DC_INLINE uint32_t PRIV murmur_rotl32(uint32_t x, int8_t r)
MurmurHash3 implementation, copied (with love) from Austin Appleby's implementation.