1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | #ifndef __X86INTRIN_H |
25 | #error "Never use <ia32intrin.h> directly; include <x86intrin.h> instead." |
26 | #endif |
27 | |
28 | #ifndef __IA32INTRIN_H |
29 | #define __IA32INTRIN_H |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
44 | __bsfd(int __A) { |
45 | return __builtin_ctz(__A); |
46 | } |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
61 | __bsrd(int __A) { |
62 | return 31 - __builtin_clz(__A); |
63 | } |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
77 | __bswapd(int __A) { |
78 | return __builtin_bswap32(__A); |
79 | } |
80 | |
81 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
82 | _bswap(int __A) { |
83 | return __builtin_bswap32(__A); |
84 | } |
85 | |
86 | #define _bit_scan_forward(A) __bsfd((A)) |
87 | #define _bit_scan_reverse(A) __bsrd((A)) |
88 | |
89 | #ifdef __x86_64__ |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
103 | __bsfq(long long __A) { |
104 | return __builtin_ctzll(__A); |
105 | } |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
120 | __bsrq(long long __A) { |
121 | return 63 - __builtin_clzll(__A); |
122 | } |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | static __inline__ long long __attribute__((__always_inline__, __nodebug__)) |
136 | __bswapq(long long __A) { |
137 | return __builtin_bswap64(__A); |
138 | } |
139 | |
140 | #define _bswap64(A) __bswapq((A)) |
141 | #endif |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
156 | __popcntd(unsigned int __A) |
157 | { |
158 | return __builtin_popcount(__A); |
159 | } |
160 | |
161 | #define _popcnt32(A) __popcntd((A)) |
162 | |
163 | #ifdef __x86_64__ |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | static __inline__ long long __attribute__((__always_inline__, __nodebug__)) |
177 | __popcntq(unsigned long long __A) |
178 | { |
179 | return __builtin_popcountll(__A); |
180 | } |
181 | |
182 | #define _popcnt64(A) __popcntq((A)) |
183 | #endif |
184 | |
185 | #ifdef __x86_64__ |
186 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) |
187 | __readeflags(void) |
188 | { |
189 | return __builtin_ia32_readeflags_u64(); |
190 | } |
191 | |
192 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
193 | __writeeflags(unsigned long long __f) |
194 | { |
195 | __builtin_ia32_writeeflags_u64(__f); |
196 | } |
197 | |
198 | #else |
199 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
200 | __readeflags(void) |
201 | { |
202 | return __builtin_ia32_readeflags_u32(); |
203 | } |
204 | |
205 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
206 | __writeeflags(unsigned int __f) |
207 | { |
208 | __builtin_ia32_writeeflags_u32(__f); |
209 | } |
210 | #endif |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2"))) |
228 | __crc32b(unsigned int __C, unsigned char __D) |
229 | { |
230 | return __builtin_ia32_crc32qi(__C, __D); |
231 | } |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2"))) |
249 | __crc32w(unsigned int __C, unsigned short __D) |
250 | { |
251 | return __builtin_ia32_crc32hi(__C, __D); |
252 | } |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2"))) |
270 | __crc32d(unsigned int __C, unsigned int __D) |
271 | { |
272 | return __builtin_ia32_crc32si(__C, __D); |
273 | } |
274 | |
275 | #ifdef __x86_64__ |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("sse4.2"))) |
292 | __crc32q(unsigned long long __C, unsigned long long __D) |
293 | { |
294 | return __builtin_ia32_crc32di(__C, __D); |
295 | } |
296 | #endif |
297 | |
298 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) |
299 | __rdpmc(int __A) { |
300 | return __builtin_ia32_rdpmc(__A); |
301 | } |
302 | |
303 | |
304 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) |
305 | __rdtscp(unsigned int *__A) { |
306 | return __builtin_ia32_rdtscp(__A); |
307 | } |
308 | |
309 | #define _rdtsc() __rdtsc() |
310 | |
311 | #define _rdpmc(A) __rdpmc(A) |
312 | |
313 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
314 | _wbinvd(void) { |
315 | __builtin_ia32_wbinvd(); |
316 | } |
317 | |
318 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
319 | __rolb(unsigned char __X, int __C) { |
320 | return __builtin_rotateleft8(__X, __C); |
321 | } |
322 | |
323 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
324 | __rorb(unsigned char __X, int __C) { |
325 | return __builtin_rotateright8(__X, __C); |
326 | } |
327 | |
328 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
329 | __rolw(unsigned short __X, int __C) { |
330 | return __builtin_rotateleft16(__X, __C); |
331 | } |
332 | |
333 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
334 | __rorw(unsigned short __X, int __C) { |
335 | return __builtin_rotateright16(__X, __C); |
336 | } |
337 | |
338 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
339 | __rold(unsigned int __X, int __C) { |
340 | return __builtin_rotateleft32(__X, __C); |
341 | } |
342 | |
343 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
344 | __rord(unsigned int __X, int __C) { |
345 | return __builtin_rotateright32(__X, __C); |
346 | } |
347 | |
348 | #ifdef __x86_64__ |
349 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) |
350 | __rolq(unsigned long long __X, int __C) { |
351 | return __builtin_rotateleft64(__X, __C); |
352 | } |
353 | |
354 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) |
355 | __rorq(unsigned long long __X, int __C) { |
356 | return __builtin_rotateright64(__X, __C); |
357 | } |
358 | #endif |
359 | |
360 | #ifndef _MSC_VER |
361 | |
362 | |
363 | #ifdef __LP64__ |
364 | #define _lrotl(a,b) __rolq((a), (b)) |
365 | #define _lrotr(a,b) __rorq((a), (b)) |
366 | #else |
367 | #define _lrotl(a,b) __rold((a), (b)) |
368 | #define _lrotr(a,b) __rord((a), (b)) |
369 | #endif |
370 | #define _rotl(a,b) __rold((a), (b)) |
371 | #define _rotr(a,b) __rord((a), (b)) |
372 | #endif |
373 | |
374 | |
375 | #define _rotwl(a,b) __rolw((a), (b)) |
376 | #define _rotwr(a,b) __rorw((a), (b)) |
377 | |
378 | #endif |
379 | |