clang 20.0.0git
lzcntintrin.h
Go to the documentation of this file.
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#if defined(__cplusplus) && (__cplusplus >= 201103L)
19#define __DEFAULT_FN_ATTRS \
20 __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) constexpr
21#else
22#define __DEFAULT_FN_ATTRS \
23 __attribute__((__always_inline__, __nodebug__, __target__("lzcnt")))
24#endif
25
26#ifndef _MSC_VER
27/// Counts the number of leading zero bits in the operand.
28///
29/// \headerfile <x86intrin.h>
30///
31/// This intrinsic corresponds to the \c LZCNT instruction.
32///
33/// \param __X
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))
38#endif // _MSC_VER
39
40/// Counts the number of leading zero bits in the operand.
41///
42/// \headerfile <x86intrin.h>
43///
44/// This intrinsic corresponds to the \c LZCNT instruction.
45///
46/// \param __X
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.
50/// \see _lzcnt_u32
51static __inline__ unsigned int __DEFAULT_FN_ATTRS
52__lzcnt32(unsigned int __X) {
53 return __builtin_ia32_lzcnt_u32(__X);
54}
55
56/// Counts the number of leading zero bits in the operand.
57///
58/// \headerfile <x86intrin.h>
59///
60/// This intrinsic corresponds to the \c LZCNT instruction.
61///
62/// \param __X
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.
66/// \see __lzcnt32
67static __inline__ unsigned int __DEFAULT_FN_ATTRS
68_lzcnt_u32(unsigned int __X) {
69 return __builtin_ia32_lzcnt_u32(__X);
70}
71
72#ifdef __x86_64__
73#ifndef _MSC_VER
74/// Counts the number of leading zero bits in the operand.
75///
76/// \headerfile <x86intrin.h>
77///
78/// This intrinsic corresponds to the \c LZCNT instruction.
79///
80/// \param __X
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.
84/// \see _lzcnt_u64
85#define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X))
86#endif // _MSC_VER
87
88/// Counts the number of leading zero bits in the operand.
89///
90/// \headerfile <x86intrin.h>
91///
92/// This intrinsic corresponds to the \c LZCNT instruction.
93///
94/// \param __X
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.
98/// \see __lzcnt64
99static __inline__ unsigned long long __DEFAULT_FN_ATTRS
100_lzcnt_u64(unsigned long long __X) {
101 return __builtin_ia32_lzcnt_u64(__X);
102}
103#endif
104
105#undef __DEFAULT_FN_ATTRS
106
107#endif /* __LZCNTINTRIN_H */
static __inline__ unsigned int __DEFAULT_FN_ATTRS __lzcnt32(unsigned int __X)
Counts the number of leading zero bits in the operand.
Definition: lzcntintrin.h:52
static __inline__ unsigned int __DEFAULT_FN_ATTRS _lzcnt_u32(unsigned int __X)
Counts the number of leading zero bits in the operand.
Definition: lzcntintrin.h:68
#define __DEFAULT_FN_ATTRS
Definition: lzcntintrin.h:22