blob: 62f613f9ee5cde0ce6d15b6789f6cacbf40c9b26 [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
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000024#ifndef __X86INTRIN_H
25#error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead."
26#endif
27
28#ifndef __TBMINTRIN_H
29#define __TBMINTRIN_H
30
Eric Christopher4d1851682015-06-17 07:09:20 +000031/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000032#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm")))
Eric Christopher4d1851682015-06-17 07:09:20 +000033
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000034#define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b)))
35
Michael Kupersteine45af542015-06-30 13:36:19 +000036static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000037__blcfill_u32(unsigned int a)
38{
Craig Topperd335c9d2013-10-05 17:08:42 +000039 return a & (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000040}
41
Michael Kupersteine45af542015-06-30 13:36:19 +000042static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000043__blci_u32(unsigned int a)
44{
Craig Topperd335c9d2013-10-05 17:08:42 +000045 return a | ~(a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000046}
47
Michael Kupersteine45af542015-06-30 13:36:19 +000048static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000049__blcic_u32(unsigned int a)
50{
Craig Topperd335c9d2013-10-05 17:08:42 +000051 return ~a & (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000052}
53
Michael Kupersteine45af542015-06-30 13:36:19 +000054static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000055__blcmsk_u32(unsigned int a)
56{
Craig Topperd335c9d2013-10-05 17:08:42 +000057 return a ^ (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000058}
59
Michael Kupersteine45af542015-06-30 13:36:19 +000060static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000061__blcs_u32(unsigned int a)
62{
Craig Topperd335c9d2013-10-05 17:08:42 +000063 return a | (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000064}
65
Michael Kupersteine45af542015-06-30 13:36:19 +000066static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000067__blsfill_u32(unsigned int a)
68{
Craig Topperd335c9d2013-10-05 17:08:42 +000069 return a | (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000070}
71
Michael Kupersteine45af542015-06-30 13:36:19 +000072static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000073__blsic_u32(unsigned int a)
74{
Craig Topperd335c9d2013-10-05 17:08:42 +000075 return ~a | (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000076}
77
Michael Kupersteine45af542015-06-30 13:36:19 +000078static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000079__t1mskc_u32(unsigned int a)
80{
Craig Topperd335c9d2013-10-05 17:08:42 +000081 return ~a | (a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000082}
83
Michael Kupersteine45af542015-06-30 13:36:19 +000084static __inline__ unsigned int __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000085__tzmsk_u32(unsigned int a)
86{
Craig Topperd335c9d2013-10-05 17:08:42 +000087 return ~a & (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000088}
89
90#ifdef __x86_64__
Craig Topperd335c9d2013-10-05 17:08:42 +000091#define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b)))
92
Michael Kupersteine45af542015-06-30 13:36:19 +000093static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +000094__blcfill_u64(unsigned long long a)
95{
96 return a & (a + 1);
97}
98
Michael Kupersteine45af542015-06-30 13:36:19 +000099static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000100__blci_u64(unsigned long long a)
101{
102 return a | ~(a + 1);
103}
104
Michael Kupersteine45af542015-06-30 13:36:19 +0000105static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000106__blcic_u64(unsigned long long a)
107{
108 return ~a & (a + 1);
109}
110
Michael Kupersteine45af542015-06-30 13:36:19 +0000111static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000112__blcmsk_u64(unsigned long long a)
113{
114 return a ^ (a + 1);
115}
116
Michael Kupersteine45af542015-06-30 13:36:19 +0000117static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000118__blcs_u64(unsigned long long a)
119{
120 return a | (a + 1);
121}
122
Michael Kupersteine45af542015-06-30 13:36:19 +0000123static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000124__blsfill_u64(unsigned long long a)
125{
126 return a | (a - 1);
127}
128
Michael Kupersteine45af542015-06-30 13:36:19 +0000129static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000130__blsic_u64(unsigned long long a)
131{
132 return ~a | (a - 1);
133}
134
Michael Kupersteine45af542015-06-30 13:36:19 +0000135static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperd335c9d2013-10-05 17:08:42 +0000136__t1mskc_u64(unsigned long long a)
137{
138 return ~a | (a + 1);
139}
140
Michael Kupersteine45af542015-06-30 13:36:19 +0000141static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000142__tzmsk_u64(unsigned long long a)
143{
Craig Topperd335c9d2013-10-05 17:08:42 +0000144 return ~a & (a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000145}
146#endif
147
Michael Kupersteine45af542015-06-30 13:36:19 +0000148#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000149
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000150#endif /* __TBMINTRIN_H */