10b57cec5SDimitry Andric /*===---- bmiintrin.h - BMI intrinsics -------------------------------------=== 20b57cec5SDimitry Andric * 30b57cec5SDimitry Andric * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric * See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric * 70b57cec5SDimitry Andric *===-----------------------------------------------------------------------=== 80b57cec5SDimitry Andric */ 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H 110b57cec5SDimitry Andric #error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead." 120b57cec5SDimitry Andric #endif 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef __BMIINTRIN_H 150b57cec5SDimitry Andric #define __BMIINTRIN_H 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric /* Allow using the tzcnt intrinsics even for non-BMI targets. Since the TZCNT 180b57cec5SDimitry Andric instruction behaves as BSF on non-BMI targets, there is code that expects 190b57cec5SDimitry Andric to use it as a potentially faster version of BSF. */ 200b57cec5SDimitry Andric #define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric /// Counts the number of trailing zero bits in the operand. 230b57cec5SDimitry Andric /// 240b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 250b57cec5SDimitry Andric /// 267a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 270b57cec5SDimitry Andric /// 280b57cec5SDimitry Andric /// \param __X 290b57cec5SDimitry Andric /// An unsigned 16-bit integer whose trailing zeros are to be counted. 300b57cec5SDimitry Andric /// \returns An unsigned 16-bit integer containing the number of trailing zero 310b57cec5SDimitry Andric /// bits in the operand. 327a6dacacSDimitry Andric /// \see _tzcnt_u16 330b57cec5SDimitry Andric static __inline__ unsigned short __RELAXED_FN_ATTRS 340b57cec5SDimitry Andric __tzcnt_u16(unsigned short __X) 350b57cec5SDimitry Andric { 360b57cec5SDimitry Andric return __builtin_ia32_tzcnt_u16(__X); 370b57cec5SDimitry Andric } 380b57cec5SDimitry Andric 39a7dea167SDimitry Andric /// Counts the number of trailing zero bits in the operand. 40a7dea167SDimitry Andric /// 41a7dea167SDimitry Andric /// \headerfile <x86intrin.h> 42a7dea167SDimitry Andric /// 437a6dacacSDimitry Andric /// \code 447a6dacacSDimitry Andric /// unsigned short _tzcnt_u16(unsigned short __X); 457a6dacacSDimitry Andric /// \endcode 467a6dacacSDimitry Andric /// 477a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 487a6dacacSDimitry Andric /// 497a6dacacSDimitry Andric /// \param __X 507a6dacacSDimitry Andric /// An unsigned 16-bit integer whose trailing zeros are to be counted. 517a6dacacSDimitry Andric /// \returns An unsigned 16-bit integer containing the number of trailing zero 527a6dacacSDimitry Andric /// bits in the operand. 537a6dacacSDimitry Andric /// \see __tzcnt_u16 547a6dacacSDimitry Andric #define _tzcnt_u16 __tzcnt_u16 557a6dacacSDimitry Andric 567a6dacacSDimitry Andric /// Counts the number of trailing zero bits in the operand. 577a6dacacSDimitry Andric /// 587a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 597a6dacacSDimitry Andric /// 607a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 61a7dea167SDimitry Andric /// 62a7dea167SDimitry Andric /// \param __X 63a7dea167SDimitry Andric /// An unsigned 32-bit integer whose trailing zeros are to be counted. 64a7dea167SDimitry Andric /// \returns An unsigned 32-bit integer containing the number of trailing zero 65a7dea167SDimitry Andric /// bits in the operand. 667a6dacacSDimitry Andric /// \see { _mm_tzcnt_32 _tzcnt_u32 } 67a7dea167SDimitry Andric static __inline__ unsigned int __RELAXED_FN_ATTRS 68a7dea167SDimitry Andric __tzcnt_u32(unsigned int __X) 69a7dea167SDimitry Andric { 70a7dea167SDimitry Andric return __builtin_ia32_tzcnt_u32(__X); 71a7dea167SDimitry Andric } 72a7dea167SDimitry Andric 73a7dea167SDimitry Andric /// Counts the number of trailing zero bits in the operand. 74a7dea167SDimitry Andric /// 75a7dea167SDimitry Andric /// \headerfile <x86intrin.h> 76a7dea167SDimitry Andric /// 777a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 78a7dea167SDimitry Andric /// 79a7dea167SDimitry Andric /// \param __X 80a7dea167SDimitry Andric /// An unsigned 32-bit integer whose trailing zeros are to be counted. 817a6dacacSDimitry Andric /// \returns A 32-bit integer containing the number of trailing zero bits in 82a7dea167SDimitry Andric /// the operand. 837a6dacacSDimitry Andric /// \see { __tzcnt_u32 _tzcnt_u32 } 84a7dea167SDimitry Andric static __inline__ int __RELAXED_FN_ATTRS 85a7dea167SDimitry Andric _mm_tzcnt_32(unsigned int __X) 86a7dea167SDimitry Andric { 8781ad6265SDimitry Andric return (int)__builtin_ia32_tzcnt_u32(__X); 88a7dea167SDimitry Andric } 89a7dea167SDimitry Andric 907a6dacacSDimitry Andric /// Counts the number of trailing zero bits in the operand. 917a6dacacSDimitry Andric /// 927a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 937a6dacacSDimitry Andric /// 947a6dacacSDimitry Andric /// \code 957a6dacacSDimitry Andric /// unsigned int _tzcnt_u32(unsigned int __X); 967a6dacacSDimitry Andric /// \endcode 977a6dacacSDimitry Andric /// 987a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 997a6dacacSDimitry Andric /// 1007a6dacacSDimitry Andric /// \param __X 1017a6dacacSDimitry Andric /// An unsigned 32-bit integer whose trailing zeros are to be counted. 1027a6dacacSDimitry Andric /// \returns An unsigned 32-bit integer containing the number of trailing zero 1037a6dacacSDimitry Andric /// bits in the operand. 1047a6dacacSDimitry Andric /// \see { _mm_tzcnt_32 __tzcnt_u32 } 1055f757f3fSDimitry Andric #define _tzcnt_u32 __tzcnt_u32 106a7dea167SDimitry Andric 107a7dea167SDimitry Andric #ifdef __x86_64__ 108a7dea167SDimitry Andric 109a7dea167SDimitry Andric /// Counts the number of trailing zero bits in the operand. 110a7dea167SDimitry Andric /// 111a7dea167SDimitry Andric /// \headerfile <x86intrin.h> 112a7dea167SDimitry Andric /// 1137a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 114a7dea167SDimitry Andric /// 115a7dea167SDimitry Andric /// \param __X 116a7dea167SDimitry Andric /// An unsigned 64-bit integer whose trailing zeros are to be counted. 117a7dea167SDimitry Andric /// \returns An unsigned 64-bit integer containing the number of trailing zero 118a7dea167SDimitry Andric /// bits in the operand. 1197a6dacacSDimitry Andric /// \see { _mm_tzcnt_64 _tzcnt_u64 } 120a7dea167SDimitry Andric static __inline__ unsigned long long __RELAXED_FN_ATTRS 121a7dea167SDimitry Andric __tzcnt_u64(unsigned long long __X) 122a7dea167SDimitry Andric { 123a7dea167SDimitry Andric return __builtin_ia32_tzcnt_u64(__X); 124a7dea167SDimitry Andric } 125a7dea167SDimitry Andric 126a7dea167SDimitry Andric /// Counts the number of trailing zero bits in the operand. 127a7dea167SDimitry Andric /// 128a7dea167SDimitry Andric /// \headerfile <x86intrin.h> 129a7dea167SDimitry Andric /// 1307a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 131a7dea167SDimitry Andric /// 132a7dea167SDimitry Andric /// \param __X 133a7dea167SDimitry Andric /// An unsigned 64-bit integer whose trailing zeros are to be counted. 134a7dea167SDimitry Andric /// \returns An 64-bit integer containing the number of trailing zero bits in 135a7dea167SDimitry Andric /// the operand. 1367a6dacacSDimitry Andric /// \see { __tzcnt_u64 _tzcnt_u64 } 137a7dea167SDimitry Andric static __inline__ long long __RELAXED_FN_ATTRS 138a7dea167SDimitry Andric _mm_tzcnt_64(unsigned long long __X) 139a7dea167SDimitry Andric { 14081ad6265SDimitry Andric return (long long)__builtin_ia32_tzcnt_u64(__X); 141a7dea167SDimitry Andric } 142a7dea167SDimitry Andric 1437a6dacacSDimitry Andric /// Counts the number of trailing zero bits in the operand. 1447a6dacacSDimitry Andric /// 1457a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 1467a6dacacSDimitry Andric /// 1477a6dacacSDimitry Andric /// \code 1487a6dacacSDimitry Andric /// unsigned long long _tzcnt_u64(unsigned long long __X); 1497a6dacacSDimitry Andric /// \endcode 1507a6dacacSDimitry Andric /// 1517a6dacacSDimitry Andric /// This intrinsic corresponds to the \c TZCNT instruction. 1527a6dacacSDimitry Andric /// 1537a6dacacSDimitry Andric /// \param __X 1547a6dacacSDimitry Andric /// An unsigned 64-bit integer whose trailing zeros are to be counted. 1557a6dacacSDimitry Andric /// \returns An unsigned 64-bit integer containing the number of trailing zero 1567a6dacacSDimitry Andric /// bits in the operand. 1577a6dacacSDimitry Andric /// \see { _mm_tzcnt_64 __tzcnt_u64 1585f757f3fSDimitry Andric #define _tzcnt_u64 __tzcnt_u64 159a7dea167SDimitry Andric 160a7dea167SDimitry Andric #endif /* __x86_64__ */ 161a7dea167SDimitry Andric 162a7dea167SDimitry Andric #undef __RELAXED_FN_ATTRS 163a7dea167SDimitry Andric 164*0fca6ea1SDimitry Andric #if !defined(__SCE__) || __has_feature(modules) || defined(__BMI__) 165a7dea167SDimitry Andric 166a7dea167SDimitry Andric /* Define the default attributes for the functions in this file. */ 167a7dea167SDimitry Andric #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi"))) 168a7dea167SDimitry Andric 1690b57cec5SDimitry Andric /// Performs a bitwise AND of the second operand with the one's 1700b57cec5SDimitry Andric /// complement of the first operand. 1710b57cec5SDimitry Andric /// 1720b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 1730b57cec5SDimitry Andric /// 1747a6dacacSDimitry Andric /// This intrinsic corresponds to the \c ANDN instruction. 1750b57cec5SDimitry Andric /// 1760b57cec5SDimitry Andric /// \param __X 1770b57cec5SDimitry Andric /// An unsigned integer containing one of the operands. 1780b57cec5SDimitry Andric /// \param __Y 1790b57cec5SDimitry Andric /// An unsigned integer containing one of the operands. 1800b57cec5SDimitry Andric /// \returns An unsigned integer containing the bitwise AND of the second 1810b57cec5SDimitry Andric /// operand with the one's complement of the first operand. 1827a6dacacSDimitry Andric /// \see _andn_u32 1830b57cec5SDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 1840b57cec5SDimitry Andric __andn_u32(unsigned int __X, unsigned int __Y) 1850b57cec5SDimitry Andric { 1860b57cec5SDimitry Andric return ~__X & __Y; 1870b57cec5SDimitry Andric } 1880b57cec5SDimitry Andric 1897a6dacacSDimitry Andric /// Performs a bitwise AND of the second operand with the one's 1907a6dacacSDimitry Andric /// complement of the first operand. 1917a6dacacSDimitry Andric /// 1927a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 1937a6dacacSDimitry Andric /// 1947a6dacacSDimitry Andric /// \code 1957a6dacacSDimitry Andric /// unsigned int _andn_u32(unsigned int __X, unsigned int __Y); 1967a6dacacSDimitry Andric /// \endcode 1977a6dacacSDimitry Andric /// 1987a6dacacSDimitry Andric /// This intrinsic corresponds to the \c ANDN instruction. 1997a6dacacSDimitry Andric /// 2007a6dacacSDimitry Andric /// \param __X 2017a6dacacSDimitry Andric /// An unsigned integer containing one of the operands. 2027a6dacacSDimitry Andric /// \param __Y 2037a6dacacSDimitry Andric /// An unsigned integer containing one of the operands. 2047a6dacacSDimitry Andric /// \returns An unsigned integer containing the bitwise AND of the second 2057a6dacacSDimitry Andric /// operand with the one's complement of the first operand. 2067a6dacacSDimitry Andric /// \see __andn_u32 2077a6dacacSDimitry Andric #define _andn_u32 __andn_u32 2087a6dacacSDimitry Andric 2090b57cec5SDimitry Andric /* AMD-specified, double-leading-underscore version of BEXTR */ 2100b57cec5SDimitry Andric /// Extracts the specified bits from the first operand and returns them 2110b57cec5SDimitry Andric /// in the least significant bits of the result. 2120b57cec5SDimitry Andric /// 2130b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 2140b57cec5SDimitry Andric /// 2157a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 2160b57cec5SDimitry Andric /// 2170b57cec5SDimitry Andric /// \param __X 2180b57cec5SDimitry Andric /// An unsigned integer whose bits are to be extracted. 2190b57cec5SDimitry Andric /// \param __Y 2200b57cec5SDimitry Andric /// An unsigned integer used to specify which bits are extracted. Bits [7:0] 2210b57cec5SDimitry Andric /// specify the index of the least significant bit. Bits [15:8] specify the 2220b57cec5SDimitry Andric /// number of bits to be extracted. 2230b57cec5SDimitry Andric /// \returns An unsigned integer whose least significant bits contain the 2240b57cec5SDimitry Andric /// extracted bits. 2250b57cec5SDimitry Andric /// \see _bextr_u32 2260b57cec5SDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 2270b57cec5SDimitry Andric __bextr_u32(unsigned int __X, unsigned int __Y) 2280b57cec5SDimitry Andric { 2290b57cec5SDimitry Andric return __builtin_ia32_bextr_u32(__X, __Y); 2300b57cec5SDimitry Andric } 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andric /* Intel-specified, single-leading-underscore version of BEXTR */ 2330b57cec5SDimitry Andric /// Extracts the specified bits from the first operand and returns them 2340b57cec5SDimitry Andric /// in the least significant bits of the result. 2350b57cec5SDimitry Andric /// 2360b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 2370b57cec5SDimitry Andric /// 2387a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 2390b57cec5SDimitry Andric /// 2400b57cec5SDimitry Andric /// \param __X 2410b57cec5SDimitry Andric /// An unsigned integer whose bits are to be extracted. 2420b57cec5SDimitry Andric /// \param __Y 2430b57cec5SDimitry Andric /// An unsigned integer used to specify the index of the least significant 2440b57cec5SDimitry Andric /// bit for the bits to be extracted. Bits [7:0] specify the index. 2450b57cec5SDimitry Andric /// \param __Z 2460b57cec5SDimitry Andric /// An unsigned integer used to specify the number of bits to be extracted. 2470b57cec5SDimitry Andric /// Bits [7:0] specify the number of bits. 2480b57cec5SDimitry Andric /// \returns An unsigned integer whose least significant bits contain the 2490b57cec5SDimitry Andric /// extracted bits. 2500b57cec5SDimitry Andric /// \see __bextr_u32 2510b57cec5SDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 2520b57cec5SDimitry Andric _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z) 2530b57cec5SDimitry Andric { 2540b57cec5SDimitry Andric return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); 2550b57cec5SDimitry Andric } 2560b57cec5SDimitry Andric 2575ffd83dbSDimitry Andric /* Intel-specified, single-leading-underscore version of BEXTR2 */ 2585ffd83dbSDimitry Andric /// Extracts the specified bits from the first operand and returns them 2595ffd83dbSDimitry Andric /// in the least significant bits of the result. 2605ffd83dbSDimitry Andric /// 2615ffd83dbSDimitry Andric /// \headerfile <x86intrin.h> 2625ffd83dbSDimitry Andric /// 2637a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 2645ffd83dbSDimitry Andric /// 2655ffd83dbSDimitry Andric /// \param __X 2665ffd83dbSDimitry Andric /// An unsigned integer whose bits are to be extracted. 2675ffd83dbSDimitry Andric /// \param __Y 2685ffd83dbSDimitry Andric /// An unsigned integer used to specify which bits are extracted. Bits [7:0] 2695ffd83dbSDimitry Andric /// specify the index of the least significant bit. Bits [15:8] specify the 2705ffd83dbSDimitry Andric /// number of bits to be extracted. 2715ffd83dbSDimitry Andric /// \returns An unsigned integer whose least significant bits contain the 2725ffd83dbSDimitry Andric /// extracted bits. 2735ffd83dbSDimitry Andric /// \see __bextr_u32 2745ffd83dbSDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 2755ffd83dbSDimitry Andric _bextr2_u32(unsigned int __X, unsigned int __Y) { 2765ffd83dbSDimitry Andric return __builtin_ia32_bextr_u32(__X, __Y); 2775ffd83dbSDimitry Andric } 2785ffd83dbSDimitry Andric 2790b57cec5SDimitry Andric /// Clears all bits in the source except for the least significant bit 2800b57cec5SDimitry Andric /// containing a value of 1 and returns the result. 2810b57cec5SDimitry Andric /// 2820b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 2830b57cec5SDimitry Andric /// 2847a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSI instruction. 2850b57cec5SDimitry Andric /// 2860b57cec5SDimitry Andric /// \param __X 2870b57cec5SDimitry Andric /// An unsigned integer whose bits are to be cleared. 2880b57cec5SDimitry Andric /// \returns An unsigned integer containing the result of clearing the bits from 2890b57cec5SDimitry Andric /// the source operand. 2907a6dacacSDimitry Andric /// \see _blsi_u32 2910b57cec5SDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 2920b57cec5SDimitry Andric __blsi_u32(unsigned int __X) 2930b57cec5SDimitry Andric { 2940b57cec5SDimitry Andric return __X & -__X; 2950b57cec5SDimitry Andric } 2960b57cec5SDimitry Andric 2977a6dacacSDimitry Andric /// Clears all bits in the source except for the least significant bit 2987a6dacacSDimitry Andric /// containing a value of 1 and returns the result. 2997a6dacacSDimitry Andric /// 3007a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 3017a6dacacSDimitry Andric /// 3027a6dacacSDimitry Andric /// \code 3037a6dacacSDimitry Andric /// unsigned int _blsi_u32(unsigned int __X); 3047a6dacacSDimitry Andric /// \endcode 3057a6dacacSDimitry Andric /// 3067a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSI instruction. 3077a6dacacSDimitry Andric /// 3087a6dacacSDimitry Andric /// \param __X 3097a6dacacSDimitry Andric /// An unsigned integer whose bits are to be cleared. 3107a6dacacSDimitry Andric /// \returns An unsigned integer containing the result of clearing the bits from 3117a6dacacSDimitry Andric /// the source operand. 3127a6dacacSDimitry Andric /// \see __blsi_u32 3137a6dacacSDimitry Andric #define _blsi_u32 __blsi_u32 3147a6dacacSDimitry Andric 3157a6dacacSDimitry Andric /// Creates a mask whose bits are set to 1, using bit 0 up to and 3167a6dacacSDimitry Andric /// including the least significant bit that is set to 1 in the source 3177a6dacacSDimitry Andric /// operand and returns the result. 3187a6dacacSDimitry Andric /// 3197a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 3207a6dacacSDimitry Andric /// 3217a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSMSK instruction. 3227a6dacacSDimitry Andric /// 3237a6dacacSDimitry Andric /// \param __X 3247a6dacacSDimitry Andric /// An unsigned integer used to create the mask. 3257a6dacacSDimitry Andric /// \returns An unsigned integer containing the newly created mask. 3267a6dacacSDimitry Andric /// \see _blsmsk_u32 3277a6dacacSDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 3287a6dacacSDimitry Andric __blsmsk_u32(unsigned int __X) 3297a6dacacSDimitry Andric { 3307a6dacacSDimitry Andric return __X ^ (__X - 1); 3317a6dacacSDimitry Andric } 3327a6dacacSDimitry Andric 3330b57cec5SDimitry Andric /// Creates a mask whose bits are set to 1, using bit 0 up to and 3340b57cec5SDimitry Andric /// including the least significant bit that is set to 1 in the source 3350b57cec5SDimitry Andric /// operand and returns the result. 3360b57cec5SDimitry Andric /// 3370b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 3380b57cec5SDimitry Andric /// 3397a6dacacSDimitry Andric /// \code 3407a6dacacSDimitry Andric /// unsigned int _blsmsk_u32(unsigned int __X); 3417a6dacacSDimitry Andric /// \endcode 3427a6dacacSDimitry Andric /// 3437a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSMSK instruction. 3440b57cec5SDimitry Andric /// 3450b57cec5SDimitry Andric /// \param __X 3460b57cec5SDimitry Andric /// An unsigned integer used to create the mask. 3470b57cec5SDimitry Andric /// \returns An unsigned integer containing the newly created mask. 3487a6dacacSDimitry Andric /// \see __blsmsk_u32 3497a6dacacSDimitry Andric #define _blsmsk_u32 __blsmsk_u32 3507a6dacacSDimitry Andric 3517a6dacacSDimitry Andric /// Clears the least significant bit that is set to 1 in the source 3527a6dacacSDimitry Andric /// operand and returns the result. 3537a6dacacSDimitry Andric /// 3547a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 3557a6dacacSDimitry Andric /// 3567a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSR instruction. 3577a6dacacSDimitry Andric /// 3587a6dacacSDimitry Andric /// \param __X 3597a6dacacSDimitry Andric /// An unsigned integer containing the operand to be cleared. 3607a6dacacSDimitry Andric /// \returns An unsigned integer containing the result of clearing the source 3617a6dacacSDimitry Andric /// operand. 3627a6dacacSDimitry Andric /// \see _blsr_u32 3630b57cec5SDimitry Andric static __inline__ unsigned int __DEFAULT_FN_ATTRS 3647a6dacacSDimitry Andric __blsr_u32(unsigned int __X) 3650b57cec5SDimitry Andric { 3667a6dacacSDimitry Andric return __X & (__X - 1); 3670b57cec5SDimitry Andric } 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric /// Clears the least significant bit that is set to 1 in the source 3700b57cec5SDimitry Andric /// operand and returns the result. 3710b57cec5SDimitry Andric /// 3720b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 3730b57cec5SDimitry Andric /// 3747a6dacacSDimitry Andric /// \code 3757a6dacacSDimitry Andric /// unsigned int _bls4_u32(unsigned int __X); 3767a6dacacSDimitry Andric /// \endcode 3777a6dacacSDimitry Andric /// 3787a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSR instruction. 3790b57cec5SDimitry Andric /// 3800b57cec5SDimitry Andric /// \param __X 3810b57cec5SDimitry Andric /// An unsigned integer containing the operand to be cleared. 3820b57cec5SDimitry Andric /// \returns An unsigned integer containing the result of clearing the source 3830b57cec5SDimitry Andric /// operand. 3847a6dacacSDimitry Andric /// \see __blsr_u32 3857a6dacacSDimitry Andric #define _blsr_u32 __blsr_u32 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric #ifdef __x86_64__ 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric /// Performs a bitwise AND of the second operand with the one's 3900b57cec5SDimitry Andric /// complement of the first operand. 3910b57cec5SDimitry Andric /// 3920b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 3930b57cec5SDimitry Andric /// 3947a6dacacSDimitry Andric /// This intrinsic corresponds to the \c ANDN instruction. 3950b57cec5SDimitry Andric /// 3960b57cec5SDimitry Andric /// \param __X 3970b57cec5SDimitry Andric /// An unsigned 64-bit integer containing one of the operands. 3980b57cec5SDimitry Andric /// \param __Y 3990b57cec5SDimitry Andric /// An unsigned 64-bit integer containing one of the operands. 4000b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer containing the bitwise AND of the second 4010b57cec5SDimitry Andric /// operand with the one's complement of the first operand. 4027a6dacacSDimitry Andric /// \see _andn_u64 4030b57cec5SDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 4040b57cec5SDimitry Andric __andn_u64 (unsigned long long __X, unsigned long long __Y) 4050b57cec5SDimitry Andric { 4060b57cec5SDimitry Andric return ~__X & __Y; 4070b57cec5SDimitry Andric } 4080b57cec5SDimitry Andric 4097a6dacacSDimitry Andric /// Performs a bitwise AND of the second operand with the one's 4107a6dacacSDimitry Andric /// complement of the first operand. 4117a6dacacSDimitry Andric /// 4127a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 4137a6dacacSDimitry Andric /// 4147a6dacacSDimitry Andric /// \code 4157a6dacacSDimitry Andric /// unsigned long long _andn_u64(unsigned long long __X, 4167a6dacacSDimitry Andric /// unsigned long long __Y); 4177a6dacacSDimitry Andric /// \endcode 4187a6dacacSDimitry Andric /// 4197a6dacacSDimitry Andric /// This intrinsic corresponds to the \c ANDN instruction. 4207a6dacacSDimitry Andric /// 4217a6dacacSDimitry Andric /// \param __X 4227a6dacacSDimitry Andric /// An unsigned 64-bit integer containing one of the operands. 4237a6dacacSDimitry Andric /// \param __Y 4247a6dacacSDimitry Andric /// An unsigned 64-bit integer containing one of the operands. 4257a6dacacSDimitry Andric /// \returns An unsigned 64-bit integer containing the bitwise AND of the second 4267a6dacacSDimitry Andric /// operand with the one's complement of the first operand. 4277a6dacacSDimitry Andric /// \see __andn_u64 4287a6dacacSDimitry Andric #define _andn_u64 __andn_u64 4297a6dacacSDimitry Andric 4300b57cec5SDimitry Andric /* AMD-specified, double-leading-underscore version of BEXTR */ 4310b57cec5SDimitry Andric /// Extracts the specified bits from the first operand and returns them 4320b57cec5SDimitry Andric /// in the least significant bits of the result. 4330b57cec5SDimitry Andric /// 4340b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 4350b57cec5SDimitry Andric /// 4367a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 4370b57cec5SDimitry Andric /// 4380b57cec5SDimitry Andric /// \param __X 4390b57cec5SDimitry Andric /// An unsigned 64-bit integer whose bits are to be extracted. 4400b57cec5SDimitry Andric /// \param __Y 4410b57cec5SDimitry Andric /// An unsigned 64-bit integer used to specify which bits are extracted. Bits 4420b57cec5SDimitry Andric /// [7:0] specify the index of the least significant bit. Bits [15:8] specify 4430b57cec5SDimitry Andric /// the number of bits to be extracted. 4440b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer whose least significant bits contain the 4450b57cec5SDimitry Andric /// extracted bits. 4460b57cec5SDimitry Andric /// \see _bextr_u64 4470b57cec5SDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 4480b57cec5SDimitry Andric __bextr_u64(unsigned long long __X, unsigned long long __Y) 4490b57cec5SDimitry Andric { 4500b57cec5SDimitry Andric return __builtin_ia32_bextr_u64(__X, __Y); 4510b57cec5SDimitry Andric } 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric /* Intel-specified, single-leading-underscore version of BEXTR */ 4540b57cec5SDimitry Andric /// Extracts the specified bits from the first operand and returns them 4550b57cec5SDimitry Andric /// in the least significant bits of the result. 4560b57cec5SDimitry Andric /// 4570b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 4580b57cec5SDimitry Andric /// 4597a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 4600b57cec5SDimitry Andric /// 4610b57cec5SDimitry Andric /// \param __X 4620b57cec5SDimitry Andric /// An unsigned 64-bit integer whose bits are to be extracted. 4630b57cec5SDimitry Andric /// \param __Y 4640b57cec5SDimitry Andric /// An unsigned integer used to specify the index of the least significant 4650b57cec5SDimitry Andric /// bit for the bits to be extracted. Bits [7:0] specify the index. 4660b57cec5SDimitry Andric /// \param __Z 4670b57cec5SDimitry Andric /// An unsigned integer used to specify the number of bits to be extracted. 4680b57cec5SDimitry Andric /// Bits [7:0] specify the number of bits. 4690b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer whose least significant bits contain the 4700b57cec5SDimitry Andric /// extracted bits. 4710b57cec5SDimitry Andric /// \see __bextr_u64 4720b57cec5SDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 4730b57cec5SDimitry Andric _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z) 4740b57cec5SDimitry Andric { 4750b57cec5SDimitry Andric return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); 4760b57cec5SDimitry Andric } 4770b57cec5SDimitry Andric 4785ffd83dbSDimitry Andric /* Intel-specified, single-leading-underscore version of BEXTR2 */ 4795ffd83dbSDimitry Andric /// Extracts the specified bits from the first operand and returns them 4805ffd83dbSDimitry Andric /// in the least significant bits of the result. 4815ffd83dbSDimitry Andric /// 4825ffd83dbSDimitry Andric /// \headerfile <x86intrin.h> 4835ffd83dbSDimitry Andric /// 4847a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BEXTR instruction. 4855ffd83dbSDimitry Andric /// 4865ffd83dbSDimitry Andric /// \param __X 4875ffd83dbSDimitry Andric /// An unsigned 64-bit integer whose bits are to be extracted. 4885ffd83dbSDimitry Andric /// \param __Y 4895ffd83dbSDimitry Andric /// An unsigned 64-bit integer used to specify which bits are extracted. Bits 4905ffd83dbSDimitry Andric /// [7:0] specify the index of the least significant bit. Bits [15:8] specify 4915ffd83dbSDimitry Andric /// the number of bits to be extracted. 4925ffd83dbSDimitry Andric /// \returns An unsigned 64-bit integer whose least significant bits contain the 4935ffd83dbSDimitry Andric /// extracted bits. 4945ffd83dbSDimitry Andric /// \see __bextr_u64 4955ffd83dbSDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 4965ffd83dbSDimitry Andric _bextr2_u64(unsigned long long __X, unsigned long long __Y) { 4975ffd83dbSDimitry Andric return __builtin_ia32_bextr_u64(__X, __Y); 4985ffd83dbSDimitry Andric } 4995ffd83dbSDimitry Andric 5000b57cec5SDimitry Andric /// Clears all bits in the source except for the least significant bit 5010b57cec5SDimitry Andric /// containing a value of 1 and returns the result. 5020b57cec5SDimitry Andric /// 5030b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 5040b57cec5SDimitry Andric /// 5057a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSI instruction. 5060b57cec5SDimitry Andric /// 5070b57cec5SDimitry Andric /// \param __X 5080b57cec5SDimitry Andric /// An unsigned 64-bit integer whose bits are to be cleared. 5090b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer containing the result of clearing the 5100b57cec5SDimitry Andric /// bits from the source operand. 5117a6dacacSDimitry Andric /// \see _blsi_u64 5120b57cec5SDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 5130b57cec5SDimitry Andric __blsi_u64(unsigned long long __X) 5140b57cec5SDimitry Andric { 5150b57cec5SDimitry Andric return __X & -__X; 5160b57cec5SDimitry Andric } 5170b57cec5SDimitry Andric 5187a6dacacSDimitry Andric /// Clears all bits in the source except for the least significant bit 5197a6dacacSDimitry Andric /// containing a value of 1 and returns the result. 5207a6dacacSDimitry Andric /// 5217a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 5227a6dacacSDimitry Andric /// 5237a6dacacSDimitry Andric /// \code 5247a6dacacSDimitry Andric /// unsigned long long _blsi_u64(unsigned long long __X); 5257a6dacacSDimitry Andric /// \endcode 5267a6dacacSDimitry Andric /// 5277a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSI instruction. 5287a6dacacSDimitry Andric /// 5297a6dacacSDimitry Andric /// \param __X 5307a6dacacSDimitry Andric /// An unsigned 64-bit integer whose bits are to be cleared. 5317a6dacacSDimitry Andric /// \returns An unsigned 64-bit integer containing the result of clearing the 5327a6dacacSDimitry Andric /// bits from the source operand. 5337a6dacacSDimitry Andric /// \see __blsi_u64 5347a6dacacSDimitry Andric #define _blsi_u64 __blsi_u64 5357a6dacacSDimitry Andric 5367a6dacacSDimitry Andric /// Creates a mask whose bits are set to 1, using bit 0 up to and 5377a6dacacSDimitry Andric /// including the least significant bit that is set to 1 in the source 5387a6dacacSDimitry Andric /// operand and returns the result. 5397a6dacacSDimitry Andric /// 5407a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 5417a6dacacSDimitry Andric /// 5427a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSMSK instruction. 5437a6dacacSDimitry Andric /// 5447a6dacacSDimitry Andric /// \param __X 5457a6dacacSDimitry Andric /// An unsigned 64-bit integer used to create the mask. 5467a6dacacSDimitry Andric /// \returns An unsigned 64-bit integer containing the newly created mask. 5477a6dacacSDimitry Andric /// \see _blsmsk_u64 5487a6dacacSDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 5497a6dacacSDimitry Andric __blsmsk_u64(unsigned long long __X) 5507a6dacacSDimitry Andric { 5517a6dacacSDimitry Andric return __X ^ (__X - 1); 5527a6dacacSDimitry Andric } 5537a6dacacSDimitry Andric 5540b57cec5SDimitry Andric /// Creates a mask whose bits are set to 1, using bit 0 up to and 5550b57cec5SDimitry Andric /// including the least significant bit that is set to 1 in the source 5560b57cec5SDimitry Andric /// operand and returns the result. 5570b57cec5SDimitry Andric /// 5580b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 5590b57cec5SDimitry Andric /// 5607a6dacacSDimitry Andric /// \code 5617a6dacacSDimitry Andric /// unsigned long long _blsmsk_u64(unsigned long long __X); 5627a6dacacSDimitry Andric /// \endcode 5637a6dacacSDimitry Andric /// 5647a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSMSK instruction. 5650b57cec5SDimitry Andric /// 5660b57cec5SDimitry Andric /// \param __X 5670b57cec5SDimitry Andric /// An unsigned 64-bit integer used to create the mask. 5680b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer containing the newly created mask. 5697a6dacacSDimitry Andric /// \see __blsmsk_u64 5707a6dacacSDimitry Andric #define _blsmsk_u64 __blsmsk_u64 5717a6dacacSDimitry Andric 5727a6dacacSDimitry Andric /// Clears the least significant bit that is set to 1 in the source 5737a6dacacSDimitry Andric /// operand and returns the result. 5747a6dacacSDimitry Andric /// 5757a6dacacSDimitry Andric /// \headerfile <x86intrin.h> 5767a6dacacSDimitry Andric /// 5777a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSR instruction. 5787a6dacacSDimitry Andric /// 5797a6dacacSDimitry Andric /// \param __X 5807a6dacacSDimitry Andric /// An unsigned 64-bit integer containing the operand to be cleared. 5817a6dacacSDimitry Andric /// \returns An unsigned 64-bit integer containing the result of clearing the 5827a6dacacSDimitry Andric /// source operand. 5837a6dacacSDimitry Andric /// \see _blsr_u64 5840b57cec5SDimitry Andric static __inline__ unsigned long long __DEFAULT_FN_ATTRS 5857a6dacacSDimitry Andric __blsr_u64(unsigned long long __X) 5860b57cec5SDimitry Andric { 5877a6dacacSDimitry Andric return __X & (__X - 1); 5880b57cec5SDimitry Andric } 5890b57cec5SDimitry Andric 5900b57cec5SDimitry Andric /// Clears the least significant bit that is set to 1 in the source 5910b57cec5SDimitry Andric /// operand and returns the result. 5920b57cec5SDimitry Andric /// 5930b57cec5SDimitry Andric /// \headerfile <x86intrin.h> 5940b57cec5SDimitry Andric /// 5957a6dacacSDimitry Andric /// \code 5967a6dacacSDimitry Andric /// unsigned long long _blsr_u64(unsigned long long __X); 5977a6dacacSDimitry Andric /// \endcode 5987a6dacacSDimitry Andric /// 5997a6dacacSDimitry Andric /// This intrinsic corresponds to the \c BLSR instruction. 6000b57cec5SDimitry Andric /// 6010b57cec5SDimitry Andric /// \param __X 6020b57cec5SDimitry Andric /// An unsigned 64-bit integer containing the operand to be cleared. 6030b57cec5SDimitry Andric /// \returns An unsigned 64-bit integer containing the result of clearing the 6040b57cec5SDimitry Andric /// source operand. 6057a6dacacSDimitry Andric /// \see __blsr_u64 6067a6dacacSDimitry Andric #define _blsr_u64 __blsr_u64 6070b57cec5SDimitry Andric 6080b57cec5SDimitry Andric #endif /* __x86_64__ */ 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS 611a7dea167SDimitry Andric 612*0fca6ea1SDimitry Andric #endif /* !defined(__SCE__) || __has_feature(modules) || defined(__BMI__) */ 6130b57cec5SDimitry Andric 6140b57cec5SDimitry Andric #endif /* __BMIINTRIN_H */ 615