1 /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------=== 2 * 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 6 * 7 *===-----------------------------------------------------------------------=== 8 */ 9 10 #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H 11 #error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead." 12 #endif 13 14 #ifndef __LZCNTINTRIN_H 15 #define __LZCNTINTRIN_H 16 17 /* Define the default attributes for the functions in this file. */ 18 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) 19 20 #ifndef _MSC_VER 21 /// Counts the number of leading zero bits in the operand. 22 /// 23 /// \headerfile <x86intrin.h> 24 /// 25 /// This intrinsic corresponds to the \c LZCNT instruction. 26 /// 27 /// \param __X 28 /// An unsigned 16-bit integer whose leading zeros are to be counted. 29 /// \returns An unsigned 16-bit integer containing the number of leading zero 30 /// bits in the operand. 31 #define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X)) 32 #endif // _MSC_VER 33 34 /// Counts the number of leading zero bits in the operand. 35 /// 36 /// \headerfile <x86intrin.h> 37 /// 38 /// This intrinsic corresponds to the \c LZCNT instruction. 39 /// 40 /// \param __X 41 /// An unsigned 32-bit integer whose leading zeros are to be counted. 42 /// \returns An unsigned 32-bit integer containing the number of leading zero 43 /// bits in the operand. 44 /// \see _lzcnt_u32 45 static __inline__ unsigned int __DEFAULT_FN_ATTRS 46 __lzcnt32(unsigned int __X) 47 { 48 return __builtin_ia32_lzcnt_u32(__X); 49 } 50 51 /// Counts the number of leading zero bits in the operand. 52 /// 53 /// \headerfile <x86intrin.h> 54 /// 55 /// This intrinsic corresponds to the \c LZCNT instruction. 56 /// 57 /// \param __X 58 /// An unsigned 32-bit integer whose leading zeros are to be counted. 59 /// \returns An unsigned 32-bit integer containing the number of leading zero 60 /// bits in the operand. 61 /// \see __lzcnt32 62 static __inline__ unsigned int __DEFAULT_FN_ATTRS 63 _lzcnt_u32(unsigned int __X) 64 { 65 return __builtin_ia32_lzcnt_u32(__X); 66 } 67 68 #ifdef __x86_64__ 69 #ifndef _MSC_VER 70 /// Counts the number of leading zero bits in the operand. 71 /// 72 /// \headerfile <x86intrin.h> 73 /// 74 /// This intrinsic corresponds to the \c LZCNT instruction. 75 /// 76 /// \param __X 77 /// An unsigned 64-bit integer whose leading zeros are to be counted. 78 /// \returns An unsigned 64-bit integer containing the number of leading zero 79 /// bits in the operand. 80 /// \see _lzcnt_u64 81 #define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X)) 82 #endif // _MSC_VER 83 84 /// Counts the number of leading zero bits in the operand. 85 /// 86 /// \headerfile <x86intrin.h> 87 /// 88 /// This intrinsic corresponds to the \c LZCNT instruction. 89 /// 90 /// \param __X 91 /// An unsigned 64-bit integer whose leading zeros are to be counted. 92 /// \returns An unsigned 64-bit integer containing the number of leading zero 93 /// bits in the operand. 94 /// \see __lzcnt64 95 static __inline__ unsigned long long __DEFAULT_FN_ATTRS 96 _lzcnt_u64(unsigned long long __X) 97 { 98 return __builtin_ia32_lzcnt_u64(__X); 99 } 100 #endif 101 102 #undef __DEFAULT_FN_ATTRS 103 104 #endif /* __LZCNTINTRIN_H */ 105