1 /*===---- tbmintrin.h - TBM intrinsics -------------------------------------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 #ifndef __X86INTRIN_H
11 #error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead."
12 #endif
13 
14 #ifndef __TBMINTRIN_H
15 #define __TBMINTRIN_H
16 
17 /* Define the default attributes for the functions in this file. */
18 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm")))
19 
20 #define __bextri_u32(a, b) \
21   ((unsigned int)__builtin_ia32_bextri_u32((unsigned int)(a), \
22                                            (unsigned int)(b)))
23 
24 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blcfill_u32(unsigned int __a)25 __blcfill_u32(unsigned int __a)
26 {
27   return __a & (__a + 1);
28 }
29 
30 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blci_u32(unsigned int __a)31 __blci_u32(unsigned int __a)
32 {
33   return __a | ~(__a + 1);
34 }
35 
36 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blcic_u32(unsigned int __a)37 __blcic_u32(unsigned int __a)
38 {
39   return ~__a & (__a + 1);
40 }
41 
42 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blcmsk_u32(unsigned int __a)43 __blcmsk_u32(unsigned int __a)
44 {
45   return __a ^ (__a + 1);
46 }
47 
48 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blcs_u32(unsigned int __a)49 __blcs_u32(unsigned int __a)
50 {
51   return __a | (__a + 1);
52 }
53 
54 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blsfill_u32(unsigned int __a)55 __blsfill_u32(unsigned int __a)
56 {
57   return __a | (__a - 1);
58 }
59 
60 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__blsic_u32(unsigned int __a)61 __blsic_u32(unsigned int __a)
62 {
63   return ~__a | (__a - 1);
64 }
65 
66 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__t1mskc_u32(unsigned int __a)67 __t1mskc_u32(unsigned int __a)
68 {
69   return ~__a | (__a + 1);
70 }
71 
72 static __inline__ unsigned int __DEFAULT_FN_ATTRS
__tzmsk_u32(unsigned int __a)73 __tzmsk_u32(unsigned int __a)
74 {
75   return ~__a & (__a - 1);
76 }
77 
78 #ifdef __x86_64__
79 #define __bextri_u64(a, b) \
80   ((unsigned long long)__builtin_ia32_bextri_u64((unsigned long long)(a), \
81                                                  (unsigned long long)(b)))
82 
83 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blcfill_u64(unsigned long long __a)84 __blcfill_u64(unsigned long long __a)
85 {
86   return __a & (__a + 1);
87 }
88 
89 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blci_u64(unsigned long long __a)90 __blci_u64(unsigned long long __a)
91 {
92   return __a | ~(__a + 1);
93 }
94 
95 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blcic_u64(unsigned long long __a)96 __blcic_u64(unsigned long long __a)
97 {
98   return ~__a & (__a + 1);
99 }
100 
101 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blcmsk_u64(unsigned long long __a)102 __blcmsk_u64(unsigned long long __a)
103 {
104   return __a ^ (__a + 1);
105 }
106 
107 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blcs_u64(unsigned long long __a)108 __blcs_u64(unsigned long long __a)
109 {
110   return __a | (__a + 1);
111 }
112 
113 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blsfill_u64(unsigned long long __a)114 __blsfill_u64(unsigned long long __a)
115 {
116   return __a | (__a - 1);
117 }
118 
119 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__blsic_u64(unsigned long long __a)120 __blsic_u64(unsigned long long __a)
121 {
122   return ~__a | (__a - 1);
123 }
124 
125 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__t1mskc_u64(unsigned long long __a)126 __t1mskc_u64(unsigned long long __a)
127 {
128   return ~__a | (__a + 1);
129 }
130 
131 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__tzmsk_u64(unsigned long long __a)132 __tzmsk_u64(unsigned long long __a)
133 {
134   return ~__a & (__a - 1);
135 }
136 #endif
137 
138 #undef __DEFAULT_FN_ATTRS
139 
140 #endif /* __TBMINTRIN_H */
141