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