Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 1 | /*===---- bmiintrin.h - BMI intrinsics -------------------------------------=== |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | * THE SOFTWARE. |
| 20 | * |
| 21 | *===-----------------------------------------------------------------------=== |
| 22 | */ |
| 23 | |
| 24 | #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H |
| 25 | #error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead." |
| 26 | #endif |
| 27 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 28 | #ifndef __BMIINTRIN_H |
| 29 | #define __BMIINTRIN_H |
| 30 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 31 | #define _tzcnt_u16(a) (__tzcnt_u16((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 32 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 33 | #define _andn_u32(a, b) (__andn_u32((a), (b))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 34 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 35 | /* _bextr_u32 != __bextr_u32 */ |
| 36 | #define _blsi_u32(a) (__blsi_u32((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 37 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 38 | #define _blsmsk_u32(a) (__blsmsk_u32((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 39 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 40 | #define _blsr_u32(a) (__blsr_u32((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 41 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 42 | #define _tzcnt_u32(a) (__tzcnt_u32((a))) |
| 43 | |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 44 | /* Define the default attributes for the functions in this file. */ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 45 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi"))) |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 46 | |
Hans Wennborg | 1acf955 | 2015-11-17 18:46:48 +0000 | [diff] [blame] | 47 | /* Allow using the tzcnt intrinsics even for non-BMI targets. Since the TZCNT |
| 48 | instruction behaves as BSF on non-BMI targets, there is code that expects |
| 49 | to use it as a potentially faster version of BSF. */ |
| 50 | #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) |
| 51 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 52 | /// Counts the number of trailing zero bits in the operand. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 53 | /// |
| 54 | /// \headerfile <x86intrin.h> |
| 55 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 56 | /// This intrinsic corresponds to the <c> TZCNT </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 57 | /// |
| 58 | /// \param __X |
| 59 | /// An unsigned 16-bit integer whose trailing zeros are to be counted. |
| 60 | /// \returns An unsigned 16-bit integer containing the number of trailing zero |
| 61 | /// bits in the operand. |
Hans Wennborg | 1acf955 | 2015-11-17 18:46:48 +0000 | [diff] [blame] | 62 | static __inline__ unsigned short __RELAXED_FN_ATTRS |
Craig Topper | 6490bdc | 2012-07-02 06:52:51 +0000 | [diff] [blame] | 63 | __tzcnt_u16(unsigned short __X) |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 64 | { |
Craig Topper | a52e0d7 | 2014-11-01 22:50:54 +0000 | [diff] [blame] | 65 | return __X ? __builtin_ctzs(__X) : 16; |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 68 | /// Performs a bitwise AND of the second operand with the one's |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 69 | /// complement of the first operand. |
| 70 | /// |
| 71 | /// \headerfile <x86intrin.h> |
| 72 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 73 | /// This intrinsic corresponds to the <c> ANDN </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 74 | /// |
| 75 | /// \param __X |
| 76 | /// An unsigned integer containing one of the operands. |
| 77 | /// \param __Y |
| 78 | /// An unsigned integer containing one of the operands. |
| 79 | /// \returns An unsigned integer containing the bitwise AND of the second |
| 80 | /// operand with the one's complement of the first operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 81 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 82 | __andn_u32(unsigned int __X, unsigned int __Y) |
| 83 | { |
| 84 | return ~__X & __Y; |
| 85 | } |
| 86 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 87 | /* AMD-specified, double-leading-underscore version of BEXTR */ |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 88 | /// Extracts the specified bits from the first operand and returns them |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 89 | /// in the least significant bits of the result. |
| 90 | /// |
| 91 | /// \headerfile <x86intrin.h> |
| 92 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 93 | /// This intrinsic corresponds to the <c> BEXTR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 94 | /// |
| 95 | /// \param __X |
| 96 | /// An unsigned integer whose bits are to be extracted. |
| 97 | /// \param __Y |
| 98 | /// An unsigned integer used to specify which bits are extracted. Bits [7:0] |
| 99 | /// specify the index of the least significant bit. Bits [15:8] specify the |
| 100 | /// number of bits to be extracted. |
| 101 | /// \returns An unsigned integer whose least significant bits contain the |
| 102 | /// extracted bits. |
Ekaterina Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame^] | 103 | /// \see _bextr_u32 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 104 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 105 | __bextr_u32(unsigned int __X, unsigned int __Y) |
| 106 | { |
| 107 | return __builtin_ia32_bextr_u32(__X, __Y); |
| 108 | } |
| 109 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 110 | /* Intel-specified, single-leading-underscore version of BEXTR */ |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 111 | /// Extracts the specified bits from the first operand and returns them |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 112 | /// in the least significant bits of the result. |
| 113 | /// |
| 114 | /// \headerfile <x86intrin.h> |
| 115 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 116 | /// This intrinsic corresponds to the <c> BEXTR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 117 | /// |
| 118 | /// \param __X |
| 119 | /// An unsigned integer whose bits are to be extracted. |
| 120 | /// \param __Y |
| 121 | /// An unsigned integer used to specify the index of the least significant |
| 122 | /// bit for the bits to be extracted. Bits [7:0] specify the index. |
| 123 | /// \param __Z |
| 124 | /// An unsigned integer used to specify the number of bits to be extracted. |
| 125 | /// Bits [7:0] specify the number of bits. |
| 126 | /// \returns An unsigned integer whose least significant bits contain the |
| 127 | /// extracted bits. |
Ekaterina Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame^] | 128 | /// \see __bextr_u32 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 129 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 130 | _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z) |
| 131 | { |
| 132 | return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); |
| 133 | } |
| 134 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 135 | /// Clears all bits in the source except for the least significant bit |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 136 | /// containing a value of 1 and returns the result. |
| 137 | /// |
| 138 | /// \headerfile <x86intrin.h> |
| 139 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 140 | /// This intrinsic corresponds to the <c> BLSI </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 141 | /// |
| 142 | /// \param __X |
| 143 | /// An unsigned integer whose bits are to be cleared. |
| 144 | /// \returns An unsigned integer containing the result of clearing the bits from |
| 145 | /// the source operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 146 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 147 | __blsi_u32(unsigned int __X) |
| 148 | { |
| 149 | return __X & -__X; |
| 150 | } |
| 151 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 152 | /// Creates a mask whose bits are set to 1, using bit 0 up to and |
Ekaterina Romanova | cb3603a | 2017-06-06 22:58:01 +0000 | [diff] [blame] | 153 | /// including the least significant bit that is set to 1 in the source |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 154 | /// operand and returns the result. |
| 155 | /// |
| 156 | /// \headerfile <x86intrin.h> |
| 157 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 158 | /// This intrinsic corresponds to the <c> BLSMSK </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 159 | /// |
| 160 | /// \param __X |
| 161 | /// An unsigned integer used to create the mask. |
| 162 | /// \returns An unsigned integer containing the newly created mask. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 163 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 164 | __blsmsk_u32(unsigned int __X) |
| 165 | { |
| 166 | return __X ^ (__X - 1); |
| 167 | } |
| 168 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 169 | /// Clears the least significant bit that is set to 1 in the source |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 170 | /// operand and returns the result. |
| 171 | /// |
| 172 | /// \headerfile <x86intrin.h> |
| 173 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 174 | /// This intrinsic corresponds to the <c> BLSR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 175 | /// |
| 176 | /// \param __X |
| 177 | /// An unsigned integer containing the operand to be cleared. |
| 178 | /// \returns An unsigned integer containing the result of clearing the source |
| 179 | /// operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 180 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 181 | __blsr_u32(unsigned int __X) |
| 182 | { |
| 183 | return __X & (__X - 1); |
| 184 | } |
| 185 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 186 | /// Counts the number of trailing zero bits in the operand. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 187 | /// |
| 188 | /// \headerfile <x86intrin.h> |
| 189 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 190 | /// This intrinsic corresponds to the <c> TZCNT </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 191 | /// |
| 192 | /// \param __X |
| 193 | /// An unsigned 32-bit integer whose trailing zeros are to be counted. |
| 194 | /// \returns An unsigned 32-bit integer containing the number of trailing zero |
| 195 | /// bits in the operand. |
Hans Wennborg | 1acf955 | 2015-11-17 18:46:48 +0000 | [diff] [blame] | 196 | static __inline__ unsigned int __RELAXED_FN_ATTRS |
Craig Topper | 6490bdc | 2012-07-02 06:52:51 +0000 | [diff] [blame] | 197 | __tzcnt_u32(unsigned int __X) |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 198 | { |
Craig Topper | a52e0d7 | 2014-11-01 22:50:54 +0000 | [diff] [blame] | 199 | return __X ? __builtin_ctz(__X) : 32; |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 202 | /// Counts the number of trailing zero bits in the operand. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 203 | /// |
| 204 | /// \headerfile <x86intrin.h> |
| 205 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 206 | /// This intrinsic corresponds to the <c> TZCNT </c> instruction. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 207 | /// |
| 208 | /// \param __X |
| 209 | /// An unsigned 32-bit integer whose trailing zeros are to be counted. |
Ekaterina Romanova | dffe45b | 2016-12-27 00:49:38 +0000 | [diff] [blame] | 210 | /// \returns An 32-bit integer containing the number of trailing zero bits in |
| 211 | /// the operand. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 212 | static __inline__ int __RELAXED_FN_ATTRS |
| 213 | _mm_tzcnt_32(unsigned int __X) |
| 214 | { |
| 215 | return __X ? __builtin_ctz(__X) : 32; |
| 216 | } |
| 217 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 218 | #ifdef __x86_64__ |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 219 | |
| 220 | #define _andn_u64(a, b) (__andn_u64((a), (b))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 221 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 222 | /* _bextr_u64 != __bextr_u64 */ |
| 223 | #define _blsi_u64(a) (__blsi_u64((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 224 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 225 | #define _blsmsk_u64(a) (__blsmsk_u64((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 226 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 227 | #define _blsr_u64(a) (__blsr_u64((a))) |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 228 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 229 | #define _tzcnt_u64(a) (__tzcnt_u64((a))) |
| 230 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 231 | /// Performs a bitwise AND of the second operand with the one's |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 232 | /// complement of the first operand. |
| 233 | /// |
| 234 | /// \headerfile <x86intrin.h> |
| 235 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 236 | /// This intrinsic corresponds to the <c> ANDN </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 237 | /// |
| 238 | /// \param __X |
| 239 | /// An unsigned 64-bit integer containing one of the operands. |
| 240 | /// \param __Y |
| 241 | /// An unsigned 64-bit integer containing one of the operands. |
| 242 | /// \returns An unsigned 64-bit integer containing the bitwise AND of the second |
| 243 | /// operand with the one's complement of the first operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 244 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 245 | __andn_u64 (unsigned long long __X, unsigned long long __Y) |
| 246 | { |
| 247 | return ~__X & __Y; |
| 248 | } |
| 249 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 250 | /* AMD-specified, double-leading-underscore version of BEXTR */ |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 251 | /// Extracts the specified bits from the first operand and returns them |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 252 | /// in the least significant bits of the result. |
| 253 | /// |
| 254 | /// \headerfile <x86intrin.h> |
| 255 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 256 | /// This intrinsic corresponds to the <c> BEXTR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 257 | /// |
| 258 | /// \param __X |
| 259 | /// An unsigned 64-bit integer whose bits are to be extracted. |
| 260 | /// \param __Y |
| 261 | /// An unsigned 64-bit integer used to specify which bits are extracted. Bits |
| 262 | /// [7:0] specify the index of the least significant bit. Bits [15:8] specify |
| 263 | /// the number of bits to be extracted. |
| 264 | /// \returns An unsigned 64-bit integer whose least significant bits contain the |
| 265 | /// extracted bits. |
Ekaterina Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame^] | 266 | /// \see _bextr_u64 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 267 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 268 | __bextr_u64(unsigned long long __X, unsigned long long __Y) |
| 269 | { |
| 270 | return __builtin_ia32_bextr_u64(__X, __Y); |
| 271 | } |
| 272 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 273 | /* Intel-specified, single-leading-underscore version of BEXTR */ |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 274 | /// Extracts the specified bits from the first operand and returns them |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 275 | /// in the least significant bits of the result. |
| 276 | /// |
| 277 | /// \headerfile <x86intrin.h> |
| 278 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 279 | /// This intrinsic corresponds to the <c> BEXTR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 280 | /// |
| 281 | /// \param __X |
| 282 | /// An unsigned 64-bit integer whose bits are to be extracted. |
| 283 | /// \param __Y |
| 284 | /// An unsigned integer used to specify the index of the least significant |
| 285 | /// bit for the bits to be extracted. Bits [7:0] specify the index. |
| 286 | /// \param __Z |
| 287 | /// An unsigned integer used to specify the number of bits to be extracted. |
| 288 | /// Bits [7:0] specify the number of bits. |
| 289 | /// \returns An unsigned 64-bit integer whose least significant bits contain the |
| 290 | /// extracted bits. |
Ekaterina Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame^] | 291 | /// \see __bextr_u64 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 292 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 293 | _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z) |
| 294 | { |
| 295 | return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); |
| 296 | } |
| 297 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 298 | /// Clears all bits in the source except for the least significant bit |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 299 | /// containing a value of 1 and returns the result. |
| 300 | /// |
| 301 | /// \headerfile <x86intrin.h> |
| 302 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 303 | /// This intrinsic corresponds to the <c> BLSI </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 304 | /// |
| 305 | /// \param __X |
| 306 | /// An unsigned 64-bit integer whose bits are to be cleared. |
| 307 | /// \returns An unsigned 64-bit integer containing the result of clearing the |
| 308 | /// bits from the source operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 309 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 310 | __blsi_u64(unsigned long long __X) |
| 311 | { |
| 312 | return __X & -__X; |
| 313 | } |
| 314 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 315 | /// Creates a mask whose bits are set to 1, using bit 0 up to and |
Ekaterina Romanova | cb3603a | 2017-06-06 22:58:01 +0000 | [diff] [blame] | 316 | /// including the least significant bit that is set to 1 in the source |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 317 | /// operand and returns the result. |
| 318 | /// |
| 319 | /// \headerfile <x86intrin.h> |
| 320 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 321 | /// This intrinsic corresponds to the <c> BLSMSK </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 322 | /// |
| 323 | /// \param __X |
| 324 | /// An unsigned 64-bit integer used to create the mask. |
Ekaterina Romanova | 03ecd77 | 2017-07-12 20:18:55 +0000 | [diff] [blame] | 325 | /// \returns An unsigned 64-bit integer containing the newly created mask. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 326 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 327 | __blsmsk_u64(unsigned long long __X) |
| 328 | { |
| 329 | return __X ^ (__X - 1); |
| 330 | } |
| 331 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 332 | /// Clears the least significant bit that is set to 1 in the source |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 333 | /// operand and returns the result. |
| 334 | /// |
| 335 | /// \headerfile <x86intrin.h> |
| 336 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 337 | /// This intrinsic corresponds to the <c> BLSR </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 338 | /// |
| 339 | /// \param __X |
| 340 | /// An unsigned 64-bit integer containing the operand to be cleared. |
| 341 | /// \returns An unsigned 64-bit integer containing the result of clearing the |
| 342 | /// source operand. |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 343 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | a06d4a1 | 2011-12-25 07:27:12 +0000 | [diff] [blame] | 344 | __blsr_u64(unsigned long long __X) |
| 345 | { |
| 346 | return __X & (__X - 1); |
| 347 | } |
| 348 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 349 | /// Counts the number of trailing zero bits in the operand. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 350 | /// |
| 351 | /// \headerfile <x86intrin.h> |
| 352 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 353 | /// This intrinsic corresponds to the <c> TZCNT </c> instruction. |
Ekaterina Romanova | c8976d5 | 2016-03-08 01:36:59 +0000 | [diff] [blame] | 354 | /// |
| 355 | /// \param __X |
| 356 | /// An unsigned 64-bit integer whose trailing zeros are to be counted. |
| 357 | /// \returns An unsigned 64-bit integer containing the number of trailing zero |
| 358 | /// bits in the operand. |
Hans Wennborg | 1acf955 | 2015-11-17 18:46:48 +0000 | [diff] [blame] | 359 | static __inline__ unsigned long long __RELAXED_FN_ATTRS |
Craig Topper | 6490bdc | 2012-07-02 06:52:51 +0000 | [diff] [blame] | 360 | __tzcnt_u64(unsigned long long __X) |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 361 | { |
Craig Topper | a52e0d7 | 2014-11-01 22:50:54 +0000 | [diff] [blame] | 362 | return __X ? __builtin_ctzll(__X) : 64; |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 363 | } |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 364 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 365 | /// Counts the number of trailing zero bits in the operand. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 366 | /// |
| 367 | /// \headerfile <x86intrin.h> |
| 368 | /// |
Ekaterina Romanova | 0c1c3bb | 2016-12-09 18:35:50 +0000 | [diff] [blame] | 369 | /// This intrinsic corresponds to the <c> TZCNT </c> instruction. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 370 | /// |
| 371 | /// \param __X |
| 372 | /// An unsigned 64-bit integer whose trailing zeros are to be counted. |
Ekaterina Romanova | dffe45b | 2016-12-27 00:49:38 +0000 | [diff] [blame] | 373 | /// \returns An 64-bit integer containing the number of trailing zero bits in |
| 374 | /// the operand. |
Michael Zuckerman | 716859a | 2016-06-22 12:32:43 +0000 | [diff] [blame] | 375 | static __inline__ long long __RELAXED_FN_ATTRS |
| 376 | _mm_tzcnt_64(unsigned long long __X) |
| 377 | { |
| 378 | return __X ? __builtin_ctzll(__X) : 64; |
| 379 | } |
| 380 | |
Sanjay Patel | 1585fb9 | 2014-05-28 20:26:57 +0000 | [diff] [blame] | 381 | #endif /* __x86_64__ */ |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 382 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 383 | #undef __DEFAULT_FN_ATTRS |
Hans Wennborg | 1acf955 | 2015-11-17 18:46:48 +0000 | [diff] [blame] | 384 | #undef __RELAXED_FN_ATTRS |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 385 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 386 | #endif /* __BMIINTRIN_H */ |