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