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