Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 1 | /*===---- immintrin.h - Intel intrinsics -----------------------------------=== |
| 2 | * |
Chandler Carruth | 4cf5743 | 2019-04-08 20:51:30 +0000 | [diff] [blame] | 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 |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 6 | * |
| 7 | *===-----------------------------------------------------------------------=== |
| 8 | */ |
| 9 | |
| 10 | #ifndef __IMMINTRIN_H |
| 11 | #define __IMMINTRIN_H |
| 12 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 13 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__MMX__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 14 | #include <mmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 15 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 16 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 17 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 18 | #include <xmmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 19 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 20 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 21 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE2__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 22 | #include <emmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 23 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 24 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 25 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSE3__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 26 | #include <pmmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 27 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 28 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 29 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SSSE3__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 30 | #include <tmmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 31 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 32 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 33 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 34 | (defined(__SSE4_2__) || defined(__SSE4_1__)) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 35 | #include <smmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 36 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 37 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 38 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 39 | (defined(__AES__) || defined(__PCLMUL__)) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 40 | #include <wmmintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 41 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 42 | |
Michael Zuckerman | b920665 | 2016-07-05 15:56:03 +0000 | [diff] [blame] | 43 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLFLUSHOPT__) |
| 44 | #include <clflushoptintrin.h> |
| 45 | #endif |
| 46 | |
Craig Topper | 89cd753 | 2017-10-12 18:57:15 +0000 | [diff] [blame] | 47 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__CLWB__) |
| 48 | #include <clwbintrin.h> |
| 49 | #endif |
| 50 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 51 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX__) |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 52 | #include <avxintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 53 | #endif |
Benjamin Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 54 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 55 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX2__) |
Craig Topper | dec792e | 2011-12-19 05:04:33 +0000 | [diff] [blame] | 56 | #include <avx2intrin.h> |
Craig Topper | 1fceff9 | 2018-05-22 20:33:04 +0000 | [diff] [blame] | 57 | #endif |
Craig Topper | dec792e | 2011-12-19 05:04:33 +0000 | [diff] [blame] | 58 | |
Craig Topper | 34c8c0d | 2018-05-22 18:54:19 +0000 | [diff] [blame] | 59 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__F16C__) |
| 60 | #include <f16cintrin.h> |
Craig Topper | 1fceff9 | 2018-05-22 20:33:04 +0000 | [diff] [blame] | 61 | #endif |
Paul Robinson | 941bc91 | 2015-12-02 18:41:52 +0000 | [diff] [blame] | 62 | |
Coby Tayree | cf96c87 | 2017-12-27 09:00:31 +0000 | [diff] [blame] | 63 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__VPCLMULQDQ__) |
| 64 | #include <vpclmulqdqintrin.h> |
| 65 | #endif |
| 66 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 67 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__BMI__) |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 68 | #include <bmiintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 69 | #endif |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 70 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 71 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__BMI2__) |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 72 | #include <bmi2intrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 73 | #endif |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 74 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 75 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__LZCNT__) |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 76 | #include <lzcntintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 77 | #endif |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 78 | |
Craig Topper | 664af9b | 2018-05-23 18:32:58 +0000 | [diff] [blame] | 79 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__POPCNT__) |
| 80 | #include <popcntintrin.h> |
| 81 | #endif |
| 82 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 83 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FMA__) |
Craig Topper | 2b1eda3 | 2012-06-04 03:42:47 +0000 | [diff] [blame] | 84 | #include <fmaintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 85 | #endif |
Craig Topper | 2b1eda3 | 2012-06-04 03:42:47 +0000 | [diff] [blame] | 86 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 87 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512F__) |
Elena Demikhovsky | fcc6df3 | 2014-07-22 11:31:39 +0000 | [diff] [blame] | 88 | #include <avx512fintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 89 | #endif |
Elena Demikhovsky | fcc6df3 | 2014-07-22 11:31:39 +0000 | [diff] [blame] | 90 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 91 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VL__) |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 92 | #include <avx512vlintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 93 | #endif |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 94 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 95 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BW__) |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 96 | #include <avx512bwintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 97 | #endif |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 98 | |
Coby Tayree | 2268576 | 2017-12-27 10:01:00 +0000 | [diff] [blame] | 99 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512BITALG__) |
| 100 | #include <avx512bitalgintrin.h> |
| 101 | #endif |
| 102 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 103 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512CD__) |
Asaf Badouh | a45b7ca | 2015-06-29 12:51:53 +0000 | [diff] [blame] | 104 | #include <avx512cdintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 105 | #endif |
Asaf Badouh | a45b7ca | 2015-06-29 12:51:53 +0000 | [diff] [blame] | 106 | |
Oren Ben Simhon | 140c1fb | 2017-05-25 13:44:11 +0000 | [diff] [blame] | 107 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VPOPCNTDQ__) |
| 108 | #include <avx512vpopcntdqintrin.h> |
| 109 | #endif |
| 110 | |
Craig Topper | b846d1f | 2017-12-16 06:02:31 +0000 | [diff] [blame] | 111 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 112 | (defined(__AVX512VL__) && defined(__AVX512VPOPCNTDQ__)) |
| 113 | #include <avx512vpopcntdqvlintrin.h> |
| 114 | #endif |
| 115 | |
Coby Tayree | 3d9c88c | 2017-12-27 10:37:51 +0000 | [diff] [blame] | 116 | #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 Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 125 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512DQ__) |
Elena Demikhovsky | e7d4c2e | 2015-04-30 09:24:29 +0000 | [diff] [blame] | 126 | #include <avx512dqintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 127 | #endif |
Elena Demikhovsky | e7d4c2e | 2015-04-30 09:24:29 +0000 | [diff] [blame] | 128 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 129 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
Coby Tayree | 2268576 | 2017-12-27 10:01:00 +0000 | [diff] [blame] | 130 | (defined(__AVX512VL__) && defined(__AVX512BITALG__)) |
| 131 | #include <avx512vlbitalgintrin.h> |
| 132 | #endif |
| 133 | |
| 134 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 135 | (defined(__AVX512VL__) && defined(__AVX512BW__)) |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 136 | #include <avx512vlbwintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 137 | #endif |
Robert Khasanov | b9f3a91 | 2014-10-08 17:18:13 +0000 | [diff] [blame] | 138 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 139 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 140 | (defined(__AVX512VL__) && defined(__AVX512CD__)) |
Michael Zuckerman | 8c2900f | 2016-04-27 11:43:14 +0000 | [diff] [blame] | 141 | #include <avx512vlcdintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 142 | #endif |
Michael Zuckerman | 8c2900f | 2016-04-27 11:43:14 +0000 | [diff] [blame] | 143 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 144 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 145 | (defined(__AVX512VL__) && defined(__AVX512DQ__)) |
Elena Demikhovsky | e7d4c2e | 2015-04-30 09:24:29 +0000 | [diff] [blame] | 146 | #include <avx512vldqintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 147 | #endif |
Elena Demikhovsky | e7d4c2e | 2015-04-30 09:24:29 +0000 | [diff] [blame] | 148 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 149 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512ER__) |
Elena Demikhovsky | fcc6df3 | 2014-07-22 11:31:39 +0000 | [diff] [blame] | 150 | #include <avx512erintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 151 | #endif |
Elena Demikhovsky | fcc6df3 | 2014-07-22 11:31:39 +0000 | [diff] [blame] | 152 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 153 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512IFMA__) |
Michael Zuckerman | 0190c65 | 2016-03-07 09:55:55 +0000 | [diff] [blame] | 154 | #include <avx512ifmaintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 155 | #endif |
Michael Zuckerman | 0190c65 | 2016-03-07 09:55:55 +0000 | [diff] [blame] | 156 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 157 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 158 | (defined(__AVX512IFMA__) && defined(__AVX512VL__)) |
Michael Zuckerman | 0190c65 | 2016-03-07 09:55:55 +0000 | [diff] [blame] | 159 | #include <avx512ifmavlintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 160 | #endif |
Michael Zuckerman | 0190c65 | 2016-03-07 09:55:55 +0000 | [diff] [blame] | 161 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 162 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512VBMI__) |
Michael Zuckerman | 9f33848 | 2016-03-07 17:04:11 +0000 | [diff] [blame] | 163 | #include <avx512vbmiintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 164 | #endif |
Michael Zuckerman | 9f33848 | 2016-03-07 17:04:11 +0000 | [diff] [blame] | 165 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 166 | #if !defined(_MSC_VER) || __has_feature(modules) || \ |
| 167 | (defined(__AVX512VBMI__) && defined(__AVX512VL__)) |
Michael Zuckerman | 9f33848 | 2016-03-07 17:04:11 +0000 | [diff] [blame] | 168 | #include <avx512vbmivlintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 169 | #endif |
Michael Zuckerman | 9f33848 | 2016-03-07 17:04:11 +0000 | [diff] [blame] | 170 | |
Coby Tayree | a09663a | 2017-12-27 11:25:07 +0000 | [diff] [blame] | 171 | #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 Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 180 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__AVX512PF__) |
Michael Zuckerman | 4fa96af | 2016-04-21 12:47:27 +0000 | [diff] [blame] | 181 | #include <avx512pfintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 182 | #endif |
Michael Zuckerman | 4fa96af | 2016-04-21 12:47:27 +0000 | [diff] [blame] | 183 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 184 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__PKU__) |
Asaf Badouh | a9d1e18 | 2015-12-31 14:14:07 +0000 | [diff] [blame] | 185 | #include <pkuintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 186 | #endif |
Asaf Badouh | a9d1e18 | 2015-12-31 14:14:07 +0000 | [diff] [blame] | 187 | |
Coby Tayree | a1e5f0c | 2017-12-27 08:16:54 +0000 | [diff] [blame] | 188 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__VAES__) |
| 189 | #include <vaesintrin.h> |
| 190 | #endif |
| 191 | |
Coby Tayree | f4811eb | 2017-12-27 08:37:47 +0000 | [diff] [blame] | 192 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__GFNI__) |
| 193 | #include <gfniintrin.h> |
| 194 | #endif |
| 195 | |
Craig Topper | 8cdb949 | 2018-01-20 18:36:52 +0000 | [diff] [blame] | 196 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDPID__) |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 197 | /// Returns the value of the IA32_TSC_AUX MSR (0xc0000103). |
Craig Topper | 8cdb949 | 2018-01-20 18:36:52 +0000 | [diff] [blame] | 198 | /// |
| 199 | /// \headerfile <immintrin.h> |
| 200 | /// |
| 201 | /// This intrinsic corresponds to the <c> RDPID </c> instruction. |
| 202 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("rdpid"))) |
| 203 | _rdpid_u32(void) { |
| 204 | return __builtin_ia32_rdpid(); |
| 205 | } |
| 206 | #endif // __RDPID__ |
| 207 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 208 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDRND__) |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 209 | static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd"))) |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 210 | _rdrand16_step(unsigned short *__p) |
| 211 | { |
| 212 | return __builtin_ia32_rdrand16_step(__p); |
| 213 | } |
| 214 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 215 | static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd"))) |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 216 | _rdrand32_step(unsigned int *__p) |
| 217 | { |
| 218 | return __builtin_ia32_rdrand32_step(__p); |
| 219 | } |
| 220 | |
Zvi Rackover | 064f000 | 2017-07-10 07:13:56 +0000 | [diff] [blame] | 221 | #ifdef __x86_64__ |
| 222 | static __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 Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 230 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 231 | #ifdef __x86_64__ |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 232 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 233 | _readfsbase_u32(void) |
| 234 | { |
| 235 | return __builtin_ia32_rdfsbase32(); |
| 236 | } |
| 237 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 238 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 239 | _readfsbase_u64(void) |
| 240 | { |
| 241 | return __builtin_ia32_rdfsbase64(); |
| 242 | } |
| 243 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 244 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 245 | _readgsbase_u32(void) |
| 246 | { |
| 247 | return __builtin_ia32_rdgsbase32(); |
| 248 | } |
| 249 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 250 | static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 251 | _readgsbase_u64(void) |
| 252 | { |
| 253 | return __builtin_ia32_rdgsbase64(); |
| 254 | } |
| 255 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 256 | static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 257 | _writefsbase_u32(unsigned int __V) |
| 258 | { |
Craig Topper | 819f2a2 | 2018-05-30 17:23:45 +0000 | [diff] [blame] | 259 | __builtin_ia32_wrfsbase32(__V); |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 262 | static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 263 | _writefsbase_u64(unsigned long long __V) |
| 264 | { |
Craig Topper | 819f2a2 | 2018-05-30 17:23:45 +0000 | [diff] [blame] | 265 | __builtin_ia32_wrfsbase64(__V); |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 268 | static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 269 | _writegsbase_u32(unsigned int __V) |
| 270 | { |
Craig Topper | 819f2a2 | 2018-05-30 17:23:45 +0000 | [diff] [blame] | 271 | __builtin_ia32_wrgsbase32(__V); |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Eric Christopher | 9fc7fb2 | 2015-06-17 07:09:32 +0000 | [diff] [blame] | 274 | static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase"))) |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 275 | _writegsbase_u64(unsigned long long __V) |
| 276 | { |
Craig Topper | 819f2a2 | 2018-05-30 17:23:45 +0000 | [diff] [blame] | 277 | __builtin_ia32_wrgsbase64(__V); |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 278 | } |
Michael Zuckerman | e54093f | 2016-06-01 12:21:00 +0000 | [diff] [blame] | 279 | |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 280 | #endif |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 281 | #endif /* __FSGSBASE__ */ |
Craig Topper | 8c7f251 | 2014-11-03 06:51:41 +0000 | [diff] [blame] | 282 | |
Craig Topper | 6ad9220 | 2018-09-28 17:09:51 +0000 | [diff] [blame] | 283 | #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 | |
| 291 | static __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 | |
| 299 | static __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 | |
| 307 | static __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 | |
| 315 | static __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__ |
| 324 | static __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 | |
| 332 | static __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 Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 342 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RTM__) |
Michael Liao | 625a875 | 2012-11-10 05:17:46 +0000 | [diff] [blame] | 343 | #include <rtmintrin.h> |
Eric Christopher | 3d920ee | 2015-06-17 18:42:07 +0000 | [diff] [blame] | 344 | #include <xtestintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 345 | #endif |
Michael Liao | 4442f79 | 2013-03-29 05:14:06 +0000 | [diff] [blame] | 346 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 347 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHA__) |
Ben Langmuir | 6efe3a8 | 2013-09-19 14:00:22 +0000 | [diff] [blame] | 348 | #include <shaintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 349 | #endif |
Ben Langmuir | 6efe3a8 | 2013-09-19 14:00:22 +0000 | [diff] [blame] | 350 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 351 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FXSR__) |
Michael Kuperstein | a3c7b74 | 2015-06-30 09:45:38 +0000 | [diff] [blame] | 352 | #include <fxsrintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 353 | #endif |
Michael Kuperstein | a3c7b74 | 2015-06-30 09:45:38 +0000 | [diff] [blame] | 354 | |
Craig Topper | 9317797 | 2019-01-16 22:56:25 +0000 | [diff] [blame] | 355 | /* No feature check desired due to internal MSC_VER checks */ |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 356 | #include <xsaveintrin.h> |
| 357 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 358 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEOPT__) |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 359 | #include <xsaveoptintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 360 | #endif |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 361 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 362 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEC__) |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 363 | #include <xsavecintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 364 | #endif |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 365 | |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 366 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVES__) |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 367 | #include <xsavesintrin.h> |
Nico Weber | 379a195 | 2016-05-16 18:14:07 +0000 | [diff] [blame] | 368 | #endif |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 369 | |
Oren Ben Simhon | fec21ec | 2017-11-26 12:34:54 +0000 | [diff] [blame] | 370 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__SHSTK__) |
| 371 | #include <cetintrin.h> |
| 372 | #endif |
| 373 | |
Eric Christopher | 29b7809 | 2015-06-17 18:42:03 +0000 | [diff] [blame] | 374 | /* Some intrinsics inside adxintrin.h are available only on processors with ADX, |
| 375 | * whereas others are also available at all times. */ |
Robert Khasanov | 83c419b | 2014-09-19 10:17:06 +0000 | [diff] [blame] | 376 | #include <adxintrin.h> |
| 377 | |
Craig Topper | 664af9b | 2018-05-23 18:32:58 +0000 | [diff] [blame] | 378 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDSEED__) |
| 379 | #include <rdseedintrin.h> |
| 380 | #endif |
| 381 | |
Craig Topper | 664af9b | 2018-05-23 18:32:58 +0000 | [diff] [blame] | 382 | #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 Buella | 078bb99 | 2018-05-25 06:34:42 +0000 | [diff] [blame] | 411 | #if !defined(_MSC_VER) || __has_feature(modules) || defined(__INVPCID__) |
| 412 | #include <invpcidintrin.h> |
| 413 | #endif |
| 414 | |
Craig Topper | b521dc3 | 2018-06-14 18:43:52 +0000 | [diff] [blame] | 415 | #ifdef _MSC_VER |
| 416 | /* Define the default attributes for these intrinsics */ |
| 417 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) |
| 418 | #ifdef __cplusplus |
| 419 | extern "C" { |
| 420 | #endif |
| 421 | /*----------------------------------------------------------------------------*\ |
| 422 | |* Interlocked Exchange HLE |
| 423 | \*----------------------------------------------------------------------------*/ |
| 424 | #if defined(__i386__) || defined(__x86_64__) |
| 425 | static __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 | } |
| 431 | static __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__) |
| 439 | static __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 | } |
| 445 | static __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__) |
| 456 | static __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 | } |
| 464 | static __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__) |
| 474 | static __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 | } |
| 482 | static __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 Kramer | 65b9f7b | 2010-08-20 18:04:07 +0000 | [diff] [blame] | 499 | #endif /* __IMMINTRIN_H */ |