Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 1 | /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------=== |
| 2 | * |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [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 |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [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 | |
| 14 | #ifndef __LZCNTINTRIN_H |
| 15 | #define __LZCNTINTRIN_H |
| 16 | |
| 17 | /* Define the default attributes for the functions in this file. */ |
| 18 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt"))) |
| 19 | |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 20 | #ifndef _MSC_VER |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 21 | /// Counts the number of leading zero bits in the operand. |
| 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. |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 31 | #define __lzcnt16(X) __builtin_ia32_lzcnt_u16((unsigned short)(X)) |
| 32 | #endif // _MSC_VER |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 33 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 34 | /// Counts the number of leading zero bits in the operand. |
| 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. |
| 44 | /// \see _lzcnt_u32 |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 45 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| 46 | __lzcnt32(unsigned int __X) |
| 47 | { |
Logan Chien | b0c8402 | 2018-11-09 16:19:54 +0800 | [diff] [blame] | 48 | return __builtin_ia32_lzcnt_u32(__X); |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 51 | /// Counts the number of leading zero bits in the operand. |
| 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. |
| 61 | /// \see __lzcnt32 |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 62 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| 63 | _lzcnt_u32(unsigned int __X) |
| 64 | { |
Logan Chien | b0c8402 | 2018-11-09 16:19:54 +0800 | [diff] [blame] | 65 | return __builtin_ia32_lzcnt_u32(__X); |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | #ifdef __x86_64__ |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 69 | #ifndef _MSC_VER |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 70 | /// Counts the number of leading zero bits in the operand. |
| 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. |
| 80 | /// \see _lzcnt_u64 |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 81 | #define __lzcnt64(X) __builtin_ia32_lzcnt_u64((unsigned long long)(X)) |
| 82 | #endif // _MSC_VER |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 83 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 84 | /// Counts the number of leading zero bits in the operand. |
| 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. |
| 94 | /// \see __lzcnt64 |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 95 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| 96 | _lzcnt_u64(unsigned long long __X) |
| 97 | { |
Logan Chien | b0c8402 | 2018-11-09 16:19:54 +0800 | [diff] [blame] | 98 | return __builtin_ia32_lzcnt_u64(__X); |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 99 | } |
| 100 | #endif |
| 101 | |
| 102 | #undef __DEFAULT_FN_ATTRS |
| 103 | |
| 104 | #endif /* __LZCNTINTRIN_H */ |