Debian Codegraph @

src/OVAL/probes/SEAP/MurmurHash3.c

raw symbols SCIP
1 //-----------------------------------------------------------------------------cxx . . $ `<file>/src/OVAL/probes/SEAP/MurmurHash3.c`/
2 // MurmurHash3 was written by Austin Appleby, and is placed in the public
3 // domain. The author hereby disclaims copyright to this source code.
4
5 // Note - The x86 and x64 versions do _not_ produce the same results, as the
6 // algorithms are optimized for their respective platforms. You can still
7 // compile and run any of them on any platform, but your performance with the
8 // non-native version will be less than optimal.
9
10 #include <config.h>cxx . . $ `<file>/build/config.h`/
11 #include "MurmurHash3.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/MurmurHash3.h`/
12
13 //-----------------------------------------------------------------------------
14 // Platform-specific functions and macros
15
16 // Microsoft Visual Studio
17
18 #if defined(_MSC_VER)
19
20 #define FORCE_INLINE __forceinline
21
22 #include <stdlib.h>
23
24 #define ROTL32(x,y) _rotl(x,y)
25 #define ROTL64(x,y) _rotl64(x,y)
26
27 #define BIG_CONSTANT(x) (x)
28
29 // Other compilers
30
31 #else // defined(_MSC_VER)
32
33 #define FORCE_INLINEcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:33:9`! __attribute__((always_inline)) inline
34
35 static inline uint32_tcxx . . $ uint32_t# rotl32cxx . . $ rotl32(70c8094990944fbe). ( uint32_tcxx . . $ uint32_t# x, int8_tcxx . . $ int8_t# r )
36 {
37 return (x << r) | (x >> (32 - r));
38 }
39
40 static inline uint64_tcxx . . $ uint64_t# rotl64cxx . . $ rotl64(9607e9ea9e8de9b6). ( uint64_tcxx . . $ uint64_t# x, int8_tcxx . . $ int8_t# r )
41 {
42 return (x << r) | (x >> (64 - r));
43 }
44
45 #define ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(x,y) rotl32(x,y)
46 #define ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(x,y) rotl64(x,y)
47
48 #define BIG_CONSTANTcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:48:9`!(x) (x##LLU)
49
50 #endif // !defined(_MSC_VER)
51
52 //-----------------------------------------------------------------------------
53 // Block read - if your platform needs to do endian-swapping or can only
54 // handle aligned reads, do the conversion here
55
56 FORCE_INLINEcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:33:9`! static uint32_tcxx . . $ uint32_t# getblock32cxx . . $ getblock32(7433825cc0143832). ( const uint32_tcxx . . $ uint32_t# * p, int i )
57 {
58 return p[i];
59 }
60
61 FORCE_INLINEcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:33:9`! static uint64_tcxx . . $ uint64_t# getblock64cxx . . $ getblock64(273705af1bed09b4). ( const uint64_tcxx . . $ uint64_t# * p, int i )
62 {
63 return p[i];
64 }
65
66 //-----------------------------------------------------------------------------
67 // Finalization mix - force all bits of a hash block to avalanche
68
69 FORCE_INLINEcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:33:9`! static uint32_tcxx . . $ uint32_t# fmix32cxx . . $ fmix32(2141b656ce2cc063). ( uint32_tcxx . . $ uint32_t# h )
70 {
71 h ^= h >> 16;
72 h *= 0x85ebca6b;
73 h ^= h >> 13;
74 h *= 0xc2b2ae35;
75 h ^= h >> 16;
76
77 return h;
78 }
79
80 //----------
81
82 FORCE_INLINEcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:33:9`! static uint64_tcxx . . $ uint64_t# fmix64cxx . . $ fmix64(ecdaa1632f49f591). ( uint64_tcxx . . $ uint64_t# k )
83 {
84 k ^= k >> 33;
85 k *= BIG_CONSTANTcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:48:9`!(0xff51afd7ed558ccd);
86 k ^= k >> 33;
87 k *= BIG_CONSTANTcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:48:9`!(0xc4ceb9fe1a85ec53);
88 k ^= k >> 33;
89
90 return k;
91 }
92
93 //-----------------------------------------------------------------------------
94
95 void MurmurHash3_x86_32cxx . . $ MurmurHash3_x86_32(a91a69c6ec3707ee). ( const void * key, int len,
96 uint32_tcxx . . $ uint32_t# seed, void * out )
97 {
98 const uint8_tcxx . . $ uint8_t# * data = (const uint8_tcxx . . $ uint8_t#*)key;
99 const int nblocks = len / 4;
100
101 uint32_tcxx . . $ uint32_t# h1 = seed;
102
103 uint32_tcxx . . $ uint32_t# c1 = 0xcc9e2d51;
104 uint32_tcxx . . $ uint32_t# c2 = 0x1b873593;
105
106 //----------
107 // body
108
109 const uint32_tcxx . . $ uint32_t# * blocks = (const uint32_tcxx . . $ uint32_t# *)(data + nblocks*4);
110
111 for(int i = -nblocks; i; i++)
112 {
113 uint32_tcxx . . $ uint32_t# k1 = getblock32cxx . . $ getblock32(7433825cc0143832).(blocks,i);
114
115 k1 *= c1;
116 k1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k1,15);
117 k1 *= c2;
118
119 h1 ^= k1;
120 h1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(h1,13);
121 h1 = h1*5+0xe6546b64;
122 }
123
124 //----------
125 // tail
126
127 const uint8_tcxx . . $ uint8_t# * tail = (const uint8_tcxx . . $ uint8_t#*)(data + nblocks*4);
128
129 uint32_tcxx . . $ uint32_t# k1 = 0;
130
131 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
132 #pragma GCC diagnostic push
133 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
134 #endif
135 switch(len & 3)
136 {
137 case 3: k1 ^= tail[2] << 16;
138 case 2: k1 ^= tail[1] << 8;
139 case 1: k1 ^= tail[0];
140 k1 *= c1; k1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k1,15); k1 *= c2; h1 ^= k1;
141 };
142 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
143 #pragma GCC diagnostic pop
144 #endif
145
146 //----------
147 // finalization
148
149 h1 ^= len;
150
151 h1 = fmix32cxx . . $ fmix32(2141b656ce2cc063).(h1);
152
153 *(uint32_tcxx . . $ uint32_t#*)out = h1;
154 }
155
156 //-----------------------------------------------------------------------------
157
158 void MurmurHash3_x86_128cxx . . $ MurmurHash3_x86_128(a91a69c6ec3707ee). ( const void * key, const int len,
159 uint32_tcxx . . $ uint32_t# seed, void * out )
160 {
161 const uint8_tcxx . . $ uint8_t# * data = (const uint8_tcxx . . $ uint8_t#*)key;
162 const int nblocks = len / 16;
163
164 uint32_tcxx . . $ uint32_t# h1 = seed;
165 uint32_tcxx . . $ uint32_t# h2 = seed;
166 uint32_tcxx . . $ uint32_t# h3 = seed;
167 uint32_tcxx . . $ uint32_t# h4 = seed;
168
169 uint32_tcxx . . $ uint32_t# c1 = 0x239b961b;
170 uint32_tcxx . . $ uint32_t# c2 = 0xab0e9789;
171 uint32_tcxx . . $ uint32_t# c3 = 0x38b34ae5;
172 uint32_tcxx . . $ uint32_t# c4 = 0xa1e38b93;
173
174 //----------
175 // body
176
177 const uint32_tcxx . . $ uint32_t# * blocks = (const uint32_tcxx . . $ uint32_t# *)(data + nblocks*16);
178
179 for(int i = -nblocks; i; i++)
180 {
181 uint32_tcxx . . $ uint32_t# k1 = getblock32cxx . . $ getblock32(7433825cc0143832).(blocks,i*4+0);
182 uint32_tcxx . . $ uint32_t# k2 = getblock32cxx . . $ getblock32(7433825cc0143832).(blocks,i*4+1);
183 uint32_tcxx . . $ uint32_t# k3 = getblock32cxx . . $ getblock32(7433825cc0143832).(blocks,i*4+2);
184 uint32_tcxx . . $ uint32_t# k4 = getblock32cxx . . $ getblock32(7433825cc0143832).(blocks,i*4+3);
185
186 k1 *= c1; k1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k1,15); k1 *= c2; h1 ^= k1;
187
188 h1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
189
190 k2 *= c2; k2 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k2,16); k2 *= c3; h2 ^= k2;
191
192 h2 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
193
194 k3 *= c3; k3 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k3,17); k3 *= c4; h3 ^= k3;
195
196 h3 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
197
198 k4 *= c4; k4 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k4,18); k4 *= c1; h4 ^= k4;
199
200 h4 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
201 }
202
203 //----------
204 // tail
205
206 const uint8_tcxx . . $ uint8_t# * tail = (const uint8_tcxx . . $ uint8_t#*)(data + nblocks*16);
207
208 uint32_tcxx . . $ uint32_t# k1 = 0;
209 uint32_tcxx . . $ uint32_t# k2 = 0;
210 uint32_tcxx . . $ uint32_t# k3 = 0;
211 uint32_tcxx . . $ uint32_t# k4 = 0;
212
213 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
214 #pragma GCC diagnostic push
215 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
216 #endif
217 switch(len & 15)
218 {
219 case 15: k4 ^= (uint32_tcxx . . $ uint32_t#)tail[14] << 16;
220 case 14: k4 ^= (uint32_tcxx . . $ uint32_t#)tail[13] << 8;
221 case 13: k4 ^= (uint32_tcxx . . $ uint32_t#)tail[12] << 0;
222 k4 *= c4; k4 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k4,18); k4 *= c1; h4 ^= k4;
223
224 case 12: k3 ^= (uint32_tcxx . . $ uint32_t#)tail[11] << 24;
225 case 11: k3 ^= (uint32_tcxx . . $ uint32_t#)tail[10] << 16;
226 case 10: k3 ^= (uint32_tcxx . . $ uint32_t#)tail[ 9] << 8;
227 case 9: k3 ^= (uint32_tcxx . . $ uint32_t#)tail[ 8] << 0;
228 k3 *= c3; k3 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k3,17); k3 *= c4; h3 ^= k3;
229
230 case 8: k2 ^= (uint32_tcxx . . $ uint32_t#)tail[ 7] << 24;
231 case 7: k2 ^= (uint32_tcxx . . $ uint32_t#)tail[ 6] << 16;
232 case 6: k2 ^= (uint32_tcxx . . $ uint32_t#)tail[ 5] << 8;
233 case 5: k2 ^= (uint32_tcxx . . $ uint32_t#)tail[ 4] << 0;
234 k2 *= c2; k2 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k2,16); k2 *= c3; h2 ^= k2;
235
236 case 4: k1 ^= (uint32_tcxx . . $ uint32_t#)tail[ 3] << 24;
237 case 3: k1 ^= (uint32_tcxx . . $ uint32_t#)tail[ 2] << 16;
238 case 2: k1 ^= (uint32_tcxx . . $ uint32_t#)tail[ 1] << 8;
239 case 1: k1 ^= (uint32_tcxx . . $ uint32_t#)tail[ 0] << 0;
240 k1 *= c1; k1 = ROTL32cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:45:9`!(k1,15); k1 *= c2; h1 ^= k1;
241 };
242 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
243 #pragma GCC diagnostic pop
244 #endif
245
246 //----------
247 // finalization
248
249 h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
250
251 h1 += h2; h1 += h3; h1 += h4;
252 h2 += h1; h3 += h1; h4 += h1;
253
254 h1 = fmix32cxx . . $ fmix32(2141b656ce2cc063).(h1);
255 h2 = fmix32cxx . . $ fmix32(2141b656ce2cc063).(h2);
256 h3 = fmix32cxx . . $ fmix32(2141b656ce2cc063).(h3);
257 h4 = fmix32cxx . . $ fmix32(2141b656ce2cc063).(h4);
258
259 h1 += h2; h1 += h3; h1 += h4;
260 h2 += h1; h3 += h1; h4 += h1;
261
262 ((uint32_tcxx . . $ uint32_t#*)out)[0] = h1;
263 ((uint32_tcxx . . $ uint32_t#*)out)[1] = h2;
264 ((uint32_tcxx . . $ uint32_t#*)out)[2] = h3;
265 ((uint32_tcxx . . $ uint32_t#*)out)[3] = h4;
266 }
267
268 //-----------------------------------------------------------------------------
269
270 void MurmurHash3_x64_128cxx . . $ MurmurHash3_x64_128(a91a69c6ec3707ee). ( const void * key, const int len,
271 const uint32_tcxx . . $ uint32_t# seed, void * out )
272 {
273 const uint8_tcxx . . $ uint8_t# * data = (const uint8_tcxx . . $ uint8_t#*)key;
274 const int nblocks = len / 16;
275
276 uint64_tcxx . . $ uint64_t# h1 = seed;
277 uint64_tcxx . . $ uint64_t# h2 = seed;
278
279 uint64_tcxx . . $ uint64_t# c1 = BIG_CONSTANTcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:48:9`!(0x87c37b91114253d5);
280 uint64_tcxx . . $ uint64_t# c2 = BIG_CONSTANTcxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:48:9`!(0x4cf5ad432745937f);
281
282 //----------
283 // body
284
285 const uint64_tcxx . . $ uint64_t# * blocks = (const uint64_tcxx . . $ uint64_t# *)(data);
286
287 for(int i = 0; i < nblocks; i++)
288 {
289 uint64_tcxx . . $ uint64_t# k1 = getblock64cxx . . $ getblock64(273705af1bed09b4).(blocks,i*2+0);
290 uint64_tcxx . . $ uint64_t# k2 = getblock64cxx . . $ getblock64(273705af1bed09b4).(blocks,i*2+1);
291
292 k1 *= c1; k1 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(k1,31); k1 *= c2; h1 ^= k1;
293
294 h1 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
295
296 k2 *= c2; k2 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(k2,33); k2 *= c1; h2 ^= k2;
297
298 h2 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
299 }
300
301 //----------
302 // tail
303
304 const uint8_tcxx . . $ uint8_t# * tail = (const uint8_tcxx . . $ uint8_t#*)(data + nblocks*16);
305
306 uint64_tcxx . . $ uint64_t# k1 = 0;
307 uint64_tcxx . . $ uint64_t# k2 = 0;
308
309 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
310 #pragma GCC diagnostic push
311 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
312 #endif
313 switch(len & 15)
314 {
315 case 15: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[14]) << 48;
316 case 14: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[13]) << 40;
317 case 13: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[12]) << 32;
318 case 12: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[11]) << 24;
319 case 11: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[10]) << 16;
320 case 10: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 9]) << 8;
321 case 9: k2 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 8]) << 0;
322 k2 *= c2; k2 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(k2,33); k2 *= c1; h2 ^= k2;
323
324 case 8: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 7]) << 56;
325 case 7: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 6]) << 48;
326 case 6: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 5]) << 40;
327 case 5: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 4]) << 32;
328 case 4: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 3]) << 24;
329 case 3: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 2]) << 16;
330 case 2: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 1]) << 8;
331 case 1: k1 ^= (uint64_tcxx . . $ uint64_t#)(tail[ 0]) << 0;
332 k1 *= c1; k1 = ROTL64cxx . . $ `src/OVAL/probes/SEAP/MurmurHash3.c:46:9`!(k1,31); k1 *= c2; h1 ^= k1;
333 };
334 #if __GNUC__cxx . . $ `<built-in>:8:9`! > 4 || (__GNUC__cxx . . $ `<built-in>:8:9`! == 4 && __GNUC_MINOR__cxx . . $ `<built-in>:9:9`! >= 6)
335 #pragma GCC diagnostic pop
336 #endif
337
338 //----------
339 // finalization
340
341 h1 ^= len; h2 ^= len;
342
343 h1 += h2;
344 h2 += h1;
345
346 h1 = fmix64cxx . . $ fmix64(ecdaa1632f49f591).(h1);
347 h2 = fmix64cxx . . $ fmix64(ecdaa1632f49f591).(h2);
348
349 h1 += h2;
350 h2 += h1;
351
352 ((uint64_tcxx . . $ uint64_t#*)out)[0] = h1;
353 ((uint64_tcxx . . $ uint64_t#*)out)[1] = h2;
354 }
355
356 //-----------------------------------------------------------------------------