blob: 785961c6ab86892dbfe5a8fbb42a60f8e4400275 [file] [log] [blame]
Pirama Arumuga Nainar45562a52016-03-17 10:49:59 -07001/*===---- 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 __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
31/* Define the default attributes for the functions in this file. */
32#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm")))
33
34#define __bextri_u32(a, b) \
35 ((unsigned int)__builtin_ia32_bextri_u32((unsigned int)(a), \
36 (unsigned int)(b)))
37
38static __inline__ unsigned int __DEFAULT_FN_ATTRS
39__blcfill_u32(unsigned int a)
40{
41 return a & (a + 1);
42}
43
44static __inline__ unsigned int __DEFAULT_FN_ATTRS
45__blci_u32(unsigned int a)
46{
47 return a | ~(a + 1);
48}
49
50static __inline__ unsigned int __DEFAULT_FN_ATTRS
51__blcic_u32(unsigned int a)
52{
53 return ~a & (a + 1);
54}
55
56static __inline__ unsigned int __DEFAULT_FN_ATTRS
57__blcmsk_u32(unsigned int a)
58{
59 return a ^ (a + 1);
60}
61
62static __inline__ unsigned int __DEFAULT_FN_ATTRS
63__blcs_u32(unsigned int a)
64{
65 return a | (a + 1);
66}
67
68static __inline__ unsigned int __DEFAULT_FN_ATTRS
69__blsfill_u32(unsigned int a)
70{
71 return a | (a - 1);
72}
73
74static __inline__ unsigned int __DEFAULT_FN_ATTRS
75__blsic_u32(unsigned int a)
76{
77 return ~a | (a - 1);
78}
79
80static __inline__ unsigned int __DEFAULT_FN_ATTRS
81__t1mskc_u32(unsigned int a)
82{
83 return ~a | (a + 1);
84}
85
86static __inline__ unsigned int __DEFAULT_FN_ATTRS
87__tzmsk_u32(unsigned int a)
88{
89 return ~a & (a - 1);
90}
91
92#ifdef __x86_64__
93#define __bextri_u64(a, b) \
94 ((unsigned long long)__builtin_ia32_bextri_u64((unsigned long long)(a), \
95 (unsigned long long)(b)))
96
97static __inline__ unsigned long long __DEFAULT_FN_ATTRS
98__blcfill_u64(unsigned long long a)
99{
100 return a & (a + 1);
101}
102
103static __inline__ unsigned long long __DEFAULT_FN_ATTRS
104__blci_u64(unsigned long long a)
105{
106 return a | ~(a + 1);
107}
108
109static __inline__ unsigned long long __DEFAULT_FN_ATTRS
110__blcic_u64(unsigned long long a)
111{
112 return ~a & (a + 1);
113}
114
115static __inline__ unsigned long long __DEFAULT_FN_ATTRS
116__blcmsk_u64(unsigned long long a)
117{
118 return a ^ (a + 1);
119}
120
121static __inline__ unsigned long long __DEFAULT_FN_ATTRS
122__blcs_u64(unsigned long long a)
123{
124 return a | (a + 1);
125}
126
127static __inline__ unsigned long long __DEFAULT_FN_ATTRS
128__blsfill_u64(unsigned long long a)
129{
130 return a | (a - 1);
131}
132
133static __inline__ unsigned long long __DEFAULT_FN_ATTRS
134__blsic_u64(unsigned long long a)
135{
136 return ~a | (a - 1);
137}
138
139static __inline__ unsigned long long __DEFAULT_FN_ATTRS
140__t1mskc_u64(unsigned long long a)
141{
142 return ~a | (a + 1);
143}
144
145static __inline__ unsigned long long __DEFAULT_FN_ATTRS
146__tzmsk_u64(unsigned long long a)
147{
148 return ~a & (a - 1);
149}
150#endif
151
152#undef __DEFAULT_FN_ATTRS
153
154#endif /* __TBMINTRIN_H */