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