1 /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------===
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
7 *===-----------------------------------------------------------------------===
10 #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
11 #error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead."
14 #ifndef __LZCNTINTRIN_H
15 #define __LZCNTINTRIN_H
17 /* Define the default attributes for the functions in this file. */
18 #if defined(__cplusplus) && (__cplusplus >= 201103L)
19 #define __DEFAULT_FN_ATTRS \
20 __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) constexpr
22 #define __DEFAULT_FN_ATTRS \
23 __attribute__((__always_inline__, __nodebug__, __target__("lzcnt")))
27 /// Counts the number of leading zero bits in the operand.
29 /// \headerfile <x86intrin.h>
31 /// This intrinsic corresponds to the \c LZCNT instruction.
34 /// An unsigned 16-bit integer whose leading zeros are to be counted.
35 /// \returns An unsigned 16-bit integer containing the number of leading zero
36 /// bits in the operand.
37 #define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X))
40 /// Counts the number of leading zero bits in the operand.
42 /// \headerfile <x86intrin.h>
44 /// This intrinsic corresponds to the \c LZCNT instruction.
47 /// An unsigned 32-bit integer whose leading zeros are to be counted.
48 /// \returns An unsigned 32-bit integer containing the number of leading zero
49 /// bits in the operand.
51 static __inline__
unsigned int __DEFAULT_FN_ATTRS
52 __lzcnt32(unsigned int __X
) {
53 return __builtin_ia32_lzcnt_u32(__X
);
56 /// Counts the number of leading zero bits in the operand.
58 /// \headerfile <x86intrin.h>
60 /// This intrinsic corresponds to the \c LZCNT instruction.
63 /// An unsigned 32-bit integer whose leading zeros are to be counted.
64 /// \returns An unsigned 32-bit integer containing the number of leading zero
65 /// bits in the operand.
67 static __inline__
unsigned int __DEFAULT_FN_ATTRS
68 _lzcnt_u32(unsigned int __X
) {
69 return __builtin_ia32_lzcnt_u32(__X
);
74 /// Counts the number of leading zero bits in the operand.
76 /// \headerfile <x86intrin.h>
78 /// This intrinsic corresponds to the \c LZCNT instruction.
81 /// An unsigned 64-bit integer whose leading zeros are to be counted.
82 /// \returns An unsigned 64-bit integer containing the number of leading zero
83 /// bits in the operand.
85 #define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X))
88 /// Counts the number of leading zero bits in the operand.
90 /// \headerfile <x86intrin.h>
92 /// This intrinsic corresponds to the \c LZCNT instruction.
95 /// An unsigned 64-bit integer whose leading zeros are to be counted.
96 /// \returns An unsigned 64-bit integer containing the number of leading zero
97 /// bits in the operand.
99 static __inline__
unsigned long long __DEFAULT_FN_ATTRS
100 _lzcnt_u64(unsigned long long __X
) {
101 return __builtin_ia32_lzcnt_u64(__X
);
105 #undef __DEFAULT_FN_ATTRS
107 #endif /* __LZCNTINTRIN_H */