ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
ia32intrin.h
Go to the documentation of this file.
1 /* ===-------- ia32intrin.h ---------------------------------------------------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 #ifndef __X86INTRIN_H
11 #error "Never use <ia32intrin.h> directly; include <x86intrin.h> instead."
12 #endif
13 
14 #ifndef __IA32INTRIN_H
15 #define __IA32INTRIN_H
16 
29 static __inline__ int __attribute__((__always_inline__, __nodebug__))
30 __bsfd(int __A) {
31  return __builtin_ctz(__A);
32 }
33 
46 static __inline__ int __attribute__((__always_inline__, __nodebug__))
47 __bsrd(int __A) {
48  return 31 - __builtin_clz(__A);
49 }
50 
62 static __inline__ int __attribute__((__always_inline__, __nodebug__))
63 __bswapd(int __A) {
64  return __builtin_bswap32(__A);
65 }
66 
67 static __inline__ int __attribute__((__always_inline__, __nodebug__))
68 _bswap(int __A) {
69  return __builtin_bswap32(__A);
70 }
71 
72 #define _bit_scan_forward(A) __bsfd((A))
73 #define _bit_scan_reverse(A) __bsrd((A))
74 
75 #ifdef __x86_64__
88 static __inline__ int __attribute__((__always_inline__, __nodebug__))
89 __bsfq(long long __A) {
90  return __builtin_ctzll(__A);
91 }
92 
105 static __inline__ int __attribute__((__always_inline__, __nodebug__))
106 __bsrq(long long __A) {
107  return 63 - __builtin_clzll(__A);
108 }
109 
121 static __inline__ long long __attribute__((__always_inline__, __nodebug__))
122 __bswapq(long long __A) {
123  return __builtin_bswap64(__A);
124 }
125 
126 #define _bswap64(A) __bswapq((A))
127 #endif
128 
141 static __inline__ int __attribute__((__always_inline__, __nodebug__))
142 __popcntd(unsigned int __A)
143 {
144  return __builtin_popcount(__A);
145 }
146 
147 #define _popcnt32(A) __popcntd((A))
148 
149 #ifdef __x86_64__
162 static __inline__ long long __attribute__((__always_inline__, __nodebug__))
163 __popcntq(unsigned long long __A)
164 {
165  return __builtin_popcountll(__A);
166 }
167 
168 #define _popcnt64(A) __popcntq((A))
169 #endif /* __x86_64__ */
170 
171 #ifdef __x86_64__
172 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
173 __readeflags(void)
174 {
175  return __builtin_ia32_readeflags_u64();
176 }
177 
178 static __inline__ void __attribute__((__always_inline__, __nodebug__))
179 __writeeflags(unsigned long long __f)
180 {
181  __builtin_ia32_writeeflags_u64(__f);
182 }
183 
184 #else /* !__x86_64__ */
185 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
186 __readeflags(void)
187 {
188  return __builtin_ia32_readeflags_u32();
189 }
190 
191 static __inline__ void __attribute__((__always_inline__, __nodebug__))
192 __writeeflags(unsigned int __f)
193 {
194  __builtin_ia32_writeeflags_u32(__f);
195 }
196 #endif /* !__x86_64__ */
197 
208 static __inline__ unsigned int __attribute__((__always_inline__))
209 _castf32_u32(float __A) {
210  unsigned int D;
211  __builtin_memcpy(&D, &__A, sizeof(__A));
212  return D;
213 }
214 
225 static __inline__ unsigned long long __attribute__((__always_inline__))
226 _castf64_u64(double __A) {
227  unsigned long long D;
228  __builtin_memcpy(&D, &__A, sizeof(__A));
229  return D;
230 }
231 
242 static __inline__ float __attribute__((__always_inline__))
243 _castu32_f32(unsigned int __A) {
244  float D;
245  __builtin_memcpy(&D, &__A, sizeof(__A));
246  return D;
247 }
248 
259 static __inline__ double __attribute__((__always_inline__))
260 _castu64_f64(unsigned long long __A) {
261  double D;
262  __builtin_memcpy(&D, &__A, sizeof(__A));
263  return D;
264 }
265 
281 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
282 __crc32b(unsigned int __C, unsigned char __D)
283 {
284  return __builtin_ia32_crc32qi(__C, __D);
285 }
286 
302 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
303 __crc32w(unsigned int __C, unsigned short __D)
304 {
305  return __builtin_ia32_crc32hi(__C, __D);
306 }
307 
323 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
324 __crc32d(unsigned int __C, unsigned int __D)
325 {
326  return __builtin_ia32_crc32si(__C, __D);
327 }
328 
329 #ifdef __x86_64__
345 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
346 __crc32q(unsigned long long __C, unsigned long long __D)
347 {
348  return __builtin_ia32_crc32di(__C, __D);
349 }
350 #endif /* __x86_64__ */
351 
352 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
353 __rdpmc(int __A) {
354  return __builtin_ia32_rdpmc(__A);
355 }
356 
357 /* __rdtscp */
358 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
359 __rdtscp(unsigned int *__A) {
360  return __builtin_ia32_rdtscp(__A);
361 }
362 
363 #define _rdtsc() __rdtsc()
364 
365 #define _rdpmc(A) __rdpmc(A)
366 
367 static __inline__ void __attribute__((__always_inline__, __nodebug__))
368 _wbinvd(void) {
369  __builtin_ia32_wbinvd();
370 }
371 
372 static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
373 __rolb(unsigned char __X, int __C) {
374  return __builtin_rotateleft8(__X, __C);
375 }
376 
377 static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
378 __rorb(unsigned char __X, int __C) {
379  return __builtin_rotateright8(__X, __C);
380 }
381 
382 static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
383 __rolw(unsigned short __X, int __C) {
384  return __builtin_rotateleft16(__X, __C);
385 }
386 
387 static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
388 __rorw(unsigned short __X, int __C) {
389  return __builtin_rotateright16(__X, __C);
390 }
391 
392 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
393 __rold(unsigned int __X, int __C) {
394  return __builtin_rotateleft32(__X, __C);
395 }
396 
397 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
398 __rord(unsigned int __X, int __C) {
399  return __builtin_rotateright32(__X, __C);
400 }
401 
402 #ifdef __x86_64__
403 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
404 __rolq(unsigned long long __X, int __C) {
405  return __builtin_rotateleft64(__X, __C);
406 }
407 
408 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
409 __rorq(unsigned long long __X, int __C) {
410  return __builtin_rotateright64(__X, __C);
411 }
412 #endif /* __x86_64__ */
413 
414 #ifndef _MSC_VER
415 /* These are already provided as builtins for MSVC. */
416 /* Select the correct function based on the size of long. */
417 #ifdef __LP64__
418 #define _lrotl(a,b) __rolq((a), (b))
419 #define _lrotr(a,b) __rorq((a), (b))
420 #else
421 #define _lrotl(a,b) __rold((a), (b))
422 #define _lrotr(a,b) __rord((a), (b))
423 #endif
424 #define _rotl(a,b) __rold((a), (b))
425 #define _rotr(a,b) __rord((a), (b))
426 #endif // _MSC_VER
427 
428 /* These are not builtins so need to be provided in all modes. */
429 #define _rotwl(a,b) __rolw((a), (b))
430 #define _rotwr(a,b) __rorw((a), (b))
431 
432 #endif /* __IA32INTRIN_H */
static __inline__ int __attribute__((__always_inline__, __nodebug__)) __bsfd(int __A)
Find the first set bit starting from the lsb.
Definition: ia32intrin.h:29
static __inline__ unsigned int unsigned char __D
Definition: ia32intrin.h:283
static __inline__ unsigned char int __C
Definition: ia32intrin.h:373