1234287Sdim/*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------=== 2234287Sdim * 3353358Sdim * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim * See https://llvm.org/LICENSE.txt for license information. 5353358Sdim * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6234287Sdim * 7234287Sdim *===-----------------------------------------------------------------------=== 8234287Sdim */ 9234287Sdim 10234287Sdim#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H 11234287Sdim#error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead." 12234287Sdim#endif 13234287Sdim 14234287Sdim#ifndef __LZCNTINTRIN_H 15234287Sdim#define __LZCNTINTRIN_H 16234287Sdim 17288943Sdim/* Define the default attributes for the functions in this file. */ 18296417Sdim#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) 19288943Sdim 20344779Sdim#ifndef _MSC_VER 21341825Sdim/// Counts the number of leading zero bits in the operand. 22314564Sdim/// 23314564Sdim/// \headerfile <x86intrin.h> 24314564Sdim/// 25314564Sdim/// This intrinsic corresponds to the \c LZCNT instruction. 26314564Sdim/// 27314564Sdim/// \param __X 28314564Sdim/// An unsigned 16-bit integer whose leading zeros are to be counted. 29314564Sdim/// \returns An unsigned 16-bit integer containing the number of leading zero 30314564Sdim/// bits in the operand. 31344779Sdim#define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X)) 32344779Sdim#endif // _MSC_VER 33234287Sdim 34341825Sdim/// Counts the number of leading zero bits in the operand. 35314564Sdim/// 36314564Sdim/// \headerfile <x86intrin.h> 37314564Sdim/// 38314564Sdim/// This intrinsic corresponds to the \c LZCNT instruction. 39314564Sdim/// 40314564Sdim/// \param __X 41314564Sdim/// An unsigned 32-bit integer whose leading zeros are to be counted. 42314564Sdim/// \returns An unsigned 32-bit integer containing the number of leading zero 43314564Sdim/// bits in the operand. 44341825Sdim/// \see _lzcnt_u32 45288943Sdimstatic __inline__ unsigned int __DEFAULT_FN_ATTRS 46234287Sdim__lzcnt32(unsigned int __X) 47234287Sdim{ 48344779Sdim return __builtin_ia32_lzcnt_u32(__X); 49234287Sdim} 50234287Sdim 51341825Sdim/// Counts the number of leading zero bits in the operand. 52314564Sdim/// 53314564Sdim/// \headerfile <x86intrin.h> 54314564Sdim/// 55314564Sdim/// This intrinsic corresponds to the \c LZCNT instruction. 56314564Sdim/// 57314564Sdim/// \param __X 58314564Sdim/// An unsigned 32-bit integer whose leading zeros are to be counted. 59314564Sdim/// \returns An unsigned 32-bit integer containing the number of leading zero 60314564Sdim/// bits in the operand. 61341825Sdim/// \see __lzcnt32 62288943Sdimstatic __inline__ unsigned int __DEFAULT_FN_ATTRS 63280031Sdim_lzcnt_u32(unsigned int __X) 64280031Sdim{ 65344779Sdim return __builtin_ia32_lzcnt_u32(__X); 66280031Sdim} 67280031Sdim 68234287Sdim#ifdef __x86_64__ 69344779Sdim#ifndef _MSC_VER 70341825Sdim/// Counts the number of leading zero bits in the operand. 71314564Sdim/// 72314564Sdim/// \headerfile <x86intrin.h> 73314564Sdim/// 74314564Sdim/// This intrinsic corresponds to the \c LZCNT instruction. 75314564Sdim/// 76314564Sdim/// \param __X 77314564Sdim/// An unsigned 64-bit integer whose leading zeros are to be counted. 78314564Sdim/// \returns An unsigned 64-bit integer containing the number of leading zero 79314564Sdim/// bits in the operand. 80341825Sdim/// \see _lzcnt_u64 81344779Sdim#define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X)) 82344779Sdim#endif // _MSC_VER 83280031Sdim 84341825Sdim/// Counts the number of leading zero bits in the operand. 85314564Sdim/// 86314564Sdim/// \headerfile <x86intrin.h> 87314564Sdim/// 88314564Sdim/// This intrinsic corresponds to the \c LZCNT instruction. 89314564Sdim/// 90314564Sdim/// \param __X 91314564Sdim/// An unsigned 64-bit integer whose leading zeros are to be counted. 92314564Sdim/// \returns An unsigned 64-bit integer containing the number of leading zero 93314564Sdim/// bits in the operand. 94341825Sdim/// \see __lzcnt64 95288943Sdimstatic __inline__ unsigned long long __DEFAULT_FN_ATTRS 96280031Sdim_lzcnt_u64(unsigned long long __X) 97280031Sdim{ 98344779Sdim return __builtin_ia32_lzcnt_u64(__X); 99280031Sdim} 100234287Sdim#endif 101234287Sdim 102288943Sdim#undef __DEFAULT_FN_ATTRS 103288943Sdim 104234287Sdim#endif /* __LZCNTINTRIN_H */ 105