blob: d09ebc0e25d5f0259b7259d1cfb84375e4678415 [file] [log] [blame]
Yunzhong Gaof4e0b102013-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
Eric Christopher4d1851682015-06-17 07:09:20 +000035/* Define the default attributes for the functions in this file. */
36#define DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
37
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000038#define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b)))
39
Eric Christopher4d1851682015-06-17 07:09:20 +000040static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000041__blcfill_u32(unsigned int a)
42{
Craig Topperd335c9d2013-10-05 17:08:42 +000043 return a & (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000044}
45
Eric Christopher4d1851682015-06-17 07:09:20 +000046static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000047__blci_u32(unsigned int a)
48{
Craig Topperd335c9d2013-10-05 17:08:42 +000049 return a | ~(a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000050}
51
Eric Christopher4d1851682015-06-17 07:09:20 +000052static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000053__blcic_u32(unsigned int a)
54{
Craig Topperd335c9d2013-10-05 17:08:42 +000055 return ~a & (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000056}
57
Eric Christopher4d1851682015-06-17 07:09:20 +000058static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000059__blcmsk_u32(unsigned int a)
60{
Craig Topperd335c9d2013-10-05 17:08:42 +000061 return a ^ (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000062}
63
Eric Christopher4d1851682015-06-17 07:09:20 +000064static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000065__blcs_u32(unsigned int a)
66{
Craig Topperd335c9d2013-10-05 17:08:42 +000067 return a | (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000068}
69
Eric Christopher4d1851682015-06-17 07:09:20 +000070static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000071__blsfill_u32(unsigned int a)
72{
Craig Topperd335c9d2013-10-05 17:08:42 +000073 return a | (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000074}
75
Eric Christopher4d1851682015-06-17 07:09:20 +000076static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000077__blsic_u32(unsigned int a)
78{
Craig Topperd335c9d2013-10-05 17:08:42 +000079 return ~a | (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000080}
81
Eric Christopher4d1851682015-06-17 07:09:20 +000082static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000083__t1mskc_u32(unsigned int a)
84{
Craig Topperd335c9d2013-10-05 17:08:42 +000085 return ~a | (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000086}
87
Eric Christopher4d1851682015-06-17 07:09:20 +000088static __inline__ unsigned int DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000089__tzmsk_u32(unsigned int a)
90{
Craig Topperd335c9d2013-10-05 17:08:42 +000091 return ~a & (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000092}
93
94#ifdef __x86_64__
Craig Topperd335c9d2013-10-05 17:08:42 +000095#define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b)))
96
Eric Christopher4d1851682015-06-17 07:09:20 +000097static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +000098__blcfill_u64(unsigned long long a)
99{
100 return a & (a + 1);
101}
102
Eric Christopher4d1851682015-06-17 07:09:20 +0000103static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000104__blci_u64(unsigned long long a)
105{
106 return a | ~(a + 1);
107}
108
Eric Christopher4d1851682015-06-17 07:09:20 +0000109static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000110__blcic_u64(unsigned long long a)
111{
112 return ~a & (a + 1);
113}
114
Eric Christopher4d1851682015-06-17 07:09:20 +0000115static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000116__blcmsk_u64(unsigned long long a)
117{
118 return a ^ (a + 1);
119}
120
Eric Christopher4d1851682015-06-17 07:09:20 +0000121static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000122__blcs_u64(unsigned long long a)
123{
124 return a | (a + 1);
125}
126
Eric Christopher4d1851682015-06-17 07:09:20 +0000127static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000128__blsfill_u64(unsigned long long a)
129{
130 return a | (a - 1);
131}
132
Eric Christopher4d1851682015-06-17 07:09:20 +0000133static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000134__blsic_u64(unsigned long long a)
135{
136 return ~a | (a - 1);
137}
138
Eric Christopher4d1851682015-06-17 07:09:20 +0000139static __inline__ unsigned long long DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000140__t1mskc_u64(unsigned long long a)
141{
142 return ~a | (a + 1);
143}
144
Eric Christopher4d1851682015-06-17 07:09:20 +0000145static __inline__ unsigned long long DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000146__tzmsk_u64(unsigned long long a)
147{
Craig Topperd335c9d2013-10-05 17:08:42 +0000148 return ~a & (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000149}
150#endif
151
Eric Christopher4d1851682015-06-17 07:09:20 +0000152#undef DEFAULT_FN_ATTRS
153
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000154#endif /* __TBMINTRIN_H */