xref: /freebsd/contrib/llvm-project/clang/lib/Headers/ia32intrin.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric /* ===-------- ia32intrin.h ---------------------------------------------------===
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 <ia32intrin.h> directly; include <x86intrin.h> instead."
12*0b57cec5SDimitry Andric #endif
13*0b57cec5SDimitry Andric 
14*0b57cec5SDimitry Andric #ifndef __IA32INTRIN_H
15*0b57cec5SDimitry Andric #define __IA32INTRIN_H
16*0b57cec5SDimitry Andric 
17*0b57cec5SDimitry Andric /** Find the first set bit starting from the lsb. Result is undefined if
18*0b57cec5SDimitry Andric  *  input is 0.
19*0b57cec5SDimitry Andric  *
20*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
21*0b57cec5SDimitry Andric  *
22*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSF </c> instruction or the
23*0b57cec5SDimitry Andric  *  <c> TZCNT </c> instruction.
24*0b57cec5SDimitry Andric  *
25*0b57cec5SDimitry Andric  *  \param __A
26*0b57cec5SDimitry Andric  *     A 32-bit integer operand.
27*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the bit number.
28*0b57cec5SDimitry Andric  */
29*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
30*0b57cec5SDimitry Andric __bsfd(int __A) {
31*0b57cec5SDimitry Andric   return __builtin_ctz(__A);
32*0b57cec5SDimitry Andric }
33*0b57cec5SDimitry Andric 
34*0b57cec5SDimitry Andric /** Find the first set bit starting from the msb. Result is undefined if
35*0b57cec5SDimitry Andric  *  input is 0.
36*0b57cec5SDimitry Andric  *
37*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
38*0b57cec5SDimitry Andric  *
39*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSR </c> instruction or the
40*0b57cec5SDimitry Andric  *  <c> LZCNT </c> instruction and an <c> XOR </c>.
41*0b57cec5SDimitry Andric  *
42*0b57cec5SDimitry Andric  *  \param __A
43*0b57cec5SDimitry Andric  *     A 32-bit integer operand.
44*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the bit number.
45*0b57cec5SDimitry Andric  */
46*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
47*0b57cec5SDimitry Andric __bsrd(int __A) {
48*0b57cec5SDimitry Andric   return 31 - __builtin_clz(__A);
49*0b57cec5SDimitry Andric }
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric /** Swaps the bytes in the input. Converting little endian to big endian or
52*0b57cec5SDimitry Andric  *  vice versa.
53*0b57cec5SDimitry Andric  *
54*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
55*0b57cec5SDimitry Andric  *
56*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSWAP </c> instruction.
57*0b57cec5SDimitry Andric  *
58*0b57cec5SDimitry Andric  *  \param __A
59*0b57cec5SDimitry Andric  *     A 32-bit integer operand.
60*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the swapped bytes.
61*0b57cec5SDimitry Andric  */
62*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
63*0b57cec5SDimitry Andric __bswapd(int __A) {
64*0b57cec5SDimitry Andric   return __builtin_bswap32(__A);
65*0b57cec5SDimitry Andric }
66*0b57cec5SDimitry Andric 
67*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
68*0b57cec5SDimitry Andric _bswap(int __A) {
69*0b57cec5SDimitry Andric   return __builtin_bswap32(__A);
70*0b57cec5SDimitry Andric }
71*0b57cec5SDimitry Andric 
72*0b57cec5SDimitry Andric #define _bit_scan_forward(A) __bsfd((A))
73*0b57cec5SDimitry Andric #define _bit_scan_reverse(A) __bsrd((A))
74*0b57cec5SDimitry Andric 
75*0b57cec5SDimitry Andric #ifdef __x86_64__
76*0b57cec5SDimitry Andric /** Find the first set bit starting from the lsb. Result is undefined if
77*0b57cec5SDimitry Andric  *  input is 0.
78*0b57cec5SDimitry Andric  *
79*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
80*0b57cec5SDimitry Andric  *
81*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSF </c> instruction or the
82*0b57cec5SDimitry Andric  *  <c> TZCNT </c> instruction.
83*0b57cec5SDimitry Andric  *
84*0b57cec5SDimitry Andric  *  \param __A
85*0b57cec5SDimitry Andric  *     A 64-bit integer operand.
86*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the bit number.
87*0b57cec5SDimitry Andric  */
88*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
89*0b57cec5SDimitry Andric __bsfq(long long __A) {
90*0b57cec5SDimitry Andric   return __builtin_ctzll(__A);
91*0b57cec5SDimitry Andric }
92*0b57cec5SDimitry Andric 
93*0b57cec5SDimitry Andric /** Find the first set bit starting from the msb. Result is undefined if
94*0b57cec5SDimitry Andric  *  input is 0.
95*0b57cec5SDimitry Andric  *
96*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
97*0b57cec5SDimitry Andric  *
98*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSR </c> instruction or the
99*0b57cec5SDimitry Andric  *  <c> LZCNT </c> instruction and an <c> XOR </c>.
100*0b57cec5SDimitry Andric  *
101*0b57cec5SDimitry Andric  *  \param __A
102*0b57cec5SDimitry Andric  *     A 64-bit integer operand.
103*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the bit number.
104*0b57cec5SDimitry Andric  */
105*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
106*0b57cec5SDimitry Andric __bsrq(long long __A) {
107*0b57cec5SDimitry Andric   return 63 - __builtin_clzll(__A);
108*0b57cec5SDimitry Andric }
109*0b57cec5SDimitry Andric 
110*0b57cec5SDimitry Andric /** Swaps the bytes in the input. Converting little endian to big endian or
111*0b57cec5SDimitry Andric  *  vice versa.
112*0b57cec5SDimitry Andric  *
113*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
114*0b57cec5SDimitry Andric  *
115*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> BSWAP </c> instruction.
116*0b57cec5SDimitry Andric  *
117*0b57cec5SDimitry Andric  *  \param __A
118*0b57cec5SDimitry Andric  *     A 64-bit integer operand.
119*0b57cec5SDimitry Andric  *  \returns A 64-bit integer containing the swapped bytes.
120*0b57cec5SDimitry Andric  */
121*0b57cec5SDimitry Andric static __inline__ long long __attribute__((__always_inline__, __nodebug__))
122*0b57cec5SDimitry Andric __bswapq(long long __A) {
123*0b57cec5SDimitry Andric   return __builtin_bswap64(__A);
124*0b57cec5SDimitry Andric }
125*0b57cec5SDimitry Andric 
126*0b57cec5SDimitry Andric #define _bswap64(A) __bswapq((A))
127*0b57cec5SDimitry Andric #endif
128*0b57cec5SDimitry Andric 
129*0b57cec5SDimitry Andric /** Counts the number of bits in the source operand having a value of 1.
130*0b57cec5SDimitry Andric  *
131*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
132*0b57cec5SDimitry Andric  *
133*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> POPCNT </c> instruction or a
134*0b57cec5SDimitry Andric  *  a sequence of arithmetic and logic ops to calculate it.
135*0b57cec5SDimitry Andric  *
136*0b57cec5SDimitry Andric  *  \param __A
137*0b57cec5SDimitry Andric  *     An unsigned 32-bit integer operand.
138*0b57cec5SDimitry Andric  *  \returns A 32-bit integer containing the number of bits with value 1 in the
139*0b57cec5SDimitry Andric  *     source operand.
140*0b57cec5SDimitry Andric  */
141*0b57cec5SDimitry Andric static __inline__ int __attribute__((__always_inline__, __nodebug__))
142*0b57cec5SDimitry Andric __popcntd(unsigned int __A)
143*0b57cec5SDimitry Andric {
144*0b57cec5SDimitry Andric   return __builtin_popcount(__A);
145*0b57cec5SDimitry Andric }
146*0b57cec5SDimitry Andric 
147*0b57cec5SDimitry Andric #define _popcnt32(A) __popcntd((A))
148*0b57cec5SDimitry Andric 
149*0b57cec5SDimitry Andric #ifdef __x86_64__
150*0b57cec5SDimitry Andric /** Counts the number of bits in the source operand having a value of 1.
151*0b57cec5SDimitry Andric  *
152*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
153*0b57cec5SDimitry Andric  *
154*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> POPCNT </c> instruction or a
155*0b57cec5SDimitry Andric  *  a sequence of arithmetic and logic ops to calculate it.
156*0b57cec5SDimitry Andric  *
157*0b57cec5SDimitry Andric  *  \param __A
158*0b57cec5SDimitry Andric  *     An unsigned 64-bit integer operand.
159*0b57cec5SDimitry Andric  *  \returns A 64-bit integer containing the number of bits with value 1 in the
160*0b57cec5SDimitry Andric  *     source operand.
161*0b57cec5SDimitry Andric  */
162*0b57cec5SDimitry Andric static __inline__ long long __attribute__((__always_inline__, __nodebug__))
163*0b57cec5SDimitry Andric __popcntq(unsigned long long __A)
164*0b57cec5SDimitry Andric {
165*0b57cec5SDimitry Andric   return __builtin_popcountll(__A);
166*0b57cec5SDimitry Andric }
167*0b57cec5SDimitry Andric 
168*0b57cec5SDimitry Andric #define _popcnt64(A) __popcntq((A))
169*0b57cec5SDimitry Andric #endif /* __x86_64__ */
170*0b57cec5SDimitry Andric 
171*0b57cec5SDimitry Andric #ifdef __x86_64__
172*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
173*0b57cec5SDimitry Andric __readeflags(void)
174*0b57cec5SDimitry Andric {
175*0b57cec5SDimitry Andric   return __builtin_ia32_readeflags_u64();
176*0b57cec5SDimitry Andric }
177*0b57cec5SDimitry Andric 
178*0b57cec5SDimitry Andric static __inline__ void __attribute__((__always_inline__, __nodebug__))
179*0b57cec5SDimitry Andric __writeeflags(unsigned long long __f)
180*0b57cec5SDimitry Andric {
181*0b57cec5SDimitry Andric   __builtin_ia32_writeeflags_u64(__f);
182*0b57cec5SDimitry Andric }
183*0b57cec5SDimitry Andric 
184*0b57cec5SDimitry Andric #else /* !__x86_64__ */
185*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
186*0b57cec5SDimitry Andric __readeflags(void)
187*0b57cec5SDimitry Andric {
188*0b57cec5SDimitry Andric   return __builtin_ia32_readeflags_u32();
189*0b57cec5SDimitry Andric }
190*0b57cec5SDimitry Andric 
191*0b57cec5SDimitry Andric static __inline__ void __attribute__((__always_inline__, __nodebug__))
192*0b57cec5SDimitry Andric __writeeflags(unsigned int __f)
193*0b57cec5SDimitry Andric {
194*0b57cec5SDimitry Andric   __builtin_ia32_writeeflags_u32(__f);
195*0b57cec5SDimitry Andric }
196*0b57cec5SDimitry Andric #endif /* !__x86_64__ */
197*0b57cec5SDimitry Andric 
198*0b57cec5SDimitry Andric /** Adds the unsigned integer operand to the CRC-32C checksum of the
199*0b57cec5SDimitry Andric  *     unsigned char operand.
200*0b57cec5SDimitry Andric  *
201*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
202*0b57cec5SDimitry Andric  *
203*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> CRC32B </c> instruction.
204*0b57cec5SDimitry Andric  *
205*0b57cec5SDimitry Andric  *  \param __C
206*0b57cec5SDimitry Andric  *     An unsigned integer operand to add to the CRC-32C checksum of operand
207*0b57cec5SDimitry Andric  *     \a  __D.
208*0b57cec5SDimitry Andric  *  \param __D
209*0b57cec5SDimitry Andric  *     An unsigned 8-bit integer operand used to compute the CRC-32C checksum.
210*0b57cec5SDimitry Andric  *  \returns The result of adding operand \a __C to the CRC-32C checksum of
211*0b57cec5SDimitry Andric  *     operand \a __D.
212*0b57cec5SDimitry Andric  */
213*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
214*0b57cec5SDimitry Andric __crc32b(unsigned int __C, unsigned char __D)
215*0b57cec5SDimitry Andric {
216*0b57cec5SDimitry Andric   return __builtin_ia32_crc32qi(__C, __D);
217*0b57cec5SDimitry Andric }
218*0b57cec5SDimitry Andric 
219*0b57cec5SDimitry Andric /** Adds the unsigned integer operand to the CRC-32C checksum of the
220*0b57cec5SDimitry Andric  *     unsigned short operand.
221*0b57cec5SDimitry Andric  *
222*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
223*0b57cec5SDimitry Andric  *
224*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> CRC32W </c> instruction.
225*0b57cec5SDimitry Andric  *
226*0b57cec5SDimitry Andric  *  \param __C
227*0b57cec5SDimitry Andric  *     An unsigned integer operand to add to the CRC-32C checksum of operand
228*0b57cec5SDimitry Andric  *     \a  __D.
229*0b57cec5SDimitry Andric  *  \param __D
230*0b57cec5SDimitry Andric  *     An unsigned 16-bit integer operand used to compute the CRC-32C checksum.
231*0b57cec5SDimitry Andric  *  \returns The result of adding operand \a __C to the CRC-32C checksum of
232*0b57cec5SDimitry Andric  *     operand \a __D.
233*0b57cec5SDimitry Andric  */
234*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
235*0b57cec5SDimitry Andric __crc32w(unsigned int __C, unsigned short __D)
236*0b57cec5SDimitry Andric {
237*0b57cec5SDimitry Andric   return __builtin_ia32_crc32hi(__C, __D);
238*0b57cec5SDimitry Andric }
239*0b57cec5SDimitry Andric 
240*0b57cec5SDimitry Andric /** Adds the unsigned integer operand to the CRC-32C checksum of the
241*0b57cec5SDimitry Andric  *     second unsigned integer operand.
242*0b57cec5SDimitry Andric  *
243*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
244*0b57cec5SDimitry Andric  *
245*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> CRC32D </c> instruction.
246*0b57cec5SDimitry Andric  *
247*0b57cec5SDimitry Andric  *  \param __C
248*0b57cec5SDimitry Andric  *     An unsigned integer operand to add to the CRC-32C checksum of operand
249*0b57cec5SDimitry Andric  *     \a  __D.
250*0b57cec5SDimitry Andric  *  \param __D
251*0b57cec5SDimitry Andric  *     An unsigned 32-bit integer operand used to compute the CRC-32C checksum.
252*0b57cec5SDimitry Andric  *  \returns The result of adding operand \a __C to the CRC-32C checksum of
253*0b57cec5SDimitry Andric  *     operand \a __D.
254*0b57cec5SDimitry Andric  */
255*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
256*0b57cec5SDimitry Andric __crc32d(unsigned int __C, unsigned int __D)
257*0b57cec5SDimitry Andric {
258*0b57cec5SDimitry Andric   return __builtin_ia32_crc32si(__C, __D);
259*0b57cec5SDimitry Andric }
260*0b57cec5SDimitry Andric 
261*0b57cec5SDimitry Andric #ifdef __x86_64__
262*0b57cec5SDimitry Andric /** Adds the unsigned integer operand to the CRC-32C checksum of the
263*0b57cec5SDimitry Andric  *     unsigned 64-bit integer operand.
264*0b57cec5SDimitry Andric  *
265*0b57cec5SDimitry Andric  *  \headerfile <x86intrin.h>
266*0b57cec5SDimitry Andric  *
267*0b57cec5SDimitry Andric  *  This intrinsic corresponds to the <c> CRC32Q </c> instruction.
268*0b57cec5SDimitry Andric  *
269*0b57cec5SDimitry Andric  *  \param __C
270*0b57cec5SDimitry Andric  *     An unsigned integer operand to add to the CRC-32C checksum of operand
271*0b57cec5SDimitry Andric  *     \a  __D.
272*0b57cec5SDimitry Andric  *  \param __D
273*0b57cec5SDimitry Andric  *     An unsigned 64-bit integer operand used to compute the CRC-32C checksum.
274*0b57cec5SDimitry Andric  *  \returns The result of adding operand \a __C to the CRC-32C checksum of
275*0b57cec5SDimitry Andric  *     operand \a __D.
276*0b57cec5SDimitry Andric  */
277*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
278*0b57cec5SDimitry Andric __crc32q(unsigned long long __C, unsigned long long __D)
279*0b57cec5SDimitry Andric {
280*0b57cec5SDimitry Andric   return __builtin_ia32_crc32di(__C, __D);
281*0b57cec5SDimitry Andric }
282*0b57cec5SDimitry Andric #endif /* __x86_64__ */
283*0b57cec5SDimitry Andric 
284*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
285*0b57cec5SDimitry Andric __rdpmc(int __A) {
286*0b57cec5SDimitry Andric   return __builtin_ia32_rdpmc(__A);
287*0b57cec5SDimitry Andric }
288*0b57cec5SDimitry Andric 
289*0b57cec5SDimitry Andric /* __rdtscp */
290*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
291*0b57cec5SDimitry Andric __rdtscp(unsigned int *__A) {
292*0b57cec5SDimitry Andric   return __builtin_ia32_rdtscp(__A);
293*0b57cec5SDimitry Andric }
294*0b57cec5SDimitry Andric 
295*0b57cec5SDimitry Andric #define _rdtsc() __rdtsc()
296*0b57cec5SDimitry Andric 
297*0b57cec5SDimitry Andric #define _rdpmc(A) __rdpmc(A)
298*0b57cec5SDimitry Andric 
299*0b57cec5SDimitry Andric static __inline__ void __attribute__((__always_inline__, __nodebug__))
300*0b57cec5SDimitry Andric _wbinvd(void) {
301*0b57cec5SDimitry Andric   __builtin_ia32_wbinvd();
302*0b57cec5SDimitry Andric }
303*0b57cec5SDimitry Andric 
304*0b57cec5SDimitry Andric static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
305*0b57cec5SDimitry Andric __rolb(unsigned char __X, int __C) {
306*0b57cec5SDimitry Andric   return __builtin_rotateleft8(__X, __C);
307*0b57cec5SDimitry Andric }
308*0b57cec5SDimitry Andric 
309*0b57cec5SDimitry Andric static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
310*0b57cec5SDimitry Andric __rorb(unsigned char __X, int __C) {
311*0b57cec5SDimitry Andric   return __builtin_rotateright8(__X, __C);
312*0b57cec5SDimitry Andric }
313*0b57cec5SDimitry Andric 
314*0b57cec5SDimitry Andric static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
315*0b57cec5SDimitry Andric __rolw(unsigned short __X, int __C) {
316*0b57cec5SDimitry Andric   return __builtin_rotateleft16(__X, __C);
317*0b57cec5SDimitry Andric }
318*0b57cec5SDimitry Andric 
319*0b57cec5SDimitry Andric static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
320*0b57cec5SDimitry Andric __rorw(unsigned short __X, int __C) {
321*0b57cec5SDimitry Andric   return __builtin_rotateright16(__X, __C);
322*0b57cec5SDimitry Andric }
323*0b57cec5SDimitry Andric 
324*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
325*0b57cec5SDimitry Andric __rold(unsigned int __X, int __C) {
326*0b57cec5SDimitry Andric   return __builtin_rotateleft32(__X, __C);
327*0b57cec5SDimitry Andric }
328*0b57cec5SDimitry Andric 
329*0b57cec5SDimitry Andric static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
330*0b57cec5SDimitry Andric __rord(unsigned int __X, int __C) {
331*0b57cec5SDimitry Andric   return __builtin_rotateright32(__X, __C);
332*0b57cec5SDimitry Andric }
333*0b57cec5SDimitry Andric 
334*0b57cec5SDimitry Andric #ifdef __x86_64__
335*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
336*0b57cec5SDimitry Andric __rolq(unsigned long long __X, int __C) {
337*0b57cec5SDimitry Andric   return __builtin_rotateleft64(__X, __C);
338*0b57cec5SDimitry Andric }
339*0b57cec5SDimitry Andric 
340*0b57cec5SDimitry Andric static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
341*0b57cec5SDimitry Andric __rorq(unsigned long long __X, int __C) {
342*0b57cec5SDimitry Andric   return __builtin_rotateright64(__X, __C);
343*0b57cec5SDimitry Andric }
344*0b57cec5SDimitry Andric #endif /* __x86_64__ */
345*0b57cec5SDimitry Andric 
346*0b57cec5SDimitry Andric #ifndef _MSC_VER
347*0b57cec5SDimitry Andric /* These are already provided as builtins for MSVC. */
348*0b57cec5SDimitry Andric /* Select the correct function based on the size of long. */
349*0b57cec5SDimitry Andric #ifdef __LP64__
350*0b57cec5SDimitry Andric #define _lrotl(a,b) __rolq((a), (b))
351*0b57cec5SDimitry Andric #define _lrotr(a,b) __rorq((a), (b))
352*0b57cec5SDimitry Andric #else
353*0b57cec5SDimitry Andric #define _lrotl(a,b) __rold((a), (b))
354*0b57cec5SDimitry Andric #define _lrotr(a,b) __rord((a), (b))
355*0b57cec5SDimitry Andric #endif
356*0b57cec5SDimitry Andric #define _rotl(a,b) __rold((a), (b))
357*0b57cec5SDimitry Andric #define _rotr(a,b) __rord((a), (b))
358*0b57cec5SDimitry Andric #endif // _MSC_VER
359*0b57cec5SDimitry Andric 
360*0b57cec5SDimitry Andric /* These are not builtins so need to be provided in all modes. */
361*0b57cec5SDimitry Andric #define _rotwl(a,b) __rolw((a), (b))
362*0b57cec5SDimitry Andric #define _rotwr(a,b) __rorw((a), (b))
363*0b57cec5SDimitry Andric 
364*0b57cec5SDimitry Andric #endif /* __IA32INTRIN_H */
365