Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 1 | /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------=== |
| 2 | * |
Chandler Carruth | 4cf5743 | 2019-04-08 20:51:30 +0000 | [diff] [blame] | 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 |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 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 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 14 | #ifndef __LZCNTINTRIN_H |
| 15 | #define __LZCNTINTRIN_H |
| 16 | |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 17 | /* Define the default attributes for the functions in this file. */ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 18 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 19 | |
Craig Topper | 1f2b181 | 2018-12-14 00:21:02 +0000 | [diff] [blame] | 20 | #ifndef _MSC_VER |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 21 | /// Counts the number of leading zero bits in the operand. |
Ekaterina Romanova | 06b1914 | 2016-11-18 06:26:01 +0000 | [diff] [blame] | 22 | /// |
| 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 Topper | 1f2b181 | 2018-12-14 00:21:02 +0000 | [diff] [blame] | 31 | #define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X)) |
| 32 | #endif // _MSC_VER |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 33 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 34 | /// Counts the number of leading zero bits in the operand. |
Ekaterina Romanova | 06b1914 | 2016-11-18 06:26:01 +0000 | [diff] [blame] | 35 | /// |
| 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 Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame] | 44 | /// \see _lzcnt_u32 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 45 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 46 | __lzcnt32(unsigned int __X) |
| 47 | { |
Craig Topper | fb5d9f2 | 2018-09-26 17:01:44 +0000 | [diff] [blame] | 48 | return __builtin_ia32_lzcnt_u32(__X); |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 51 | /// Counts the number of leading zero bits in the operand. |
Ekaterina Romanova | 06b1914 | 2016-11-18 06:26:01 +0000 | [diff] [blame] | 52 | /// |
| 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 Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame] | 61 | /// \see __lzcnt32 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 62 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | e1c664b | 2014-11-01 22:50:57 +0000 | [diff] [blame] | 63 | _lzcnt_u32(unsigned int __X) |
| 64 | { |
Craig Topper | fb5d9f2 | 2018-09-26 17:01:44 +0000 | [diff] [blame] | 65 | return __builtin_ia32_lzcnt_u32(__X); |
Craig Topper | e1c664b | 2014-11-01 22:50:57 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 68 | #ifdef __x86_64__ |
Craig Topper | 1f2b181 | 2018-12-14 00:21:02 +0000 | [diff] [blame] | 69 | #ifndef _MSC_VER |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 70 | /// Counts the number of leading zero bits in the operand. |
Ekaterina Romanova | 06b1914 | 2016-11-18 06:26:01 +0000 | [diff] [blame] | 71 | /// |
| 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 Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame] | 80 | /// \see _lzcnt_u64 |
Craig Topper | 1f2b181 | 2018-12-14 00:21:02 +0000 | [diff] [blame] | 81 | #define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X)) |
| 82 | #endif // _MSC_VER |
Craig Topper | e1c664b | 2014-11-01 22:50:57 +0000 | [diff] [blame] | 83 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 84 | /// Counts the number of leading zero bits in the operand. |
Ekaterina Romanova | 06b1914 | 2016-11-18 06:26:01 +0000 | [diff] [blame] | 85 | /// |
| 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 Romanova | 9b41215 | 2018-05-23 06:33:22 +0000 | [diff] [blame] | 94 | /// \see __lzcnt64 |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 95 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | e1c664b | 2014-11-01 22:50:57 +0000 | [diff] [blame] | 96 | _lzcnt_u64(unsigned long long __X) |
| 97 | { |
Craig Topper | fb5d9f2 | 2018-09-26 17:01:44 +0000 | [diff] [blame] | 98 | return __builtin_ia32_lzcnt_u64(__X); |
Craig Topper | e1c664b | 2014-11-01 22:50:57 +0000 | [diff] [blame] | 99 | } |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 100 | #endif |
| 101 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 102 | #undef __DEFAULT_FN_ATTRS |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 103 | |
Craig Topper | f2855ad | 2011-12-25 06:25:37 +0000 | [diff] [blame] | 104 | #endif /* __LZCNTINTRIN_H */ |