bmiintrin.h revision 234353
1163953Srrs/*===---- bmiintrin.h - BMI intrinsics -------------------------------------===
2169382Srrs *
3163953Srrs * Permission is hereby granted, free of charge, to any person obtaining a copy
4163953Srrs * of this software and associated documentation files (the "Software"), to deal
5163953Srrs * in the Software without restriction, including without limitation the rights
6163953Srrs * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7163953Srrs * copies of the Software, and to permit persons to whom the Software is
8163953Srrs * furnished to do so, subject to the following conditions:
9163953Srrs *
10163953Srrs * The above copyright notice and this permission notice shall be included in
11163953Srrs * all copies or substantial portions of the Software.
12163953Srrs *
13163953Srrs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14163953Srrs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15163953Srrs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16163953Srrs * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17163953Srrs * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18163953Srrs * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19163953Srrs * THE SOFTWARE.
20163953Srrs *
21163953Srrs *===-----------------------------------------------------------------------===
22163953Srrs */
23163953Srrs
24163953Srrs#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
25163953Srrs#error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."
26163953Srrs#endif
27163953Srrs
28163953Srrs#ifndef __BMI__
29163953Srrs# error "BMI instruction set not enabled"
30163953Srrs#endif /* __BMI__ */
31163953Srrs
32163953Srrs#ifndef __BMIINTRIN_H
33163953Srrs#define __BMIINTRIN_H
34163953Srrs
35163953Srrsstatic __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
36163953Srrs__tzcnt16(unsigned short __X)
37163953Srrs{
38167598Srrs  return __builtin_ctzs(__X);
39163953Srrs}
40163953Srrs
41163953Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
42163953Srrs__andn_u32(unsigned int __X, unsigned int __Y)
43163953Srrs{
44163953Srrs  return ~__X & __Y;
45163953Srrs}
46163953Srrs
47170091Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
48163953Srrs__bextr_u32(unsigned int __X, unsigned int __Y)
49163953Srrs{
50163953Srrs  return __builtin_ia32_bextr_u32(__X, __Y);
51163953Srrs}
52163953Srrs
53163953Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
54163953Srrs__blsi_u32(unsigned int __X)
55163953Srrs{
56165220Srrs  return __X & -__X;
57165220Srrs}
58165220Srrs
59165220Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
60165220Srrs__blsmsk_u32(unsigned int __X)
61163953Srrs{
62163953Srrs  return __X ^ (__X - 1);
63165220Srrs}
64163953Srrs
65163953Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
66163953Srrs__blsr_u32(unsigned int __X)
67165220Srrs{
68165220Srrs  return __X & (__X - 1);
69165220Srrs}
70165220Srrs
71165220Srrsstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
72165220Srrs__tzcnt32(unsigned int __X)
73163953Srrs{
74163953Srrs  return __builtin_ctz(__X);
75163953Srrs}
76163953Srrs
77163953Srrs#ifdef __x86_64__
78163953Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
79163953Srrs__andn_u64 (unsigned long long __X, unsigned long long __Y)
80163953Srrs{
81170181Srrs  return ~__X & __Y;
82163953Srrs}
83163953Srrs
84163953Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
85163953Srrs__bextr_u64(unsigned long long __X, unsigned long long __Y)
86163953Srrs{
87169420Srrs  return __builtin_ia32_bextr_u64(__X, __Y);
88169420Srrs}
89163953Srrs
90163953Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
91163953Srrs__blsi_u64(unsigned long long __X)
92163953Srrs{
93169420Srrs  return __X & -__X;
94169420Srrs}
95169420Srrs
96163953Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
97163953Srrs__blsmsk_u64(unsigned long long __X)
98163953Srrs{
99163953Srrs  return __X ^ (__X - 1);
100169352Srrs}
101170181Srrs
102168299Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
103168299Srrs__blsr_u64(unsigned long long __X)
104163953Srrs{
105163953Srrs  return __X & (__X - 1);
106163953Srrs}
107163953Srrs
108163953Srrsstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
109169352Srrs__tzcnt64(unsigned long long __X)
110170181Srrs{
111168299Srrs  return __builtin_ctzll(__X);
112168299Srrs}
113163953Srrs#endif
114163953Srrs
115163953Srrs#endif /* __BMIINTRIN_H */
116163953Srrs