blob: 1fda86ed26df57d4850dfe97936249c8cd9053ad [file] [log] [blame]
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +00001/*===---- immintrin.h - Intel intrinsics -----------------------------------===
2 *
Chandler Carruth4cf57432019-04-08 20:51:30 +00003 * 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
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +00006 *
7 *===-----------------------------------------------------------------------===
8 */
9
10#ifndef __IMMINTRIN_H
11#define __IMMINTRIN_H
12
Nico Weber379a1952016-05-16 18:14:07 +000013#if !defined(_MSC_VER) || __has_feature(modules) || defined(__MMX__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000014#include <mmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000015#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000016
Nico Weber379a1952016-05-16 18:14:07 +000017#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000018#include <xmmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000019#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000020
Nico Weber379a1952016-05-16 18:14:07 +000021#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE2__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000022#include <emmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000023#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000024
Nico Weber379a1952016-05-16 18:14:07 +000025#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE3__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000026#include <pmmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000027#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000028
Nico Weber379a1952016-05-16 18:14:07 +000029#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSSE3__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000030#include <tmmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000031#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000032
Nico Weber379a1952016-05-16 18:14:07 +000033#if !defined(_MSC_VER) || __has_feature(modules) || \
34 (defined(__SSE4_2__) || defined(__SSE4_1__))
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000035#include <smmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000036#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000037
Nico Weber379a1952016-05-16 18:14:07 +000038#if !defined(_MSC_VER) || __has_feature(modules) || \
39 (defined(__AES__) || defined(__PCLMUL__))
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000040#include <wmmintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000041#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000042
Michael Zuckermanb9206652016-07-05 15:56:03 +000043#if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLFLUSHOPT__)
44#include <clflushoptintrin.h>
45#endif
46
Craig Topper89cd7532017-10-12 18:57:15 +000047#if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLWB__)
48#include <clwbintrin.h>
49#endif
50
Nico Weber379a1952016-05-16 18:14:07 +000051#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX__)
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000052#include <avxintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000053#endif
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +000054
Nico Weber379a1952016-05-16 18:14:07 +000055#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX2__)
Craig Topperdec792e2011-12-19 05:04:33 +000056#include <avx2intrin.h>
Craig Topper1fceff92018-05-22 20:33:04 +000057#endif
Craig Topperdec792e2011-12-19 05:04:33 +000058
Craig Topper34c8c0d2018-05-22 18:54:19 +000059#if !defined(_MSC_VER) || __has_feature(modules) || defined(__F16C__)
60#include <f16cintrin.h>
Craig Topper1fceff92018-05-22 20:33:04 +000061#endif
Paul Robinson941bc912015-12-02 18:41:52 +000062
Coby Tayreecf96c872017-12-27 09:00:31 +000063#if !defined(_MSC_VER) || __has_feature(modules) || defined(__VPCLMULQDQ__)
64#include <vpclmulqdqintrin.h>
65#endif
66
Nico Weber379a1952016-05-16 18:14:07 +000067#if !defined(_MSC_VER) || __has_feature(modules) || defined(__BMI__)
Craig Topperf2855ad2011-12-25 06:25:37 +000068#include <bmiintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000069#endif
Craig Topperf2855ad2011-12-25 06:25:37 +000070
Nico Weber379a1952016-05-16 18:14:07 +000071#if !defined(_MSC_VER) || __has_feature(modules) || defined(__BMI2__)
Craig Topperc334dd62011-12-26 02:31:10 +000072#include <bmi2intrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000073#endif
Craig Topperc334dd62011-12-26 02:31:10 +000074
Nico Weber379a1952016-05-16 18:14:07 +000075#if !defined(_MSC_VER) || __has_feature(modules) || defined(__LZCNT__)
Craig Topperf2855ad2011-12-25 06:25:37 +000076#include <lzcntintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000077#endif
Craig Topperf2855ad2011-12-25 06:25:37 +000078
Craig Topper664af9b2018-05-23 18:32:58 +000079#if !defined(_MSC_VER) || __has_feature(modules) || defined(__POPCNT__)
80#include <popcntintrin.h>
81#endif
82
Nico Weber379a1952016-05-16 18:14:07 +000083#if !defined(_MSC_VER) || __has_feature(modules) || defined(__FMA__)
Craig Topper2b1eda32012-06-04 03:42:47 +000084#include <fmaintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000085#endif
Craig Topper2b1eda32012-06-04 03:42:47 +000086
Nico Weber379a1952016-05-16 18:14:07 +000087#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512F__)
Elena Demikhovskyfcc6df32014-07-22 11:31:39 +000088#include <avx512fintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000089#endif
Elena Demikhovskyfcc6df32014-07-22 11:31:39 +000090
Nico Weber379a1952016-05-16 18:14:07 +000091#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VL__)
Robert Khasanovb9f3a912014-10-08 17:18:13 +000092#include <avx512vlintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000093#endif
Robert Khasanovb9f3a912014-10-08 17:18:13 +000094
Nico Weber379a1952016-05-16 18:14:07 +000095#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BW__)
Robert Khasanovb9f3a912014-10-08 17:18:13 +000096#include <avx512bwintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +000097#endif
Robert Khasanovb9f3a912014-10-08 17:18:13 +000098
Coby Tayree22685762017-12-27 10:01:00 +000099#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BITALG__)
100#include <avx512bitalgintrin.h>
101#endif
102
Nico Weber379a1952016-05-16 18:14:07 +0000103#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512CD__)
Asaf Badouha45b7ca2015-06-29 12:51:53 +0000104#include <avx512cdintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000105#endif
Asaf Badouha45b7ca2015-06-29 12:51:53 +0000106
Oren Ben Simhon140c1fb2017-05-25 13:44:11 +0000107#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VPOPCNTDQ__)
108#include <avx512vpopcntdqintrin.h>
109#endif
110
Craig Topperb846d1f2017-12-16 06:02:31 +0000111#if !defined(_MSC_VER) || __has_feature(modules) || \
112 (defined(__AVX512VL__) && defined(__AVX512VPOPCNTDQ__))
113#include <avx512vpopcntdqvlintrin.h>
114#endif
115
Coby Tayree3d9c88c2017-12-27 10:37:51 +0000116#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VNNI__)
117#include <avx512vnniintrin.h>
118#endif
119
120#if !defined(_MSC_VER) || __has_feature(modules) || \
121 (defined(__AVX512VL__) && defined(__AVX512VNNI__))
122#include <avx512vlvnniintrin.h>
123#endif
124
Nico Weber379a1952016-05-16 18:14:07 +0000125#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512DQ__)
Elena Demikhovskye7d4c2e2015-04-30 09:24:29 +0000126#include <avx512dqintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000127#endif
Elena Demikhovskye7d4c2e2015-04-30 09:24:29 +0000128
Nico Weber379a1952016-05-16 18:14:07 +0000129#if !defined(_MSC_VER) || __has_feature(modules) || \
Coby Tayree22685762017-12-27 10:01:00 +0000130 (defined(__AVX512VL__) && defined(__AVX512BITALG__))
131#include <avx512vlbitalgintrin.h>
132#endif
133
134#if !defined(_MSC_VER) || __has_feature(modules) || \
Nico Weber379a1952016-05-16 18:14:07 +0000135 (defined(__AVX512VL__) && defined(__AVX512BW__))
Robert Khasanovb9f3a912014-10-08 17:18:13 +0000136#include <avx512vlbwintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000137#endif
Robert Khasanovb9f3a912014-10-08 17:18:13 +0000138
Nico Weber379a1952016-05-16 18:14:07 +0000139#if !defined(_MSC_VER) || __has_feature(modules) || \
140 (defined(__AVX512VL__) && defined(__AVX512CD__))
Michael Zuckerman8c2900f2016-04-27 11:43:14 +0000141#include <avx512vlcdintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000142#endif
Michael Zuckerman8c2900f2016-04-27 11:43:14 +0000143
Nico Weber379a1952016-05-16 18:14:07 +0000144#if !defined(_MSC_VER) || __has_feature(modules) || \
145 (defined(__AVX512VL__) && defined(__AVX512DQ__))
Elena Demikhovskye7d4c2e2015-04-30 09:24:29 +0000146#include <avx512vldqintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000147#endif
Elena Demikhovskye7d4c2e2015-04-30 09:24:29 +0000148
Nico Weber379a1952016-05-16 18:14:07 +0000149#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512ER__)
Elena Demikhovskyfcc6df32014-07-22 11:31:39 +0000150#include <avx512erintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000151#endif
Elena Demikhovskyfcc6df32014-07-22 11:31:39 +0000152
Nico Weber379a1952016-05-16 18:14:07 +0000153#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512IFMA__)
Michael Zuckerman0190c652016-03-07 09:55:55 +0000154#include <avx512ifmaintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000155#endif
Michael Zuckerman0190c652016-03-07 09:55:55 +0000156
Nico Weber379a1952016-05-16 18:14:07 +0000157#if !defined(_MSC_VER) || __has_feature(modules) || \
158 (defined(__AVX512IFMA__) && defined(__AVX512VL__))
Michael Zuckerman0190c652016-03-07 09:55:55 +0000159#include <avx512ifmavlintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000160#endif
Michael Zuckerman0190c652016-03-07 09:55:55 +0000161
Nico Weber379a1952016-05-16 18:14:07 +0000162#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VBMI__)
Michael Zuckerman9f338482016-03-07 17:04:11 +0000163#include <avx512vbmiintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000164#endif
Michael Zuckerman9f338482016-03-07 17:04:11 +0000165
Nico Weber379a1952016-05-16 18:14:07 +0000166#if !defined(_MSC_VER) || __has_feature(modules) || \
167 (defined(__AVX512VBMI__) && defined(__AVX512VL__))
Michael Zuckerman9f338482016-03-07 17:04:11 +0000168#include <avx512vbmivlintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000169#endif
Michael Zuckerman9f338482016-03-07 17:04:11 +0000170
Coby Tayreea09663a2017-12-27 11:25:07 +0000171#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VBMI2__)
172#include <avx512vbmi2intrin.h>
173#endif
174
175#if !defined(_MSC_VER) || __has_feature(modules) || \
176 (defined(__AVX512VBMI2__) && defined(__AVX512VL__))
177#include <avx512vlvbmi2intrin.h>
178#endif
179
Nico Weber379a1952016-05-16 18:14:07 +0000180#if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512PF__)
Michael Zuckerman4fa96af2016-04-21 12:47:27 +0000181#include <avx512pfintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000182#endif
Michael Zuckerman4fa96af2016-04-21 12:47:27 +0000183
Nico Weber379a1952016-05-16 18:14:07 +0000184#if !defined(_MSC_VER) || __has_feature(modules) || defined(__PKU__)
Asaf Badouha9d1e182015-12-31 14:14:07 +0000185#include <pkuintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000186#endif
Asaf Badouha9d1e182015-12-31 14:14:07 +0000187
Coby Tayreea1e5f0c2017-12-27 08:16:54 +0000188#if !defined(_MSC_VER) || __has_feature(modules) || defined(__VAES__)
189#include <vaesintrin.h>
190#endif
191
Coby Tayreef4811eb2017-12-27 08:37:47 +0000192#if !defined(_MSC_VER) || __has_feature(modules) || defined(__GFNI__)
193#include <gfniintrin.h>
194#endif
195
Craig Topper8cdb9492018-01-20 18:36:52 +0000196#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDPID__)
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000197/// Returns the value of the IA32_TSC_AUX MSR (0xc0000103).
Craig Topper8cdb9492018-01-20 18:36:52 +0000198///
199/// \headerfile <immintrin.h>
200///
201/// This intrinsic corresponds to the <c> RDPID </c> instruction.
202static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("rdpid")))
203_rdpid_u32(void) {
204 return __builtin_ia32_rdpid();
205}
206#endif // __RDPID__
207
Nico Weber379a1952016-05-16 18:14:07 +0000208#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDRND__)
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000209static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
Benjamin Kramera43b6992012-07-12 09:33:03 +0000210_rdrand16_step(unsigned short *__p)
211{
212 return __builtin_ia32_rdrand16_step(__p);
213}
214
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000215static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
Benjamin Kramera43b6992012-07-12 09:33:03 +0000216_rdrand32_step(unsigned int *__p)
217{
218 return __builtin_ia32_rdrand32_step(__p);
219}
220
Zvi Rackover064f0002017-07-10 07:13:56 +0000221#ifdef __x86_64__
222static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
223_rdrand64_step(unsigned long long *__p)
224{
225 return __builtin_ia32_rdrand64_step(__p);
226}
227#endif
228#endif /* __RDRND__ */
229
Nico Weber379a1952016-05-16 18:14:07 +0000230#if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
Craig Topper8c7f2512014-11-03 06:51:41 +0000231#ifdef __x86_64__
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000232static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000233_readfsbase_u32(void)
234{
235 return __builtin_ia32_rdfsbase32();
236}
237
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000238static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000239_readfsbase_u64(void)
240{
241 return __builtin_ia32_rdfsbase64();
242}
243
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000244static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000245_readgsbase_u32(void)
246{
247 return __builtin_ia32_rdgsbase32();
248}
249
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000250static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000251_readgsbase_u64(void)
252{
253 return __builtin_ia32_rdgsbase64();
254}
255
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000256static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000257_writefsbase_u32(unsigned int __V)
258{
Craig Topper819f2a22018-05-30 17:23:45 +0000259 __builtin_ia32_wrfsbase32(__V);
Craig Topper8c7f2512014-11-03 06:51:41 +0000260}
261
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000262static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000263_writefsbase_u64(unsigned long long __V)
264{
Craig Topper819f2a22018-05-30 17:23:45 +0000265 __builtin_ia32_wrfsbase64(__V);
Craig Topper8c7f2512014-11-03 06:51:41 +0000266}
267
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000268static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000269_writegsbase_u32(unsigned int __V)
270{
Craig Topper819f2a22018-05-30 17:23:45 +0000271 __builtin_ia32_wrgsbase32(__V);
Craig Topper8c7f2512014-11-03 06:51:41 +0000272}
273
Eric Christopher9fc7fb22015-06-17 07:09:32 +0000274static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
Craig Topper8c7f2512014-11-03 06:51:41 +0000275_writegsbase_u64(unsigned long long __V)
276{
Craig Topper819f2a22018-05-30 17:23:45 +0000277 __builtin_ia32_wrgsbase64(__V);
Craig Topper8c7f2512014-11-03 06:51:41 +0000278}
Michael Zuckermane54093f2016-06-01 12:21:00 +0000279
Craig Topper8c7f2512014-11-03 06:51:41 +0000280#endif
Nico Weber379a1952016-05-16 18:14:07 +0000281#endif /* __FSGSBASE__ */
Craig Topper8c7f2512014-11-03 06:51:41 +0000282
Craig Topper6ad92202018-09-28 17:09:51 +0000283#if !defined(_MSC_VER) || __has_feature(modules) || defined(__MOVBE__)
284
285/* The structs used below are to force the load/store to be unaligned. This
286 * is accomplished with the __packed__ attribute. The __may_alias__ prevents
287 * tbaa metadata from being generated based on the struct and the type of the
288 * field inside of it.
289 */
290
291static __inline__ short __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
292_loadbe_i16(void const * __P) {
293 struct __loadu_i16 {
294 short __v;
295 } __attribute__((__packed__, __may_alias__));
296 return __builtin_bswap16(((struct __loadu_i16*)__P)->__v);
297}
298
299static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
300_storebe_i16(void * __P, short __D) {
301 struct __storeu_i16 {
302 short __v;
303 } __attribute__((__packed__, __may_alias__));
304 ((struct __storeu_i16*)__P)->__v = __builtin_bswap16(__D);
305}
306
307static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
308_loadbe_i32(void const * __P) {
309 struct __loadu_i32 {
310 int __v;
311 } __attribute__((__packed__, __may_alias__));
312 return __builtin_bswap32(((struct __loadu_i32*)__P)->__v);
313}
314
315static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
316_storebe_i32(void * __P, int __D) {
317 struct __storeu_i32 {
318 int __v;
319 } __attribute__((__packed__, __may_alias__));
320 ((struct __storeu_i32*)__P)->__v = __builtin_bswap32(__D);
321}
322
323#ifdef __x86_64__
324static __inline__ long long __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
325_loadbe_i64(void const * __P) {
326 struct __loadu_i64 {
327 long long __v;
328 } __attribute__((__packed__, __may_alias__));
329 return __builtin_bswap64(((struct __loadu_i64*)__P)->__v);
330}
331
332static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
333_storebe_i64(void * __P, long long __D) {
334 struct __storeu_i64 {
335 long long __v;
336 } __attribute__((__packed__, __may_alias__));
337 ((struct __storeu_i64*)__P)->__v = __builtin_bswap64(__D);
338}
339#endif
340#endif /* __MOVBE */
341
Nico Weber379a1952016-05-16 18:14:07 +0000342#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RTM__)
Michael Liao625a8752012-11-10 05:17:46 +0000343#include <rtmintrin.h>
Eric Christopher3d920ee2015-06-17 18:42:07 +0000344#include <xtestintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000345#endif
Michael Liao4442f792013-03-29 05:14:06 +0000346
Nico Weber379a1952016-05-16 18:14:07 +0000347#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHA__)
Ben Langmuir6efe3a82013-09-19 14:00:22 +0000348#include <shaintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000349#endif
Ben Langmuir6efe3a82013-09-19 14:00:22 +0000350
Nico Weber379a1952016-05-16 18:14:07 +0000351#if !defined(_MSC_VER) || __has_feature(modules) || defined(__FXSR__)
Michael Kupersteina3c7b742015-06-30 09:45:38 +0000352#include <fxsrintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000353#endif
Michael Kupersteina3c7b742015-06-30 09:45:38 +0000354
Craig Topper93177972019-01-16 22:56:25 +0000355/* No feature check desired due to internal MSC_VER checks */
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000356#include <xsaveintrin.h>
357
Nico Weber379a1952016-05-16 18:14:07 +0000358#if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEOPT__)
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000359#include <xsaveoptintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000360#endif
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000361
Nico Weber379a1952016-05-16 18:14:07 +0000362#if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEC__)
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000363#include <xsavecintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000364#endif
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000365
Nico Weber379a1952016-05-16 18:14:07 +0000366#if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVES__)
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000367#include <xsavesintrin.h>
Nico Weber379a1952016-05-16 18:14:07 +0000368#endif
Amjad Aboud2b9b8a52015-10-13 12:29:35 +0000369
Oren Ben Simhonfec21ec2017-11-26 12:34:54 +0000370#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHSTK__)
371#include <cetintrin.h>
372#endif
373
Eric Christopher29b78092015-06-17 18:42:03 +0000374/* Some intrinsics inside adxintrin.h are available only on processors with ADX,
375 * whereas others are also available at all times. */
Robert Khasanov83c419b2014-09-19 10:17:06 +0000376#include <adxintrin.h>
377
Craig Topper664af9b2018-05-23 18:32:58 +0000378#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDSEED__)
379#include <rdseedintrin.h>
380#endif
381
Craig Topper664af9b2018-05-23 18:32:58 +0000382#if !defined(_MSC_VER) || __has_feature(modules) || defined(__WBNOINVD__)
383#include <wbnoinvdintrin.h>
384#endif
385
386#if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLDEMOTE__)
387#include <cldemoteintrin.h>
388#endif
389
390#if !defined(_MSC_VER) || __has_feature(modules) || defined(__WAITPKG__)
391#include <waitpkgintrin.h>
392#endif
393
394#if !defined(_MSC_VER) || __has_feature(modules) || \
395 defined(__MOVDIRI__) || defined(__MOVDIR64B__)
396#include <movdirintrin.h>
397#endif
398
399#if !defined(_MSC_VER) || __has_feature(modules) || defined(__PCONFIG__)
400#include <pconfigintrin.h>
401#endif
402
403#if !defined(_MSC_VER) || __has_feature(modules) || defined(__SGX__)
404#include <sgxintrin.h>
405#endif
406
407#if !defined(_MSC_VER) || __has_feature(modules) || defined(__PTWRITE__)
408#include <ptwriteintrin.h>
409#endif
410
Gabor Buella078bb992018-05-25 06:34:42 +0000411#if !defined(_MSC_VER) || __has_feature(modules) || defined(__INVPCID__)
412#include <invpcidintrin.h>
413#endif
414
Craig Topperb521dc32018-06-14 18:43:52 +0000415#ifdef _MSC_VER
416/* Define the default attributes for these intrinsics */
417#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
418#ifdef __cplusplus
419extern "C" {
420#endif
421/*----------------------------------------------------------------------------*\
422|* Interlocked Exchange HLE
423\*----------------------------------------------------------------------------*/
424#if defined(__i386__) || defined(__x86_64__)
425static __inline__ long __DEFAULT_FN_ATTRS
426_InterlockedExchange_HLEAcquire(long volatile *_Target, long _Value) {
427 __asm__ __volatile__(".byte 0xf2 ; lock ; xchg %0, %1"
428 : "+r" (_Value), "+m" (*_Target) :: "memory");
429 return _Value;
430}
431static __inline__ long __DEFAULT_FN_ATTRS
432_InterlockedExchange_HLERelease(long volatile *_Target, long _Value) {
433 __asm__ __volatile__(".byte 0xf3 ; lock ; xchg %0, %1"
434 : "+r" (_Value), "+m" (*_Target) :: "memory");
435 return _Value;
436}
437#endif
438#if defined(__x86_64__)
439static __inline__ __int64 __DEFAULT_FN_ATTRS
440_InterlockedExchange64_HLEAcquire(__int64 volatile *_Target, __int64 _Value) {
441 __asm__ __volatile__(".byte 0xf2 ; lock ; xchg %0, %1"
442 : "+r" (_Value), "+m" (*_Target) :: "memory");
443 return _Value;
444}
445static __inline__ __int64 __DEFAULT_FN_ATTRS
446_InterlockedExchange64_HLERelease(__int64 volatile *_Target, __int64 _Value) {
447 __asm__ __volatile__(".byte 0xf3 ; lock ; xchg %0, %1"
448 : "+r" (_Value), "+m" (*_Target) :: "memory");
449 return _Value;
450}
451#endif
452/*----------------------------------------------------------------------------*\
453|* Interlocked Compare Exchange HLE
454\*----------------------------------------------------------------------------*/
455#if defined(__i386__) || defined(__x86_64__)
456static __inline__ long __DEFAULT_FN_ATTRS
457_InterlockedCompareExchange_HLEAcquire(long volatile *_Destination,
458 long _Exchange, long _Comparand) {
459 __asm__ __volatile__(".byte 0xf2 ; lock ; cmpxchg %2, %1"
460 : "+a" (_Comparand), "+m" (*_Destination)
461 : "r" (_Exchange) : "memory");
462 return _Comparand;
463}
464static __inline__ long __DEFAULT_FN_ATTRS
465_InterlockedCompareExchange_HLERelease(long volatile *_Destination,
466 long _Exchange, long _Comparand) {
467 __asm__ __volatile__(".byte 0xf3 ; lock ; cmpxchg %2, %1"
468 : "+a" (_Comparand), "+m" (*_Destination)
469 : "r" (_Exchange) : "memory");
470 return _Comparand;
471}
472#endif
473#if defined(__x86_64__)
474static __inline__ __int64 __DEFAULT_FN_ATTRS
475_InterlockedCompareExchange64_HLEAcquire(__int64 volatile *_Destination,
476 __int64 _Exchange, __int64 _Comparand) {
477 __asm__ __volatile__(".byte 0xf2 ; lock ; cmpxchg %2, %1"
478 : "+a" (_Comparand), "+m" (*_Destination)
479 : "r" (_Exchange) : "memory");
480 return _Comparand;
481}
482static __inline__ __int64 __DEFAULT_FN_ATTRS
483_InterlockedCompareExchange64_HLERelease(__int64 volatile *_Destination,
484 __int64 _Exchange, __int64 _Comparand) {
485 __asm__ __volatile__(".byte 0xf3 ; lock ; cmpxchg %2, %1"
486 : "+a" (_Comparand), "+m" (*_Destination)
487 : "r" (_Exchange) : "memory");
488 return _Comparand;
489}
490#endif
491#ifdef __cplusplus
492}
493#endif
494
495#undef __DEFAULT_FN_ATTRS
496
497#endif /* _MSC_VER */
498
Benjamin Kramer65b9f7b2010-08-20 18:04:07 +0000499#endif /* __IMMINTRIN_H */