blob: f95e34fbc185c881bd527e3357f4f2f7fb7db641 [file] [log] [blame]
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +00001/*===---- tbmintrin.h - TBM intrinsics -------------------------------------===
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 *
21 *===-----------------------------------------------------------------------===
22 */
23
24#ifndef __TBM__
25#error "TBM instruction set is not enabled"
26#endif
27
28#ifndef __X86INTRIN_H
29#error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead."
30#endif
31
32#ifndef __TBMINTRIN_H
33#define __TBMINTRIN_H
34
35#define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b)))
36
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000037static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
38__blcfill_u32(unsigned int a)
39{
Craig Topperd5276cc2013-10-05 17:08:42 +000040 return a & (a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000041}
42
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000043static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
44__blci_u32(unsigned int a)
45{
Craig Topperd5276cc2013-10-05 17:08:42 +000046 return a | ~(a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000047}
48
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000049static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
50__blcic_u32(unsigned int a)
51{
Craig Topperd5276cc2013-10-05 17:08:42 +000052 return ~a & (a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000053}
54
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000055static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
56__blcmsk_u32(unsigned int a)
57{
Craig Topperd5276cc2013-10-05 17:08:42 +000058 return a ^ (a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000059}
60
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000061static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
62__blcs_u32(unsigned int a)
63{
Craig Topperd5276cc2013-10-05 17:08:42 +000064 return a | (a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000065}
66
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000067static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
68__blsfill_u32(unsigned int a)
69{
Craig Topperd5276cc2013-10-05 17:08:42 +000070 return a | (a - 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000071}
72
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000073static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
74__blsic_u32(unsigned int a)
75{
Craig Topperd5276cc2013-10-05 17:08:42 +000076 return ~a | (a - 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000077}
78
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000079static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
80__t1mskc_u32(unsigned int a)
81{
Craig Topperd5276cc2013-10-05 17:08:42 +000082 return ~a | (a + 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000083}
84
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000085static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
86__tzmsk_u32(unsigned int a)
87{
Craig Topperd5276cc2013-10-05 17:08:42 +000088 return ~a & (a - 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +000089}
90
91#ifdef __x86_64__
Craig Topperd5276cc2013-10-05 17:08:42 +000092#define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b)))
93
94static __inline__ unsigned long long __attribute__((__always_inline__,
95 __nodebug__))
96__blcfill_u64(unsigned long long a)
97{
98 return a & (a + 1);
99}
100
101static __inline__ unsigned long long __attribute__((__always_inline__,
102 __nodebug__))
103__blci_u64(unsigned long long a)
104{
105 return a | ~(a + 1);
106}
107
108static __inline__ unsigned long long __attribute__((__always_inline__,
109 __nodebug__))
110__blcic_u64(unsigned long long a)
111{
112 return ~a & (a + 1);
113}
114
115static __inline__ unsigned long long __attribute__((__always_inline__,
116 __nodebug__))
117__blcmsk_u64(unsigned long long a)
118{
119 return a ^ (a + 1);
120}
121
122static __inline__ unsigned long long __attribute__((__always_inline__,
123 __nodebug__))
124__blcs_u64(unsigned long long a)
125{
126 return a | (a + 1);
127}
128
129static __inline__ unsigned long long __attribute__((__always_inline__,
130 __nodebug__))
131__blsfill_u64(unsigned long long a)
132{
133 return a | (a - 1);
134}
135
136static __inline__ unsigned long long __attribute__((__always_inline__,
137 __nodebug__))
138__blsic_u64(unsigned long long a)
139{
140 return ~a | (a - 1);
141}
142
143static __inline__ unsigned long long __attribute__((__always_inline__,
144 __nodebug__))
145__t1mskc_u64(unsigned long long a)
146{
147 return ~a | (a + 1);
148}
149
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +0000150static __inline__ unsigned long long __attribute__((__always_inline__,
151 __nodebug__))
152__tzmsk_u64(unsigned long long a)
153{
Craig Topperd5276cc2013-10-05 17:08:42 +0000154 return ~a & (a - 1);
Yunzhong Gao8c8bbad2013-09-30 17:25:14 +0000155}
156#endif
157
158#endif /* __TBMINTRIN_H */