blob: 1d0d746a824ab69f94949c05a1869e52c9e17b08 [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
Craig Topperd619eaaa2015-11-11 03:47:10 +000034#define __bextri_u32(a, b) \
35 ((unsigned int)__builtin_ia32_bextri_u32((unsigned int)(a), \
36 (unsigned int)(b)))
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000037
Michael Kupersteine45af542015-06-30 13:36:19 +000038static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000039__blcfill_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000040{
Eric Christopher39a84d02016-02-12 02:22:53 +000041 return __a & (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000042}
43
Michael Kupersteine45af542015-06-30 13:36:19 +000044static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000045__blci_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000046{
Eric Christopher39a84d02016-02-12 02:22:53 +000047 return __a | ~(__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000048}
49
Michael Kupersteine45af542015-06-30 13:36:19 +000050static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000051__blcic_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000052{
Eric Christopher39a84d02016-02-12 02:22:53 +000053 return ~__a & (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000054}
55
Michael Kupersteine45af542015-06-30 13:36:19 +000056static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000057__blcmsk_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000058{
Eric Christopher39a84d02016-02-12 02:22:53 +000059 return __a ^ (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000060}
61
Michael Kupersteine45af542015-06-30 13:36:19 +000062static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000063__blcs_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000064{
Eric Christopher39a84d02016-02-12 02:22:53 +000065 return __a | (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000066}
67
Michael Kupersteine45af542015-06-30 13:36:19 +000068static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000069__blsfill_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000070{
Eric Christopher39a84d02016-02-12 02:22:53 +000071 return __a | (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000072}
73
Michael Kupersteine45af542015-06-30 13:36:19 +000074static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000075__blsic_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000076{
Eric Christopher39a84d02016-02-12 02:22:53 +000077 return ~__a | (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000078}
79
Michael Kupersteine45af542015-06-30 13:36:19 +000080static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000081__t1mskc_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000082{
Eric Christopher39a84d02016-02-12 02:22:53 +000083 return ~__a | (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000084}
85
Michael Kupersteine45af542015-06-30 13:36:19 +000086static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000087__tzmsk_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000088{
Eric Christopher39a84d02016-02-12 02:22:53 +000089 return ~__a & (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000090}
91
92#ifdef __x86_64__
Craig Topperd619eaaa2015-11-11 03:47:10 +000093#define __bextri_u64(a, b) \
94 ((unsigned long long)__builtin_ia32_bextri_u64((unsigned long long)(a), \
95 (unsigned long long)(b)))
Craig Topperd335c9d2013-10-05 17:08:42 +000096
Michael Kupersteine45af542015-06-30 13:36:19 +000097static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000098__blcfill_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +000099{
Eric Christopher39a84d02016-02-12 02:22:53 +0000100 return __a & (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000101}
102
Michael Kupersteine45af542015-06-30 13:36:19 +0000103static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000104__blci_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000105{
Eric Christopher39a84d02016-02-12 02:22:53 +0000106 return __a | ~(__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000107}
108
Michael Kupersteine45af542015-06-30 13:36:19 +0000109static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000110__blcic_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000111{
Eric Christopher39a84d02016-02-12 02:22:53 +0000112 return ~__a & (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000113}
114
Michael Kupersteine45af542015-06-30 13:36:19 +0000115static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000116__blcmsk_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000117{
Eric Christopher39a84d02016-02-12 02:22:53 +0000118 return __a ^ (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000119}
120
Michael Kupersteine45af542015-06-30 13:36:19 +0000121static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000122__blcs_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000123{
Eric Christopher39a84d02016-02-12 02:22:53 +0000124 return __a | (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000125}
126
Michael Kupersteine45af542015-06-30 13:36:19 +0000127static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000128__blsfill_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000129{
Eric Christopher39a84d02016-02-12 02:22:53 +0000130 return __a | (__a - 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000131}
132
Michael Kupersteine45af542015-06-30 13:36:19 +0000133static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000134__blsic_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000135{
Eric Christopher39a84d02016-02-12 02:22:53 +0000136 return ~__a | (__a - 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000137}
138
Michael Kupersteine45af542015-06-30 13:36:19 +0000139static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000140__t1mskc_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000141{
Eric Christopher39a84d02016-02-12 02:22:53 +0000142 return ~__a | (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000143}
144
Michael Kupersteine45af542015-06-30 13:36:19 +0000145static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000146__tzmsk_u64(unsigned long long __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000147{
Eric Christopher39a84d02016-02-12 02:22:53 +0000148 return ~__a & (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000149}
150#endif
151
Michael Kupersteine45af542015-06-30 13:36:19 +0000152#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000153
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000154#endif /* __TBMINTRIN_H */