xref: /openbsd-src/gnu/llvm/clang/lib/Headers/bmiintrin.h (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick /*===---- bmiintrin.h - BMI intrinsics -------------------------------------===
2e5dd7070Spatrick  *
3e5dd7070Spatrick  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick  * See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick  *
7e5dd7070Spatrick  *===-----------------------------------------------------------------------===
8e5dd7070Spatrick  */
9e5dd7070Spatrick 
10e5dd7070Spatrick #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
11e5dd7070Spatrick #error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."
12e5dd7070Spatrick #endif
13e5dd7070Spatrick 
14e5dd7070Spatrick #ifndef __BMIINTRIN_H
15e5dd7070Spatrick #define __BMIINTRIN_H
16e5dd7070Spatrick 
17e5dd7070Spatrick /* Allow using the tzcnt intrinsics even for non-BMI targets. Since the TZCNT
18e5dd7070Spatrick    instruction behaves as BSF on non-BMI targets, there is code that expects
19e5dd7070Spatrick    to use it as a potentially faster version of BSF. */
20e5dd7070Spatrick #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
21e5dd7070Spatrick 
22e5dd7070Spatrick #define _tzcnt_u16(a)     (__tzcnt_u16((a)))
23e5dd7070Spatrick 
24e5dd7070Spatrick /// Counts the number of trailing zero bits in the operand.
25e5dd7070Spatrick ///
26e5dd7070Spatrick /// \headerfile <x86intrin.h>
27e5dd7070Spatrick ///
28e5dd7070Spatrick /// This intrinsic corresponds to the <c> TZCNT </c> instruction.
29e5dd7070Spatrick ///
30e5dd7070Spatrick /// \param __X
31e5dd7070Spatrick ///    An unsigned 16-bit integer whose trailing zeros are to be counted.
32e5dd7070Spatrick /// \returns An unsigned 16-bit integer containing the number of trailing zero
33e5dd7070Spatrick ///    bits in the operand.
34e5dd7070Spatrick static __inline__ unsigned short __RELAXED_FN_ATTRS
__tzcnt_u16(unsigned short __X)35e5dd7070Spatrick __tzcnt_u16(unsigned short __X)
36e5dd7070Spatrick {
37e5dd7070Spatrick   return __builtin_ia32_tzcnt_u16(__X);
38e5dd7070Spatrick }
39e5dd7070Spatrick 
40e5dd7070Spatrick /// Counts the number of trailing zero bits in the operand.
41e5dd7070Spatrick ///
42e5dd7070Spatrick /// \headerfile <x86intrin.h>
43e5dd7070Spatrick ///
44e5dd7070Spatrick /// This intrinsic corresponds to the <c> TZCNT </c> instruction.
45e5dd7070Spatrick ///
46e5dd7070Spatrick /// \param __X
47e5dd7070Spatrick ///    An unsigned 32-bit integer whose trailing zeros are to be counted.
48e5dd7070Spatrick /// \returns An unsigned 32-bit integer containing the number of trailing zero
49e5dd7070Spatrick ///    bits in the operand.
50*12c85518Srobert /// \see _mm_tzcnt_32
51e5dd7070Spatrick static __inline__ unsigned int __RELAXED_FN_ATTRS
__tzcnt_u32(unsigned int __X)52e5dd7070Spatrick __tzcnt_u32(unsigned int __X)
53e5dd7070Spatrick {
54e5dd7070Spatrick   return __builtin_ia32_tzcnt_u32(__X);
55e5dd7070Spatrick }
56e5dd7070Spatrick 
57e5dd7070Spatrick /// Counts the number of trailing zero bits in the operand.
58e5dd7070Spatrick ///
59e5dd7070Spatrick /// \headerfile <x86intrin.h>
60e5dd7070Spatrick ///
61e5dd7070Spatrick /// This intrinsic corresponds to the <c> TZCNT </c> instruction.
62e5dd7070Spatrick ///
63e5dd7070Spatrick /// \param __X
64e5dd7070Spatrick ///    An unsigned 32-bit integer whose trailing zeros are to be counted.
65e5dd7070Spatrick /// \returns An 32-bit integer containing the number of trailing zero bits in
66e5dd7070Spatrick ///    the operand.
67*12c85518Srobert /// \see __tzcnt_u32
68e5dd7070Spatrick static __inline__ int __RELAXED_FN_ATTRS
_mm_tzcnt_32(unsigned int __X)69e5dd7070Spatrick _mm_tzcnt_32(unsigned int __X)
70e5dd7070Spatrick {
71*12c85518Srobert   return (int)__builtin_ia32_tzcnt_u32(__X);
72e5dd7070Spatrick }
73e5dd7070Spatrick 
74e5dd7070Spatrick #define _tzcnt_u32(a)     (__tzcnt_u32((a)))
75e5dd7070Spatrick 
76e5dd7070Spatrick #ifdef __x86_64__
77e5dd7070Spatrick 
78e5dd7070Spatrick /// Counts the number of trailing zero bits in the operand.
79e5dd7070Spatrick ///
80e5dd7070Spatrick /// \headerfile <x86intrin.h>
81e5dd7070Spatrick ///
82e5dd7070Spatrick /// This intrinsic corresponds to the <c> TZCNT </c> instruction.
83e5dd7070Spatrick ///
84e5dd7070Spatrick /// \param __X
85e5dd7070Spatrick ///    An unsigned 64-bit integer whose trailing zeros are to be counted.
86e5dd7070Spatrick /// \returns An unsigned 64-bit integer containing the number of trailing zero
87e5dd7070Spatrick ///    bits in the operand.
88*12c85518Srobert /// \see _mm_tzcnt_64
89e5dd7070Spatrick static __inline__ unsigned long long __RELAXED_FN_ATTRS
__tzcnt_u64(unsigned long long __X)90e5dd7070Spatrick __tzcnt_u64(unsigned long long __X)
91e5dd7070Spatrick {
92e5dd7070Spatrick   return __builtin_ia32_tzcnt_u64(__X);
93e5dd7070Spatrick }
94e5dd7070Spatrick 
95e5dd7070Spatrick /// Counts the number of trailing zero bits in the operand.
96e5dd7070Spatrick ///
97e5dd7070Spatrick /// \headerfile <x86intrin.h>
98e5dd7070Spatrick ///
99e5dd7070Spatrick /// This intrinsic corresponds to the <c> TZCNT </c> instruction.
100e5dd7070Spatrick ///
101e5dd7070Spatrick /// \param __X
102e5dd7070Spatrick ///    An unsigned 64-bit integer whose trailing zeros are to be counted.
103e5dd7070Spatrick /// \returns An 64-bit integer containing the number of trailing zero bits in
104e5dd7070Spatrick ///    the operand.
105*12c85518Srobert /// \see __tzcnt_u64
106e5dd7070Spatrick static __inline__ long long __RELAXED_FN_ATTRS
_mm_tzcnt_64(unsigned long long __X)107e5dd7070Spatrick _mm_tzcnt_64(unsigned long long __X)
108e5dd7070Spatrick {
109*12c85518Srobert   return (long long)__builtin_ia32_tzcnt_u64(__X);
110e5dd7070Spatrick }
111e5dd7070Spatrick 
112e5dd7070Spatrick #define _tzcnt_u64(a)     (__tzcnt_u64((a)))
113e5dd7070Spatrick 
114e5dd7070Spatrick #endif /* __x86_64__ */
115e5dd7070Spatrick 
116e5dd7070Spatrick #undef __RELAXED_FN_ATTRS
117e5dd7070Spatrick 
118ec727ea7Spatrick #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||      \
119ec727ea7Spatrick     defined(__BMI__)
120e5dd7070Spatrick 
121e5dd7070Spatrick /* Define the default attributes for the functions in this file. */
122e5dd7070Spatrick #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi")))
123e5dd7070Spatrick 
124e5dd7070Spatrick #define _andn_u32(a, b)   (__andn_u32((a), (b)))
125e5dd7070Spatrick 
126e5dd7070Spatrick /* _bextr_u32 != __bextr_u32 */
127e5dd7070Spatrick #define _blsi_u32(a)      (__blsi_u32((a)))
128e5dd7070Spatrick 
129e5dd7070Spatrick #define _blsmsk_u32(a)    (__blsmsk_u32((a)))
130e5dd7070Spatrick 
131e5dd7070Spatrick #define _blsr_u32(a)      (__blsr_u32((a)))
132e5dd7070Spatrick 
133e5dd7070Spatrick /// Performs a bitwise AND of the second operand with the one's
134e5dd7070Spatrick ///    complement of the first operand.
135e5dd7070Spatrick ///
136e5dd7070Spatrick /// \headerfile <x86intrin.h>
137e5dd7070Spatrick ///
138e5dd7070Spatrick /// This intrinsic corresponds to the <c> ANDN </c> instruction.
139e5dd7070Spatrick ///
140e5dd7070Spatrick /// \param __X
141e5dd7070Spatrick ///    An unsigned integer containing one of the operands.
142e5dd7070Spatrick /// \param __Y
143e5dd7070Spatrick ///    An unsigned integer containing one of the operands.
144e5dd7070Spatrick /// \returns An unsigned integer containing the bitwise AND of the second
145e5dd7070Spatrick ///    operand with the one's complement of the first operand.
146e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
__andn_u32(unsigned int __X,unsigned int __Y)147e5dd7070Spatrick __andn_u32(unsigned int __X, unsigned int __Y)
148e5dd7070Spatrick {
149e5dd7070Spatrick   return ~__X & __Y;
150e5dd7070Spatrick }
151e5dd7070Spatrick 
152e5dd7070Spatrick /* AMD-specified, double-leading-underscore version of BEXTR */
153e5dd7070Spatrick /// Extracts the specified bits from the first operand and returns them
154e5dd7070Spatrick ///    in the least significant bits of the result.
155e5dd7070Spatrick ///
156e5dd7070Spatrick /// \headerfile <x86intrin.h>
157e5dd7070Spatrick ///
158e5dd7070Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
159e5dd7070Spatrick ///
160e5dd7070Spatrick /// \param __X
161e5dd7070Spatrick ///    An unsigned integer whose bits are to be extracted.
162e5dd7070Spatrick /// \param __Y
163e5dd7070Spatrick ///    An unsigned integer used to specify which bits are extracted. Bits [7:0]
164e5dd7070Spatrick ///    specify the index of the least significant bit. Bits [15:8] specify the
165e5dd7070Spatrick ///    number of bits to be extracted.
166e5dd7070Spatrick /// \returns An unsigned integer whose least significant bits contain the
167e5dd7070Spatrick ///    extracted bits.
168e5dd7070Spatrick /// \see _bextr_u32
169e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
__bextr_u32(unsigned int __X,unsigned int __Y)170e5dd7070Spatrick __bextr_u32(unsigned int __X, unsigned int __Y)
171e5dd7070Spatrick {
172e5dd7070Spatrick   return __builtin_ia32_bextr_u32(__X, __Y);
173e5dd7070Spatrick }
174e5dd7070Spatrick 
175e5dd7070Spatrick /* Intel-specified, single-leading-underscore version of BEXTR */
176e5dd7070Spatrick /// Extracts the specified bits from the first operand and returns them
177e5dd7070Spatrick ///    in the least significant bits of the result.
178e5dd7070Spatrick ///
179e5dd7070Spatrick /// \headerfile <x86intrin.h>
180e5dd7070Spatrick ///
181e5dd7070Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
182e5dd7070Spatrick ///
183e5dd7070Spatrick /// \param __X
184e5dd7070Spatrick ///    An unsigned integer whose bits are to be extracted.
185e5dd7070Spatrick /// \param __Y
186e5dd7070Spatrick ///    An unsigned integer used to specify the index of the least significant
187e5dd7070Spatrick ///    bit for the bits to be extracted. Bits [7:0] specify the index.
188e5dd7070Spatrick /// \param __Z
189e5dd7070Spatrick ///    An unsigned integer used to specify the number of bits to be extracted.
190e5dd7070Spatrick ///    Bits [7:0] specify the number of bits.
191e5dd7070Spatrick /// \returns An unsigned integer whose least significant bits contain the
192e5dd7070Spatrick ///    extracted bits.
193e5dd7070Spatrick /// \see __bextr_u32
194e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
_bextr_u32(unsigned int __X,unsigned int __Y,unsigned int __Z)195e5dd7070Spatrick _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
196e5dd7070Spatrick {
197e5dd7070Spatrick   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
198e5dd7070Spatrick }
199e5dd7070Spatrick 
200ec727ea7Spatrick /* Intel-specified, single-leading-underscore version of BEXTR2 */
201ec727ea7Spatrick /// Extracts the specified bits from the first operand and returns them
202ec727ea7Spatrick ///    in the least significant bits of the result.
203ec727ea7Spatrick ///
204ec727ea7Spatrick /// \headerfile <x86intrin.h>
205ec727ea7Spatrick ///
206ec727ea7Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
207ec727ea7Spatrick ///
208ec727ea7Spatrick /// \param __X
209ec727ea7Spatrick ///    An unsigned integer whose bits are to be extracted.
210ec727ea7Spatrick /// \param __Y
211ec727ea7Spatrick ///    An unsigned integer used to specify which bits are extracted. Bits [7:0]
212ec727ea7Spatrick ///    specify the index of the least significant bit. Bits [15:8] specify the
213ec727ea7Spatrick ///    number of bits to be extracted.
214ec727ea7Spatrick /// \returns An unsigned integer whose least significant bits contain the
215ec727ea7Spatrick ///    extracted bits.
216ec727ea7Spatrick /// \see __bextr_u32
217ec727ea7Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
_bextr2_u32(unsigned int __X,unsigned int __Y)218ec727ea7Spatrick _bextr2_u32(unsigned int __X, unsigned int __Y) {
219ec727ea7Spatrick   return __builtin_ia32_bextr_u32(__X, __Y);
220ec727ea7Spatrick }
221ec727ea7Spatrick 
222e5dd7070Spatrick /// Clears all bits in the source except for the least significant bit
223e5dd7070Spatrick ///    containing a value of 1 and returns the result.
224e5dd7070Spatrick ///
225e5dd7070Spatrick /// \headerfile <x86intrin.h>
226e5dd7070Spatrick ///
227e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSI </c> instruction.
228e5dd7070Spatrick ///
229e5dd7070Spatrick /// \param __X
230e5dd7070Spatrick ///    An unsigned integer whose bits are to be cleared.
231e5dd7070Spatrick /// \returns An unsigned integer containing the result of clearing the bits from
232e5dd7070Spatrick ///    the source operand.
233e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blsi_u32(unsigned int __X)234e5dd7070Spatrick __blsi_u32(unsigned int __X)
235e5dd7070Spatrick {
236e5dd7070Spatrick   return __X & -__X;
237e5dd7070Spatrick }
238e5dd7070Spatrick 
239e5dd7070Spatrick /// Creates a mask whose bits are set to 1, using bit 0 up to and
240e5dd7070Spatrick ///    including the least significant bit that is set to 1 in the source
241e5dd7070Spatrick ///    operand and returns the result.
242e5dd7070Spatrick ///
243e5dd7070Spatrick /// \headerfile <x86intrin.h>
244e5dd7070Spatrick ///
245e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSMSK </c> instruction.
246e5dd7070Spatrick ///
247e5dd7070Spatrick /// \param __X
248e5dd7070Spatrick ///    An unsigned integer used to create the mask.
249e5dd7070Spatrick /// \returns An unsigned integer containing the newly created mask.
250e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blsmsk_u32(unsigned int __X)251e5dd7070Spatrick __blsmsk_u32(unsigned int __X)
252e5dd7070Spatrick {
253e5dd7070Spatrick   return __X ^ (__X - 1);
254e5dd7070Spatrick }
255e5dd7070Spatrick 
256e5dd7070Spatrick /// Clears the least significant bit that is set to 1 in the source
257e5dd7070Spatrick ///    operand and returns the result.
258e5dd7070Spatrick ///
259e5dd7070Spatrick /// \headerfile <x86intrin.h>
260e5dd7070Spatrick ///
261e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSR </c> instruction.
262e5dd7070Spatrick ///
263e5dd7070Spatrick /// \param __X
264e5dd7070Spatrick ///    An unsigned integer containing the operand to be cleared.
265e5dd7070Spatrick /// \returns An unsigned integer containing the result of clearing the source
266e5dd7070Spatrick ///    operand.
267e5dd7070Spatrick static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blsr_u32(unsigned int __X)268e5dd7070Spatrick __blsr_u32(unsigned int __X)
269e5dd7070Spatrick {
270e5dd7070Spatrick   return __X & (__X - 1);
271e5dd7070Spatrick }
272e5dd7070Spatrick 
273e5dd7070Spatrick #ifdef __x86_64__
274e5dd7070Spatrick 
275e5dd7070Spatrick #define _andn_u64(a, b)   (__andn_u64((a), (b)))
276e5dd7070Spatrick 
277e5dd7070Spatrick /* _bextr_u64 != __bextr_u64 */
278e5dd7070Spatrick #define _blsi_u64(a)      (__blsi_u64((a)))
279e5dd7070Spatrick 
280e5dd7070Spatrick #define _blsmsk_u64(a)    (__blsmsk_u64((a)))
281e5dd7070Spatrick 
282e5dd7070Spatrick #define _blsr_u64(a)      (__blsr_u64((a)))
283e5dd7070Spatrick 
284e5dd7070Spatrick /// Performs a bitwise AND of the second operand with the one's
285e5dd7070Spatrick ///    complement of the first operand.
286e5dd7070Spatrick ///
287e5dd7070Spatrick /// \headerfile <x86intrin.h>
288e5dd7070Spatrick ///
289e5dd7070Spatrick /// This intrinsic corresponds to the <c> ANDN </c> instruction.
290e5dd7070Spatrick ///
291e5dd7070Spatrick /// \param __X
292e5dd7070Spatrick ///    An unsigned 64-bit integer containing one of the operands.
293e5dd7070Spatrick /// \param __Y
294e5dd7070Spatrick ///    An unsigned 64-bit integer containing one of the operands.
295e5dd7070Spatrick /// \returns An unsigned 64-bit integer containing the bitwise AND of the second
296e5dd7070Spatrick ///    operand with the one's complement of the first operand.
297e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__andn_u64(unsigned long long __X,unsigned long long __Y)298e5dd7070Spatrick __andn_u64 (unsigned long long __X, unsigned long long __Y)
299e5dd7070Spatrick {
300e5dd7070Spatrick   return ~__X & __Y;
301e5dd7070Spatrick }
302e5dd7070Spatrick 
303e5dd7070Spatrick /* AMD-specified, double-leading-underscore version of BEXTR */
304e5dd7070Spatrick /// Extracts the specified bits from the first operand and returns them
305e5dd7070Spatrick ///    in the least significant bits of the result.
306e5dd7070Spatrick ///
307e5dd7070Spatrick /// \headerfile <x86intrin.h>
308e5dd7070Spatrick ///
309e5dd7070Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
310e5dd7070Spatrick ///
311e5dd7070Spatrick /// \param __X
312e5dd7070Spatrick ///    An unsigned 64-bit integer whose bits are to be extracted.
313e5dd7070Spatrick /// \param __Y
314e5dd7070Spatrick ///    An unsigned 64-bit integer used to specify which bits are extracted. Bits
315e5dd7070Spatrick ///    [7:0] specify the index of the least significant bit. Bits [15:8] specify
316e5dd7070Spatrick ///    the number of bits to be extracted.
317e5dd7070Spatrick /// \returns An unsigned 64-bit integer whose least significant bits contain the
318e5dd7070Spatrick ///    extracted bits.
319e5dd7070Spatrick /// \see _bextr_u64
320e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__bextr_u64(unsigned long long __X,unsigned long long __Y)321e5dd7070Spatrick __bextr_u64(unsigned long long __X, unsigned long long __Y)
322e5dd7070Spatrick {
323e5dd7070Spatrick   return __builtin_ia32_bextr_u64(__X, __Y);
324e5dd7070Spatrick }
325e5dd7070Spatrick 
326e5dd7070Spatrick /* Intel-specified, single-leading-underscore version of BEXTR */
327e5dd7070Spatrick /// Extracts the specified bits from the first operand and returns them
328e5dd7070Spatrick ///     in the least significant bits of the result.
329e5dd7070Spatrick ///
330e5dd7070Spatrick /// \headerfile <x86intrin.h>
331e5dd7070Spatrick ///
332e5dd7070Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
333e5dd7070Spatrick ///
334e5dd7070Spatrick /// \param __X
335e5dd7070Spatrick ///    An unsigned 64-bit integer whose bits are to be extracted.
336e5dd7070Spatrick /// \param __Y
337e5dd7070Spatrick ///    An unsigned integer used to specify the index of the least significant
338e5dd7070Spatrick ///    bit for the bits to be extracted. Bits [7:0] specify the index.
339e5dd7070Spatrick /// \param __Z
340e5dd7070Spatrick ///    An unsigned integer used to specify the number of bits to be extracted.
341e5dd7070Spatrick ///    Bits [7:0] specify the number of bits.
342e5dd7070Spatrick /// \returns An unsigned 64-bit integer whose least significant bits contain the
343e5dd7070Spatrick ///    extracted bits.
344e5dd7070Spatrick /// \see __bextr_u64
345e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
_bextr_u64(unsigned long long __X,unsigned int __Y,unsigned int __Z)346e5dd7070Spatrick _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)
347e5dd7070Spatrick {
348e5dd7070Spatrick   return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
349e5dd7070Spatrick }
350e5dd7070Spatrick 
351ec727ea7Spatrick /* Intel-specified, single-leading-underscore version of BEXTR2 */
352ec727ea7Spatrick /// Extracts the specified bits from the first operand and returns them
353ec727ea7Spatrick ///    in the least significant bits of the result.
354ec727ea7Spatrick ///
355ec727ea7Spatrick /// \headerfile <x86intrin.h>
356ec727ea7Spatrick ///
357ec727ea7Spatrick /// This intrinsic corresponds to the <c> BEXTR </c> instruction.
358ec727ea7Spatrick ///
359ec727ea7Spatrick /// \param __X
360ec727ea7Spatrick ///    An unsigned 64-bit integer whose bits are to be extracted.
361ec727ea7Spatrick /// \param __Y
362ec727ea7Spatrick ///    An unsigned 64-bit integer used to specify which bits are extracted. Bits
363ec727ea7Spatrick ///    [7:0] specify the index of the least significant bit. Bits [15:8] specify
364ec727ea7Spatrick ///    the number of bits to be extracted.
365ec727ea7Spatrick /// \returns An unsigned 64-bit integer whose least significant bits contain the
366ec727ea7Spatrick ///    extracted bits.
367ec727ea7Spatrick /// \see __bextr_u64
368ec727ea7Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
_bextr2_u64(unsigned long long __X,unsigned long long __Y)369ec727ea7Spatrick _bextr2_u64(unsigned long long __X, unsigned long long __Y) {
370ec727ea7Spatrick   return __builtin_ia32_bextr_u64(__X, __Y);
371ec727ea7Spatrick }
372ec727ea7Spatrick 
373e5dd7070Spatrick /// Clears all bits in the source except for the least significant bit
374e5dd7070Spatrick ///    containing a value of 1 and returns the result.
375e5dd7070Spatrick ///
376e5dd7070Spatrick /// \headerfile <x86intrin.h>
377e5dd7070Spatrick ///
378e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSI </c> instruction.
379e5dd7070Spatrick ///
380e5dd7070Spatrick /// \param __X
381e5dd7070Spatrick ///    An unsigned 64-bit integer whose bits are to be cleared.
382e5dd7070Spatrick /// \returns An unsigned 64-bit integer containing the result of clearing the
383e5dd7070Spatrick ///    bits from the source operand.
384e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blsi_u64(unsigned long long __X)385e5dd7070Spatrick __blsi_u64(unsigned long long __X)
386e5dd7070Spatrick {
387e5dd7070Spatrick   return __X & -__X;
388e5dd7070Spatrick }
389e5dd7070Spatrick 
390e5dd7070Spatrick /// Creates a mask whose bits are set to 1, using bit 0 up to and
391e5dd7070Spatrick ///    including the least significant bit that is set to 1 in the source
392e5dd7070Spatrick ///    operand and returns the result.
393e5dd7070Spatrick ///
394e5dd7070Spatrick /// \headerfile <x86intrin.h>
395e5dd7070Spatrick ///
396e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSMSK </c> instruction.
397e5dd7070Spatrick ///
398e5dd7070Spatrick /// \param __X
399e5dd7070Spatrick ///    An unsigned 64-bit integer used to create the mask.
400e5dd7070Spatrick /// \returns An unsigned 64-bit integer containing the newly created mask.
401e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blsmsk_u64(unsigned long long __X)402e5dd7070Spatrick __blsmsk_u64(unsigned long long __X)
403e5dd7070Spatrick {
404e5dd7070Spatrick   return __X ^ (__X - 1);
405e5dd7070Spatrick }
406e5dd7070Spatrick 
407e5dd7070Spatrick /// Clears the least significant bit that is set to 1 in the source
408e5dd7070Spatrick ///    operand and returns the result.
409e5dd7070Spatrick ///
410e5dd7070Spatrick /// \headerfile <x86intrin.h>
411e5dd7070Spatrick ///
412e5dd7070Spatrick /// This intrinsic corresponds to the <c> BLSR </c> instruction.
413e5dd7070Spatrick ///
414e5dd7070Spatrick /// \param __X
415e5dd7070Spatrick ///    An unsigned 64-bit integer containing the operand to be cleared.
416e5dd7070Spatrick /// \returns An unsigned 64-bit integer containing the result of clearing the
417e5dd7070Spatrick ///    source operand.
418e5dd7070Spatrick static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blsr_u64(unsigned long long __X)419e5dd7070Spatrick __blsr_u64(unsigned long long __X)
420e5dd7070Spatrick {
421e5dd7070Spatrick   return __X & (__X - 1);
422e5dd7070Spatrick }
423e5dd7070Spatrick 
424e5dd7070Spatrick #endif /* __x86_64__ */
425e5dd7070Spatrick 
426e5dd7070Spatrick #undef __DEFAULT_FN_ATTRS
427e5dd7070Spatrick 
428ec727ea7Spatrick #endif /* !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules)   \
429ec727ea7Spatrick           || defined(__BMI__) */
430e5dd7070Spatrick 
431e5dd7070Spatrick #endif /* __BMIINTRIN_H */
432