blob: f4ddce9d0e6834ae11ce88a9341aae4778a235e6 [file] [log] [blame]
Craig Topperf2855ad2011-12-25 06:25:37 +00001/*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------===
2 *
Chandler Carruth4cf57432019-04-08 20:51:30 +00003 * 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
Craig Topperf2855ad2011-12-25 06:25:37 +00006 *
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
Craig Topperf2855ad2011-12-25 06:25:37 +000014#ifndef __LZCNTINTRIN_H
15#define __LZCNTINTRIN_H
16
Eric Christopher4d1851682015-06-17 07:09:20 +000017/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000018#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt")))
Eric Christopher4d1851682015-06-17 07:09:20 +000019
Craig Topper1f2b1812018-12-14 00:21:02 +000020#ifndef _MSC_VER
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000021/// Counts the number of leading zero bits in the operand.
Ekaterina Romanova06b19142016-11-18 06:26:01 +000022///
23/// \headerfile <x86intrin.h>
24///
25/// This intrinsic corresponds to the \c LZCNT instruction.
26///
27/// \param __X
28/// An unsigned 16-bit integer whose leading zeros are to be counted.
29/// \returns An unsigned 16-bit integer containing the number of leading zero
30/// bits in the operand.
Craig Topper1f2b1812018-12-14 00:21:02 +000031#define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X))
32#endif // _MSC_VER
Craig Topperf2855ad2011-12-25 06:25:37 +000033
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000034/// Counts the number of leading zero bits in the operand.
Ekaterina Romanova06b19142016-11-18 06:26:01 +000035///
36/// \headerfile <x86intrin.h>
37///
38/// This intrinsic corresponds to the \c LZCNT instruction.
39///
40/// \param __X
41/// An unsigned 32-bit integer whose leading zeros are to be counted.
42/// \returns An unsigned 32-bit integer containing the number of leading zero
43/// bits in the operand.
Ekaterina Romanova9b412152018-05-23 06:33:22 +000044/// \see _lzcnt_u32
Michael Kupersteine45af542015-06-30 13:36:19 +000045static __inline__ unsigned int __DEFAULT_FN_ATTRS
Craig Topperf2855ad2011-12-25 06:25:37 +000046__lzcnt32(unsigned int __X)
47{
Craig Topperfb5d9f22018-09-26 17:01:44 +000048 return __builtin_ia32_lzcnt_u32(__X);
Craig Topperf2855ad2011-12-25 06:25:37 +000049}
50
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000051/// Counts the number of leading zero bits in the operand.
Ekaterina Romanova06b19142016-11-18 06:26:01 +000052///
53/// \headerfile <x86intrin.h>
54///
55/// This intrinsic corresponds to the \c LZCNT instruction.
56///
57/// \param __X
58/// An unsigned 32-bit integer whose leading zeros are to be counted.
59/// \returns An unsigned 32-bit integer containing the number of leading zero
60/// bits in the operand.
Ekaterina Romanova9b412152018-05-23 06:33:22 +000061/// \see __lzcnt32
Michael Kupersteine45af542015-06-30 13:36:19 +000062static __inline__ unsigned int __DEFAULT_FN_ATTRS
Craig Toppere1c664b2014-11-01 22:50:57 +000063_lzcnt_u32(unsigned int __X)
64{
Craig Topperfb5d9f22018-09-26 17:01:44 +000065 return __builtin_ia32_lzcnt_u32(__X);
Craig Toppere1c664b2014-11-01 22:50:57 +000066}
67
Craig Topperf2855ad2011-12-25 06:25:37 +000068#ifdef __x86_64__
Craig Topper1f2b1812018-12-14 00:21:02 +000069#ifndef _MSC_VER
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000070/// Counts the number of leading zero bits in the operand.
Ekaterina Romanova06b19142016-11-18 06:26:01 +000071///
72/// \headerfile <x86intrin.h>
73///
74/// This intrinsic corresponds to the \c LZCNT instruction.
75///
76/// \param __X
77/// An unsigned 64-bit integer whose leading zeros are to be counted.
78/// \returns An unsigned 64-bit integer containing the number of leading zero
79/// bits in the operand.
Ekaterina Romanova9b412152018-05-23 06:33:22 +000080/// \see _lzcnt_u64
Craig Topper1f2b1812018-12-14 00:21:02 +000081#define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X))
82#endif // _MSC_VER
Craig Toppere1c664b2014-11-01 22:50:57 +000083
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000084/// Counts the number of leading zero bits in the operand.
Ekaterina Romanova06b19142016-11-18 06:26:01 +000085///
86/// \headerfile <x86intrin.h>
87///
88/// This intrinsic corresponds to the \c LZCNT instruction.
89///
90/// \param __X
91/// An unsigned 64-bit integer whose leading zeros are to be counted.
92/// \returns An unsigned 64-bit integer containing the number of leading zero
93/// bits in the operand.
Ekaterina Romanova9b412152018-05-23 06:33:22 +000094/// \see __lzcnt64
Michael Kupersteine45af542015-06-30 13:36:19 +000095static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Toppere1c664b2014-11-01 22:50:57 +000096_lzcnt_u64(unsigned long long __X)
97{
Craig Topperfb5d9f22018-09-26 17:01:44 +000098 return __builtin_ia32_lzcnt_u64(__X);
Craig Toppere1c664b2014-11-01 22:50:57 +000099}
Craig Topperf2855ad2011-12-25 06:25:37 +0000100#endif
101
Michael Kupersteine45af542015-06-30 13:36:19 +0000102#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000103
Craig Topperf2855ad2011-12-25 06:25:37 +0000104#endif /* __LZCNTINTRIN_H */