xref: /minix3/external/bsd/llvm/dist/clang/lib/Headers/lzcntintrin.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------===
2f4a2713aSLionel Sambuc  *
3f4a2713aSLionel Sambuc  * Permission is hereby granted, free of charge, to any person obtaining a copy
4f4a2713aSLionel Sambuc  * of this software and associated documentation files (the "Software"), to deal
5f4a2713aSLionel Sambuc  * in the Software without restriction, including without limitation the rights
6f4a2713aSLionel Sambuc  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7f4a2713aSLionel Sambuc  * copies of the Software, and to permit persons to whom the Software is
8f4a2713aSLionel Sambuc  * furnished to do so, subject to the following conditions:
9f4a2713aSLionel Sambuc  *
10f4a2713aSLionel Sambuc  * The above copyright notice and this permission notice shall be included in
11f4a2713aSLionel Sambuc  * all copies or substantial portions of the Software.
12f4a2713aSLionel Sambuc  *
13f4a2713aSLionel Sambuc  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14f4a2713aSLionel Sambuc  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15f4a2713aSLionel Sambuc  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16f4a2713aSLionel Sambuc  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17f4a2713aSLionel Sambuc  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18f4a2713aSLionel Sambuc  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19f4a2713aSLionel Sambuc  * THE SOFTWARE.
20f4a2713aSLionel Sambuc  *
21f4a2713aSLionel Sambuc  *===-----------------------------------------------------------------------===
22f4a2713aSLionel Sambuc  */
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
25f4a2713aSLionel Sambuc #error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead."
26f4a2713aSLionel Sambuc #endif
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc #ifndef __LZCNT__
29f4a2713aSLionel Sambuc # error "LZCNT instruction is not enabled"
30f4a2713aSLionel Sambuc #endif /* __LZCNT__ */
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc #ifndef __LZCNTINTRIN_H
33f4a2713aSLionel Sambuc #define __LZCNTINTRIN_H
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
__lzcnt16(unsigned short __X)36f4a2713aSLionel Sambuc __lzcnt16(unsigned short __X)
37f4a2713aSLionel Sambuc {
38*0a6a1f1dSLionel Sambuc   return __X ? __builtin_clzs(__X) : 16;
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
__lzcnt32(unsigned int __X)42f4a2713aSLionel Sambuc __lzcnt32(unsigned int __X)
43f4a2713aSLionel Sambuc {
44*0a6a1f1dSLionel Sambuc   return __X ? __builtin_clz(__X) : 32;
45*0a6a1f1dSLionel Sambuc }
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
_lzcnt_u32(unsigned int __X)48*0a6a1f1dSLionel Sambuc _lzcnt_u32(unsigned int __X)
49*0a6a1f1dSLionel Sambuc {
50*0a6a1f1dSLionel Sambuc   return __X ? __builtin_clz(__X) : 32;
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc #ifdef __x86_64__
54f4a2713aSLionel Sambuc static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
__lzcnt64(unsigned long long __X)55f4a2713aSLionel Sambuc __lzcnt64(unsigned long long __X)
56f4a2713aSLionel Sambuc {
57*0a6a1f1dSLionel Sambuc   return __X ? __builtin_clzll(__X) : 64;
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
_lzcnt_u64(unsigned long long __X)61*0a6a1f1dSLionel Sambuc _lzcnt_u64(unsigned long long __X)
62*0a6a1f1dSLionel Sambuc {
63*0a6a1f1dSLionel Sambuc   return __X ? __builtin_clzll(__X) : 64;
64f4a2713aSLionel Sambuc }
65f4a2713aSLionel Sambuc #endif
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc #endif /* __LZCNTINTRIN_H */
68