xref: /freebsd/contrib/llvm-project/clang/lib/Headers/adxintrin.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*===---- adxintrin.h - ADX 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 __IMMINTRIN_H
11 #error "Never use <adxintrin.h> directly; include <immintrin.h> instead."
12 #endif
13 
14 #ifndef __ADXINTRIN_H
15 #define __ADXINTRIN_H
16 
17 /* Define the default attributes for the functions in this file. */
18 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
19 
20 /* Use C++ inline semantics in C++, GNU inline for C mode. */
21 #if defined(__cplusplus)
22 #define __INLINE __inline
23 #else
24 #define __INLINE static __inline
25 #endif
26 
27 #if defined(__cplusplus)
28 extern "C" {
29 #endif
30 
31 /* Intrinsics that are available only if __ADX__ is defined. */
32 
33 /// Adds unsigned 32-bit integers \a __x and \a __y, plus 0 or 1 as indicated
34 ///    by the carry flag \a __cf. Stores the unsigned 32-bit sum in the memory
35 ///    at \a __p, and returns the 8-bit carry-out (carry flag).
36 ///
37 /// \code{.operation}
38 /// temp := (__cf == 0) ? 0 : 1
39 /// Store32(__p, __x + __y + temp)
40 /// result := CF
41 /// \endcode
42 ///
43 /// \headerfile <immintrin.h>
44 ///
45 /// This intrinsic corresponds to the \c ADCX instruction.
46 ///
47 /// \param __cf
48 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
49 /// \param __x
50 ///    A 32-bit unsigned addend.
51 /// \param __y
52 ///    A 32-bit unsigned addend.
53 /// \param __p
54 ///    Pointer to memory for storing the sum.
55 /// \returns The 8-bit unsigned carry-out value.
56 __INLINE unsigned char
57     __attribute__((__always_inline__, __nodebug__, __target__("adx")))
58     _addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
59                    unsigned int *__p) {
60   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
61 }
62 
63 #ifdef __x86_64__
64 /// Adds unsigned 64-bit integers \a __x and \a __y, plus 0 or 1 as indicated
65 ///    by the carry flag \a __cf. Stores the unsigned 64-bit sum in the memory
66 ///    at \a __p, and returns the 8-bit carry-out (carry flag).
67 ///
68 /// \code{.operation}
69 /// temp := (__cf == 0) ? 0 : 1
70 /// Store64(__p, __x + __y + temp)
71 /// result := CF
72 /// \endcode
73 ///
74 /// \headerfile <immintrin.h>
75 ///
76 /// This intrinsic corresponds to the \c ADCX instruction.
77 ///
78 /// \param __cf
79 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
80 /// \param __x
81 ///    A 64-bit unsigned addend.
82 /// \param __y
83 ///    A 64-bit unsigned addend.
84 /// \param __p
85 ///    Pointer to memory for storing the sum.
86 /// \returns The 8-bit unsigned carry-out value.
87 __INLINE unsigned char
88     __attribute__((__always_inline__, __nodebug__, __target__("adx")))
89     _addcarryx_u64(unsigned char __cf, unsigned long long __x,
90                    unsigned long long __y, unsigned long long *__p) {
91   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
92 }
93 #endif
94 
95 /* Intrinsics that are also available if __ADX__ is undefined. */
96 
97 /// Adds unsigned 32-bit integers \a __x and \a __y, plus 0 or 1 as indicated
98 ///    by the carry flag \a __cf. Stores the unsigned 32-bit sum in the memory
99 ///    at \a __p, and returns the 8-bit carry-out (carry flag).
100 ///
101 /// \code{.operation}
102 /// temp := (__cf == 0) ? 0 : 1
103 /// Store32(__p, __x + __y + temp)
104 /// result := CF
105 /// \endcode
106 ///
107 /// \headerfile <immintrin.h>
108 ///
109 /// This intrinsic corresponds to the \c ADC instruction.
110 ///
111 /// \param __cf
112 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
113 /// \param __x
114 ///    A 32-bit unsigned addend.
115 /// \param __y
116 ///    A 32-bit unsigned addend.
117 /// \param __p
118 ///    Pointer to memory for storing the sum.
119 /// \returns The 8-bit unsigned carry-out value.
120 __INLINE unsigned char __DEFAULT_FN_ATTRS _addcarry_u32(unsigned char __cf,
121                                                         unsigned int __x,
122                                                         unsigned int __y,
123                                                         unsigned int *__p) {
124   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
125 }
126 
127 #ifdef __x86_64__
128 /// Adds unsigned 64-bit integers \a __x and \a __y, plus 0 or 1 as indicated
129 ///    by the carry flag \a __cf. Stores the unsigned 64-bit sum in the memory
130 ///    at \a __p, and returns the 8-bit carry-out (carry flag).
131 ///
132 /// \code{.operation}
133 /// temp := (__cf == 0) ? 0 : 1
134 /// Store64(__p, __x + __y + temp)
135 /// result := CF
136 /// \endcode
137 ///
138 /// \headerfile <immintrin.h>
139 ///
140 /// This intrinsic corresponds to the \c ADC instruction.
141 ///
142 /// \param __cf
143 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
144 /// \param __x
145 ///    A 64-bit unsigned addend.
146 /// \param __y
147 ///    A 64-bit unsigned addend.
148 /// \param __p
149 ///    Pointer to memory for storing the sum.
150 /// \returns The 8-bit unsigned carry-out value.
151 __INLINE unsigned char __DEFAULT_FN_ATTRS
152 _addcarry_u64(unsigned char __cf, unsigned long long __x,
153               unsigned long long __y, unsigned long long *__p) {
154   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
155 }
156 #endif
157 
158 /// Adds unsigned 32-bit integer \a __y to 0 or 1 as indicated by the carry
159 ///    flag \a __cf, and subtracts the result from unsigned 32-bit integer
160 ///    \a __x. Stores the unsigned 32-bit difference in the memory at \a __p,
161 ///    and returns the 8-bit carry-out (carry or overflow flag).
162 ///
163 /// \code{.operation}
164 /// temp := (__cf == 0) ? 0 : 1
165 /// Store32(__p, __x - (__y + temp))
166 /// result := CF
167 /// \endcode
168 ///
169 /// \headerfile <immintrin.h>
170 ///
171 /// This intrinsic corresponds to the \c SBB instruction.
172 ///
173 /// \param __cf
174 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
175 /// \param __x
176 ///    The 32-bit unsigned minuend.
177 /// \param __y
178 ///    The 32-bit unsigned subtrahend.
179 /// \param __p
180 ///    Pointer to memory for storing the difference.
181 /// \returns The 8-bit unsigned carry-out value.
182 __INLINE unsigned char __DEFAULT_FN_ATTRS _subborrow_u32(unsigned char __cf,
183                                                          unsigned int __x,
184                                                          unsigned int __y,
185                                                          unsigned int *__p) {
186   return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p);
187 }
188 
189 #ifdef __x86_64__
190 /// Adds unsigned 64-bit integer \a __y to 0 or 1 as indicated by the carry
191 ///    flag \a __cf, and subtracts the result from unsigned 64-bit integer
192 ///    \a __x. Stores the unsigned 64-bit difference in the memory at \a __p,
193 ///    and returns the 8-bit carry-out (carry or overflow flag).
194 ///
195 /// \code{.operation}
196 /// temp := (__cf == 0) ? 0 : 1
197 /// Store64(__p, __x - (__y + temp))
198 /// result := CF
199 /// \endcode
200 ///
201 /// \headerfile <immintrin.h>
202 ///
203 /// This intrinsic corresponds to the \c ADC instruction.
204 ///
205 /// \param __cf
206 ///    The 8-bit unsigned carry flag; any non-zero value indicates carry.
207 /// \param __x
208 ///    The 64-bit unsigned minuend.
209 /// \param __y
210 ///    The 64-bit unsigned subtrahend.
211 /// \param __p
212 ///    Pointer to memory for storing the difference.
213 /// \returns The 8-bit unsigned carry-out value.
214 __INLINE unsigned char __DEFAULT_FN_ATTRS
215 _subborrow_u64(unsigned char __cf, unsigned long long __x,
216                unsigned long long __y, unsigned long long *__p) {
217   return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p);
218 }
219 #endif
220 
221 #if defined(__cplusplus)
222 }
223 #endif
224 
225 #undef __DEFAULT_FN_ATTRS
226 
227 #endif /* __ADXINTRIN_H */
228