1 /*===---- immintrin.h - Intel intrinsics -----------------------------------===
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
7 *===-----------------------------------------------------------------------===
13 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__MMX__)
17 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE__)
18 #include <xmmintrin.h>
21 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE2__)
22 #include <emmintrin.h>
25 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE3__)
26 #include <pmmintrin.h>
29 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSSE3__)
30 #include <tmmintrin.h>
33 #if !defined(_MSC_VER) || __has_feature(modules) || \
34 (defined(__SSE4_2__) || defined(__SSE4_1__))
35 #include <smmintrin.h>
38 #if !defined(_MSC_VER) || __has_feature(modules) || \
39 (defined(__AES__) || defined(__PCLMUL__))
40 #include <wmmintrin.h>
43 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLFLUSHOPT__)
44 #include <clflushoptintrin.h>
47 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLWB__)
48 #include <clwbintrin.h>
51 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX__)
52 #include <avxintrin.h>
55 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX2__)
56 #include <avx2intrin.h>
59 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__F16C__)
60 #include <f16cintrin.h>
63 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__VPCLMULQDQ__)
64 #include <vpclmulqdqintrin.h>
67 /* No feature check desired due to internal checks */
68 #include <bmiintrin.h>
70 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__BMI2__)
71 #include <bmi2intrin.h>
74 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__LZCNT__)
75 #include <lzcntintrin.h>
78 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__POPCNT__)
79 #include <popcntintrin.h>
82 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FMA__)
83 #include <fmaintrin.h>
86 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512F__)
87 #include <avx512fintrin.h>
90 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VL__)
91 #include <avx512vlintrin.h>
94 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BW__)
95 #include <avx512bwintrin.h>
98 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BITALG__)
99 #include <avx512bitalgintrin.h>
102 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512CD__)
103 #include <avx512cdintrin.h>
106 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VPOPCNTDQ__)
107 #include <avx512vpopcntdqintrin.h>
110 #if !defined(_MSC_VER) || __has_feature(modules) || \
111 (defined(__AVX512VL__) && defined(__AVX512VPOPCNTDQ__))
112 #include <avx512vpopcntdqvlintrin.h>
115 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VNNI__)
116 #include <avx512vnniintrin.h>
119 #if !defined(_MSC_VER) || __has_feature(modules) || \
120 (defined(__AVX512VL__) && defined(__AVX512VNNI__))
121 #include <avx512vlvnniintrin.h>
124 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512DQ__)
125 #include <avx512dqintrin.h>
128 #if !defined(_MSC_VER) || __has_feature(modules) || \
129 (defined(__AVX512VL__) && defined(__AVX512BITALG__))
130 #include <avx512vlbitalgintrin.h>
133 #if !defined(_MSC_VER) || __has_feature(modules) || \
134 (defined(__AVX512VL__) && defined(__AVX512BW__))
135 #include <avx512vlbwintrin.h>
138 #if !defined(_MSC_VER) || __has_feature(modules) || \
139 (defined(__AVX512VL__) && defined(__AVX512CD__))
140 #include <avx512vlcdintrin.h>
143 #if !defined(_MSC_VER) || __has_feature(modules) || \
144 (defined(__AVX512VL__) && defined(__AVX512DQ__))
145 #include <avx512vldqintrin.h>
148 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512ER__)
149 #include <avx512erintrin.h>
152 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512IFMA__)
153 #include <avx512ifmaintrin.h>
156 #if !defined(_MSC_VER) || __has_feature(modules) || \
157 (defined(__AVX512IFMA__) && defined(__AVX512VL__))
158 #include <avx512ifmavlintrin.h>
161 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VBMI__)
162 #include <avx512vbmiintrin.h>
165 #if !defined(_MSC_VER) || __has_feature(modules) || \
166 (defined(__AVX512VBMI__) && defined(__AVX512VL__))
167 #include <avx512vbmivlintrin.h>
170 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VBMI2__)
171 #include <avx512vbmi2intrin.h>
174 #if !defined(_MSC_VER) || __has_feature(modules) || \
175 (defined(__AVX512VBMI2__) && defined(__AVX512VL__))
176 #include <avx512vlvbmi2intrin.h>
179 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512PF__)
180 #include <avx512pfintrin.h>
183 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BF16__)
184 #include <avx512bf16intrin.h>
187 #if !defined(_MSC_VER) || __has_feature(modules) || \
188 (defined(__AVX512VL__) && defined(__AVX512BF16__))
189 #include <avx512vlbf16intrin.h>
192 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__PKU__)
193 #include <pkuintrin.h>
196 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__VAES__)
197 #include <vaesintrin.h>
200 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__GFNI__)
201 #include <gfniintrin.h>
204 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDPID__)
205 /// Returns the value of the IA32_TSC_AUX MSR (0xc0000103).
207 /// \headerfile <immintrin.h>
209 /// This intrinsic corresponds to the <c> RDPID </c> instruction.
210 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("rdpid")))
212 return __builtin_ia32_rdpid();
216 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDRND__)
217 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
218 _rdrand16_step(unsigned short *__p)
220 return __builtin_ia32_rdrand16_step(__p);
223 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
224 _rdrand32_step(unsigned int *__p)
226 return __builtin_ia32_rdrand32_step(__p);
230 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
231 _rdrand64_step(unsigned long long *__p)
233 return __builtin_ia32_rdrand64_step(__p);
236 #endif /* __RDRND__ */
238 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
240 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
241 _readfsbase_u32(void)
243 return __builtin_ia32_rdfsbase32();
246 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
247 _readfsbase_u64(void)
249 return __builtin_ia32_rdfsbase64();
252 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
253 _readgsbase_u32(void)
255 return __builtin_ia32_rdgsbase32();
258 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
259 _readgsbase_u64(void)
261 return __builtin_ia32_rdgsbase64();
264 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
265 _writefsbase_u32(unsigned int __V)
267 __builtin_ia32_wrfsbase32(__V);
270 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
271 _writefsbase_u64(unsigned long long __V)
273 __builtin_ia32_wrfsbase64(__V);
276 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
277 _writegsbase_u32(unsigned int __V)
279 __builtin_ia32_wrgsbase32(__V);
282 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
283 _writegsbase_u64(unsigned long long __V)
285 __builtin_ia32_wrgsbase64(__V);
289 #endif /* __FSGSBASE__ */
291 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__MOVBE__)
293 /* The structs used below are to force the load/store to be unaligned. This
294 * is accomplished with the __packed__ attribute. The __may_alias__ prevents
295 * tbaa metadata from being generated based on the struct and the type of the
296 * field inside of it.
299 static __inline__ short __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
300 _loadbe_i16(void const * __P) {
303 } __attribute__((__packed__, __may_alias__));
304 return __builtin_bswap16(((struct __loadu_i16*)__P)->__v);
307 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
308 _storebe_i16(void * __P, short __D) {
309 struct __storeu_i16 {
311 } __attribute__((__packed__, __may_alias__));
312 ((struct __storeu_i16*)__P)->__v = __builtin_bswap16(__D);
315 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
316 _loadbe_i32(void const * __P) {
319 } __attribute__((__packed__, __may_alias__));
320 return __builtin_bswap32(((struct __loadu_i32*)__P)->__v);
323 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
324 _storebe_i32(void * __P, int __D) {
325 struct __storeu_i32 {
327 } __attribute__((__packed__, __may_alias__));
328 ((struct __storeu_i32*)__P)->__v = __builtin_bswap32(__D);
332 static __inline__ long long __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
333 _loadbe_i64(void const * __P) {
336 } __attribute__((__packed__, __may_alias__));
337 return __builtin_bswap64(((struct __loadu_i64*)__P)->__v);
340 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
341 _storebe_i64(void * __P, long long __D) {
342 struct __storeu_i64 {
344 } __attribute__((__packed__, __may_alias__));
345 ((struct __storeu_i64*)__P)->__v = __builtin_bswap64(__D);
350 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RTM__)
351 #include <rtmintrin.h>
352 #include <xtestintrin.h>
355 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHA__)
356 #include <shaintrin.h>
359 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FXSR__)
360 #include <fxsrintrin.h>
363 /* No feature check desired due to internal MSC_VER checks */
364 #include <xsaveintrin.h>
366 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEOPT__)
367 #include <xsaveoptintrin.h>
370 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEC__)
371 #include <xsavecintrin.h>
374 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVES__)
375 #include <xsavesintrin.h>
378 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHSTK__)
379 #include <cetintrin.h>
382 /* Some intrinsics inside adxintrin.h are available only on processors with ADX,
383 * whereas others are also available at all times. */
384 #include <adxintrin.h>
386 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDSEED__)
387 #include <rdseedintrin.h>
390 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__WBNOINVD__)
391 #include <wbnoinvdintrin.h>
394 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLDEMOTE__)
395 #include <cldemoteintrin.h>
398 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__WAITPKG__)
399 #include <waitpkgintrin.h>
402 #if !defined(_MSC_VER) || __has_feature(modules) || \
403 defined(__MOVDIRI__) || defined(__MOVDIR64B__)
404 #include <movdirintrin.h>
407 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__PCONFIG__)
408 #include <pconfigintrin.h>
411 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SGX__)
412 #include <sgxintrin.h>
415 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__PTWRITE__)
416 #include <ptwriteintrin.h>
419 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__INVPCID__)
420 #include <invpcidintrin.h>
423 #if !defined(_MSC_VER) || __has_feature(modules) || \
424 defined(__AVX512VP2INTERSECT__)
425 #include <avx512vp2intersectintrin.h>
428 #if !defined(_MSC_VER) || __has_feature(modules) || \
429 (defined(__AVX512VL__) && defined(__AVX512VP2INTERSECT__))
430 #include <avx512vlvp2intersectintrin.h>
433 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__ENQCMD__)
434 #include <enqcmdintrin.h>
437 #if defined(_MSC_VER) && __has_extension(gnu_asm)
438 /* Define the default attributes for these intrinsics */
439 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
443 /*----------------------------------------------------------------------------*\
444 |* Interlocked Exchange HLE
445 \*----------------------------------------------------------------------------*/
446 #if defined(__i386__) || defined(__x86_64__)
447 static __inline__ long __DEFAULT_FN_ATTRS
448 _InterlockedExchange_HLEAcquire(long volatile *_Target, long _Value) {
449 __asm__ __volatile__(".byte 0xf2 ; lock ; xchg %0, %1"
450 : "+r" (_Value), "+m" (*_Target) :: "memory");
453 static __inline__ long __DEFAULT_FN_ATTRS
454 _InterlockedExchange_HLERelease(long volatile *_Target, long _Value) {
455 __asm__ __volatile__(".byte 0xf3 ; lock ; xchg %0, %1"
456 : "+r" (_Value), "+m" (*_Target) :: "memory");
460 #if defined(__x86_64__)
461 static __inline__ __int64 __DEFAULT_FN_ATTRS
462 _InterlockedExchange64_HLEAcquire(__int64 volatile *_Target, __int64 _Value) {
463 __asm__ __volatile__(".byte 0xf2 ; lock ; xchg %0, %1"
464 : "+r" (_Value), "+m" (*_Target) :: "memory");
467 static __inline__ __int64 __DEFAULT_FN_ATTRS
468 _InterlockedExchange64_HLERelease(__int64 volatile *_Target, __int64 _Value) {
469 __asm__ __volatile__(".byte 0xf3 ; lock ; xchg %0, %1"
470 : "+r" (_Value), "+m" (*_Target) :: "memory");
474 /*----------------------------------------------------------------------------*\
475 |* Interlocked Compare Exchange HLE
476 \*----------------------------------------------------------------------------*/
477 #if defined(__i386__) || defined(__x86_64__)
478 static __inline__ long __DEFAULT_FN_ATTRS
479 _InterlockedCompareExchange_HLEAcquire(long volatile *_Destination,
480 long _Exchange, long _Comparand) {
481 __asm__ __volatile__(".byte 0xf2 ; lock ; cmpxchg %2, %1"
482 : "+a" (_Comparand), "+m" (*_Destination)
483 : "r" (_Exchange) : "memory");
486 static __inline__ long __DEFAULT_FN_ATTRS
487 _InterlockedCompareExchange_HLERelease(long volatile *_Destination,
488 long _Exchange, long _Comparand) {
489 __asm__ __volatile__(".byte 0xf3 ; lock ; cmpxchg %2, %1"
490 : "+a" (_Comparand), "+m" (*_Destination)
491 : "r" (_Exchange) : "memory");
495 #if defined(__x86_64__)
496 static __inline__ __int64 __DEFAULT_FN_ATTRS
497 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *_Destination,
498 __int64 _Exchange, __int64 _Comparand) {
499 __asm__ __volatile__(".byte 0xf2 ; lock ; cmpxchg %2, %1"
500 : "+a" (_Comparand), "+m" (*_Destination)
501 : "r" (_Exchange) : "memory");
504 static __inline__ __int64 __DEFAULT_FN_ATTRS
505 _InterlockedCompareExchange64_HLERelease(__int64 volatile *_Destination,
506 __int64 _Exchange, __int64 _Comparand) {
507 __asm__ __volatile__(".byte 0xf3 ; lock ; cmpxchg %2, %1"
508 : "+a" (_Comparand), "+m" (*_Destination)
509 : "r" (_Exchange) : "memory");
517 #undef __DEFAULT_FN_ATTRS
519 #endif /* defined(_MSC_VER) && __has_extension(gnu_asm) */
521 #endif /* __IMMINTRIN_H */