1*344a7f5eSAndroid Build Coastguard Worker /* ===-------- intrin.h ---------------------------------------------------===
2*344a7f5eSAndroid Build Coastguard Worker *
3*344a7f5eSAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a copy
4*344a7f5eSAndroid Build Coastguard Worker * of this software and associated documentation files (the "Software"), to deal
5*344a7f5eSAndroid Build Coastguard Worker * in the Software without restriction, including without limitation the rights
6*344a7f5eSAndroid Build Coastguard Worker * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*344a7f5eSAndroid Build Coastguard Worker * copies of the Software, and to permit persons to whom the Software is
8*344a7f5eSAndroid Build Coastguard Worker * furnished to do so, subject to the following conditions:
9*344a7f5eSAndroid Build Coastguard Worker *
10*344a7f5eSAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be included in
11*344a7f5eSAndroid Build Coastguard Worker * all copies or substantial portions of the Software.
12*344a7f5eSAndroid Build Coastguard Worker *
13*344a7f5eSAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*344a7f5eSAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*344a7f5eSAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*344a7f5eSAndroid Build Coastguard Worker * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*344a7f5eSAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*344a7f5eSAndroid Build Coastguard Worker * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*344a7f5eSAndroid Build Coastguard Worker * THE SOFTWARE.
20*344a7f5eSAndroid Build Coastguard Worker *
21*344a7f5eSAndroid Build Coastguard Worker *===-----------------------------------------------------------------------===
22*344a7f5eSAndroid Build Coastguard Worker */
23*344a7f5eSAndroid Build Coastguard Worker
24*344a7f5eSAndroid Build Coastguard Worker /* Only include this if we're compiling for the windows platform. */
25*344a7f5eSAndroid Build Coastguard Worker #ifndef _MSC_VER
26*344a7f5eSAndroid Build Coastguard Worker #include_next <intrin.h>
27*344a7f5eSAndroid Build Coastguard Worker #else
28*344a7f5eSAndroid Build Coastguard Worker
29*344a7f5eSAndroid Build Coastguard Worker #ifndef __INTRIN_H
30*344a7f5eSAndroid Build Coastguard Worker #define __INTRIN_H
31*344a7f5eSAndroid Build Coastguard Worker
32*344a7f5eSAndroid Build Coastguard Worker /* First include the standard intrinsics. */
33*344a7f5eSAndroid Build Coastguard Worker #if defined(__i386__) || defined(__x86_64__)
34*344a7f5eSAndroid Build Coastguard Worker #include <x86intrin.h>
35*344a7f5eSAndroid Build Coastguard Worker #endif
36*344a7f5eSAndroid Build Coastguard Worker
37*344a7f5eSAndroid Build Coastguard Worker /* For the definition of jmp_buf. */
38*344a7f5eSAndroid Build Coastguard Worker #if __STDC_HOSTED__
39*344a7f5eSAndroid Build Coastguard Worker #include <setjmp.h>
40*344a7f5eSAndroid Build Coastguard Worker #endif
41*344a7f5eSAndroid Build Coastguard Worker
42*344a7f5eSAndroid Build Coastguard Worker /* Define the default attributes for the functions in this file. */
43*344a7f5eSAndroid Build Coastguard Worker #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
44*344a7f5eSAndroid Build Coastguard Worker
45*344a7f5eSAndroid Build Coastguard Worker #ifdef __cplusplus
46*344a7f5eSAndroid Build Coastguard Worker extern "C" {
47*344a7f5eSAndroid Build Coastguard Worker #endif
48*344a7f5eSAndroid Build Coastguard Worker
49*344a7f5eSAndroid Build Coastguard Worker #if defined(__MMX__)
50*344a7f5eSAndroid Build Coastguard Worker /* And the random ones that aren't in those files. */
51*344a7f5eSAndroid Build Coastguard Worker __m64 _m_from_float(float);
52*344a7f5eSAndroid Build Coastguard Worker float _m_to_float(__m64);
53*344a7f5eSAndroid Build Coastguard Worker #endif
54*344a7f5eSAndroid Build Coastguard Worker
55*344a7f5eSAndroid Build Coastguard Worker /* Other assorted instruction intrinsics. */
56*344a7f5eSAndroid Build Coastguard Worker void __addfsbyte(unsigned long, unsigned char);
57*344a7f5eSAndroid Build Coastguard Worker void __addfsdword(unsigned long, unsigned long);
58*344a7f5eSAndroid Build Coastguard Worker void __addfsword(unsigned long, unsigned short);
59*344a7f5eSAndroid Build Coastguard Worker void __code_seg(const char *);
60*344a7f5eSAndroid Build Coastguard Worker static __inline__
61*344a7f5eSAndroid Build Coastguard Worker void __cpuid(int[4], int);
62*344a7f5eSAndroid Build Coastguard Worker static __inline__
63*344a7f5eSAndroid Build Coastguard Worker void __cpuidex(int[4], int, int);
64*344a7f5eSAndroid Build Coastguard Worker void __debugbreak(void);
65*344a7f5eSAndroid Build Coastguard Worker __int64 __emul(int, int);
66*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __emulu(unsigned int, unsigned int);
67*344a7f5eSAndroid Build Coastguard Worker void __cdecl __fastfail(unsigned int);
68*344a7f5eSAndroid Build Coastguard Worker unsigned int __getcallerseflags(void);
69*344a7f5eSAndroid Build Coastguard Worker static __inline__
70*344a7f5eSAndroid Build Coastguard Worker void __halt(void);
71*344a7f5eSAndroid Build Coastguard Worker unsigned char __inbyte(unsigned short);
72*344a7f5eSAndroid Build Coastguard Worker void __inbytestring(unsigned short, unsigned char *, unsigned long);
73*344a7f5eSAndroid Build Coastguard Worker void __incfsbyte(unsigned long);
74*344a7f5eSAndroid Build Coastguard Worker void __incfsdword(unsigned long);
75*344a7f5eSAndroid Build Coastguard Worker void __incfsword(unsigned long);
76*344a7f5eSAndroid Build Coastguard Worker unsigned long __indword(unsigned short);
77*344a7f5eSAndroid Build Coastguard Worker void __indwordstring(unsigned short, unsigned long *, unsigned long);
78*344a7f5eSAndroid Build Coastguard Worker void __int2c(void);
79*344a7f5eSAndroid Build Coastguard Worker void __invlpg(void *);
80*344a7f5eSAndroid Build Coastguard Worker unsigned short __inword(unsigned short);
81*344a7f5eSAndroid Build Coastguard Worker void __inwordstring(unsigned short, unsigned short *, unsigned long);
82*344a7f5eSAndroid Build Coastguard Worker void __lidt(void *);
83*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __ll_lshift(unsigned __int64, int);
84*344a7f5eSAndroid Build Coastguard Worker __int64 __ll_rshift(__int64, int);
85*344a7f5eSAndroid Build Coastguard Worker void __llwpcb(void *);
86*344a7f5eSAndroid Build Coastguard Worker unsigned char __lwpins32(unsigned int, unsigned int, unsigned int);
87*344a7f5eSAndroid Build Coastguard Worker void __lwpval32(unsigned int, unsigned int, unsigned int);
88*344a7f5eSAndroid Build Coastguard Worker unsigned int __lzcnt(unsigned int);
89*344a7f5eSAndroid Build Coastguard Worker unsigned short __lzcnt16(unsigned short);
90*344a7f5eSAndroid Build Coastguard Worker static __inline__
91*344a7f5eSAndroid Build Coastguard Worker void __movsb(unsigned char *, unsigned char const *, size_t);
92*344a7f5eSAndroid Build Coastguard Worker static __inline__
93*344a7f5eSAndroid Build Coastguard Worker void __movsd(unsigned long *, unsigned long const *, size_t);
94*344a7f5eSAndroid Build Coastguard Worker static __inline__
95*344a7f5eSAndroid Build Coastguard Worker void __movsw(unsigned short *, unsigned short const *, size_t);
96*344a7f5eSAndroid Build Coastguard Worker void __nop(void);
97*344a7f5eSAndroid Build Coastguard Worker void __nvreg_restore_fence(void);
98*344a7f5eSAndroid Build Coastguard Worker void __nvreg_save_fence(void);
99*344a7f5eSAndroid Build Coastguard Worker void __outbyte(unsigned short, unsigned char);
100*344a7f5eSAndroid Build Coastguard Worker void __outbytestring(unsigned short, unsigned char *, unsigned long);
101*344a7f5eSAndroid Build Coastguard Worker void __outdword(unsigned short, unsigned long);
102*344a7f5eSAndroid Build Coastguard Worker void __outdwordstring(unsigned short, unsigned long *, unsigned long);
103*344a7f5eSAndroid Build Coastguard Worker void __outword(unsigned short, unsigned short);
104*344a7f5eSAndroid Build Coastguard Worker void __outwordstring(unsigned short, unsigned short *, unsigned long);
105*344a7f5eSAndroid Build Coastguard Worker static __inline__
106*344a7f5eSAndroid Build Coastguard Worker unsigned int __popcnt(unsigned int);
107*344a7f5eSAndroid Build Coastguard Worker static __inline__
108*344a7f5eSAndroid Build Coastguard Worker unsigned short __popcnt16(unsigned short);
109*344a7f5eSAndroid Build Coastguard Worker unsigned long __readcr0(void);
110*344a7f5eSAndroid Build Coastguard Worker unsigned long __readcr2(void);
111*344a7f5eSAndroid Build Coastguard Worker static __inline__
112*344a7f5eSAndroid Build Coastguard Worker unsigned long __readcr3(void);
113*344a7f5eSAndroid Build Coastguard Worker unsigned long __readcr4(void);
114*344a7f5eSAndroid Build Coastguard Worker unsigned long __readcr8(void);
115*344a7f5eSAndroid Build Coastguard Worker unsigned int __readdr(unsigned int);
116*344a7f5eSAndroid Build Coastguard Worker #ifdef __i386__
117*344a7f5eSAndroid Build Coastguard Worker static __inline__
118*344a7f5eSAndroid Build Coastguard Worker unsigned char __readfsbyte(unsigned long);
119*344a7f5eSAndroid Build Coastguard Worker static __inline__
120*344a7f5eSAndroid Build Coastguard Worker unsigned long __readfsdword(unsigned long);
121*344a7f5eSAndroid Build Coastguard Worker static __inline__
122*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __readfsqword(unsigned long);
123*344a7f5eSAndroid Build Coastguard Worker static __inline__
124*344a7f5eSAndroid Build Coastguard Worker unsigned short __readfsword(unsigned long);
125*344a7f5eSAndroid Build Coastguard Worker #endif
126*344a7f5eSAndroid Build Coastguard Worker static __inline__
127*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __readmsr(unsigned long);
128*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __readpmc(unsigned long);
129*344a7f5eSAndroid Build Coastguard Worker unsigned long __segmentlimit(unsigned long);
130*344a7f5eSAndroid Build Coastguard Worker void __sidt(void *);
131*344a7f5eSAndroid Build Coastguard Worker void *__slwpcb(void);
132*344a7f5eSAndroid Build Coastguard Worker static __inline__
133*344a7f5eSAndroid Build Coastguard Worker void __stosb(unsigned char *, unsigned char, size_t);
134*344a7f5eSAndroid Build Coastguard Worker static __inline__
135*344a7f5eSAndroid Build Coastguard Worker void __stosd(unsigned long *, unsigned long, size_t);
136*344a7f5eSAndroid Build Coastguard Worker static __inline__
137*344a7f5eSAndroid Build Coastguard Worker void __stosw(unsigned short *, unsigned short, size_t);
138*344a7f5eSAndroid Build Coastguard Worker void __svm_clgi(void);
139*344a7f5eSAndroid Build Coastguard Worker void __svm_invlpga(void *, int);
140*344a7f5eSAndroid Build Coastguard Worker void __svm_skinit(int);
141*344a7f5eSAndroid Build Coastguard Worker void __svm_stgi(void);
142*344a7f5eSAndroid Build Coastguard Worker void __svm_vmload(size_t);
143*344a7f5eSAndroid Build Coastguard Worker void __svm_vmrun(size_t);
144*344a7f5eSAndroid Build Coastguard Worker void __svm_vmsave(size_t);
145*344a7f5eSAndroid Build Coastguard Worker void __ud2(void);
146*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __ull_rshift(unsigned __int64, int);
147*344a7f5eSAndroid Build Coastguard Worker void __vmx_off(void);
148*344a7f5eSAndroid Build Coastguard Worker void __vmx_vmptrst(unsigned __int64 *);
149*344a7f5eSAndroid Build Coastguard Worker void __wbinvd(void);
150*344a7f5eSAndroid Build Coastguard Worker void __writecr0(unsigned int);
151*344a7f5eSAndroid Build Coastguard Worker static __inline__
152*344a7f5eSAndroid Build Coastguard Worker void __writecr3(unsigned int);
153*344a7f5eSAndroid Build Coastguard Worker void __writecr4(unsigned int);
154*344a7f5eSAndroid Build Coastguard Worker void __writecr8(unsigned int);
155*344a7f5eSAndroid Build Coastguard Worker void __writedr(unsigned int, unsigned int);
156*344a7f5eSAndroid Build Coastguard Worker void __writefsbyte(unsigned long, unsigned char);
157*344a7f5eSAndroid Build Coastguard Worker void __writefsdword(unsigned long, unsigned long);
158*344a7f5eSAndroid Build Coastguard Worker void __writefsqword(unsigned long, unsigned __int64);
159*344a7f5eSAndroid Build Coastguard Worker void __writefsword(unsigned long, unsigned short);
160*344a7f5eSAndroid Build Coastguard Worker void __writemsr(unsigned long, unsigned __int64);
161*344a7f5eSAndroid Build Coastguard Worker static __inline__
162*344a7f5eSAndroid Build Coastguard Worker void *_AddressOfReturnAddress(void);
163*344a7f5eSAndroid Build Coastguard Worker static __inline__
164*344a7f5eSAndroid Build Coastguard Worker unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
165*344a7f5eSAndroid Build Coastguard Worker static __inline__
166*344a7f5eSAndroid Build Coastguard Worker unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
167*344a7f5eSAndroid Build Coastguard Worker static __inline__
168*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittest(long const *, long);
169*344a7f5eSAndroid Build Coastguard Worker static __inline__
170*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandcomplement(long *, long);
171*344a7f5eSAndroid Build Coastguard Worker static __inline__
172*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandreset(long *, long);
173*344a7f5eSAndroid Build Coastguard Worker static __inline__
174*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandset(long *, long);
175*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
176*344a7f5eSAndroid Build Coastguard Worker unsigned long __cdecl _byteswap_ulong(unsigned long);
177*344a7f5eSAndroid Build Coastguard Worker unsigned short __cdecl _byteswap_ushort(unsigned short);
178*344a7f5eSAndroid Build Coastguard Worker void __cdecl _disable(void);
179*344a7f5eSAndroid Build Coastguard Worker void __cdecl _enable(void);
180*344a7f5eSAndroid Build Coastguard Worker long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
181*344a7f5eSAndroid Build Coastguard Worker static __inline__
182*344a7f5eSAndroid Build Coastguard Worker long _InterlockedAnd(long volatile *_Value, long _Mask);
183*344a7f5eSAndroid Build Coastguard Worker static __inline__
184*344a7f5eSAndroid Build Coastguard Worker short _InterlockedAnd16(short volatile *_Value, short _Mask);
185*344a7f5eSAndroid Build Coastguard Worker static __inline__
186*344a7f5eSAndroid Build Coastguard Worker char _InterlockedAnd8(char volatile *_Value, char _Mask);
187*344a7f5eSAndroid Build Coastguard Worker unsigned char _interlockedbittestandreset(long volatile *, long);
188*344a7f5eSAndroid Build Coastguard Worker static __inline__
189*344a7f5eSAndroid Build Coastguard Worker unsigned char _interlockedbittestandset(long volatile *, long);
190*344a7f5eSAndroid Build Coastguard Worker static __inline__
191*344a7f5eSAndroid Build Coastguard Worker long __cdecl _InterlockedCompareExchange(long volatile *_Destination,
192*344a7f5eSAndroid Build Coastguard Worker long _Exchange, long _Comparand);
193*344a7f5eSAndroid Build Coastguard Worker long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long);
194*344a7f5eSAndroid Build Coastguard Worker long _InterlockedCompareExchange_HLERelease(long volatile *, long, long);
195*344a7f5eSAndroid Build Coastguard Worker static __inline__
196*344a7f5eSAndroid Build Coastguard Worker short _InterlockedCompareExchange16(short volatile *_Destination,
197*344a7f5eSAndroid Build Coastguard Worker short _Exchange, short _Comparand);
198*344a7f5eSAndroid Build Coastguard Worker static __inline__
199*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedCompareExchange64(__int64 volatile *_Destination,
200*344a7f5eSAndroid Build Coastguard Worker __int64 _Exchange, __int64 _Comparand);
201*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedcompareExchange64_HLEAcquire(__int64 volatile *, __int64,
202*344a7f5eSAndroid Build Coastguard Worker __int64);
203*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64,
204*344a7f5eSAndroid Build Coastguard Worker __int64);
205*344a7f5eSAndroid Build Coastguard Worker static __inline__
206*344a7f5eSAndroid Build Coastguard Worker char _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange,
207*344a7f5eSAndroid Build Coastguard Worker char _Comparand);
208*344a7f5eSAndroid Build Coastguard Worker void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
209*344a7f5eSAndroid Build Coastguard Worker void *);
210*344a7f5eSAndroid Build Coastguard Worker void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
211*344a7f5eSAndroid Build Coastguard Worker void *);
212*344a7f5eSAndroid Build Coastguard Worker static __inline__
213*344a7f5eSAndroid Build Coastguard Worker long __cdecl _InterlockedDecrement(long volatile *_Addend);
214*344a7f5eSAndroid Build Coastguard Worker static __inline__
215*344a7f5eSAndroid Build Coastguard Worker short _InterlockedDecrement16(short volatile *_Addend);
216*344a7f5eSAndroid Build Coastguard Worker long _InterlockedExchange(long volatile *_Target, long _Value);
217*344a7f5eSAndroid Build Coastguard Worker static __inline__
218*344a7f5eSAndroid Build Coastguard Worker short _InterlockedExchange16(short volatile *_Target, short _Value);
219*344a7f5eSAndroid Build Coastguard Worker static __inline__
220*344a7f5eSAndroid Build Coastguard Worker char _InterlockedExchange8(char volatile *_Target, char _Value);
221*344a7f5eSAndroid Build Coastguard Worker static __inline__
222*344a7f5eSAndroid Build Coastguard Worker long __cdecl _InterlockedExchangeAdd(long volatile *_Addend, long _Value);
223*344a7f5eSAndroid Build Coastguard Worker long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
224*344a7f5eSAndroid Build Coastguard Worker long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
225*344a7f5eSAndroid Build Coastguard Worker static __inline__
226*344a7f5eSAndroid Build Coastguard Worker short _InterlockedExchangeAdd16(short volatile *_Addend, short _Value);
227*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
228*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
229*344a7f5eSAndroid Build Coastguard Worker static __inline__
230*344a7f5eSAndroid Build Coastguard Worker char _InterlockedExchangeAdd8(char volatile *_Addend, char _Value);
231*344a7f5eSAndroid Build Coastguard Worker static __inline__
232*344a7f5eSAndroid Build Coastguard Worker long __cdecl _InterlockedIncrement(long volatile *_Addend);
233*344a7f5eSAndroid Build Coastguard Worker static __inline__
234*344a7f5eSAndroid Build Coastguard Worker short _InterlockedIncrement16(short volatile *_Addend);
235*344a7f5eSAndroid Build Coastguard Worker static __inline__
236*344a7f5eSAndroid Build Coastguard Worker long _InterlockedOr(long volatile *_Value, long _Mask);
237*344a7f5eSAndroid Build Coastguard Worker static __inline__
238*344a7f5eSAndroid Build Coastguard Worker short _InterlockedOr16(short volatile *_Value, short _Mask);
239*344a7f5eSAndroid Build Coastguard Worker static __inline__
240*344a7f5eSAndroid Build Coastguard Worker char _InterlockedOr8(char volatile *_Value, char _Mask);
241*344a7f5eSAndroid Build Coastguard Worker static __inline__
242*344a7f5eSAndroid Build Coastguard Worker long _InterlockedXor(long volatile *_Value, long _Mask);
243*344a7f5eSAndroid Build Coastguard Worker static __inline__
244*344a7f5eSAndroid Build Coastguard Worker short _InterlockedXor16(short volatile *_Value, short _Mask);
245*344a7f5eSAndroid Build Coastguard Worker static __inline__
246*344a7f5eSAndroid Build Coastguard Worker char _InterlockedXor8(char volatile *_Value, char _Mask);
247*344a7f5eSAndroid Build Coastguard Worker void __cdecl _invpcid(unsigned int, void *);
248*344a7f5eSAndroid Build Coastguard Worker static __inline__
249*344a7f5eSAndroid Build Coastguard Worker unsigned long __cdecl _lrotl(unsigned long, int);
250*344a7f5eSAndroid Build Coastguard Worker static __inline__
251*344a7f5eSAndroid Build Coastguard Worker unsigned long __cdecl _lrotr(unsigned long, int);
252*344a7f5eSAndroid Build Coastguard Worker static __inline__
253*344a7f5eSAndroid Build Coastguard Worker void _ReadBarrier(void);
254*344a7f5eSAndroid Build Coastguard Worker static __inline__
255*344a7f5eSAndroid Build Coastguard Worker void _ReadWriteBarrier(void);
256*344a7f5eSAndroid Build Coastguard Worker static __inline__
257*344a7f5eSAndroid Build Coastguard Worker void *_ReturnAddress(void);
258*344a7f5eSAndroid Build Coastguard Worker unsigned int _rorx_u32(unsigned int, const unsigned int);
259*344a7f5eSAndroid Build Coastguard Worker static __inline__
260*344a7f5eSAndroid Build Coastguard Worker unsigned int __cdecl _rotl(unsigned int _Value, int _Shift);
261*344a7f5eSAndroid Build Coastguard Worker static __inline__
262*344a7f5eSAndroid Build Coastguard Worker unsigned short _rotl16(unsigned short _Value, unsigned char _Shift);
263*344a7f5eSAndroid Build Coastguard Worker static __inline__
264*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __cdecl _rotl64(unsigned __int64 _Value, int _Shift);
265*344a7f5eSAndroid Build Coastguard Worker static __inline__
266*344a7f5eSAndroid Build Coastguard Worker unsigned char _rotl8(unsigned char _Value, unsigned char _Shift);
267*344a7f5eSAndroid Build Coastguard Worker static __inline__
268*344a7f5eSAndroid Build Coastguard Worker unsigned int __cdecl _rotr(unsigned int _Value, int _Shift);
269*344a7f5eSAndroid Build Coastguard Worker static __inline__
270*344a7f5eSAndroid Build Coastguard Worker unsigned short _rotr16(unsigned short _Value, unsigned char _Shift);
271*344a7f5eSAndroid Build Coastguard Worker static __inline__
272*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __cdecl _rotr64(unsigned __int64 _Value, int _Shift);
273*344a7f5eSAndroid Build Coastguard Worker static __inline__
274*344a7f5eSAndroid Build Coastguard Worker unsigned char _rotr8(unsigned char _Value, unsigned char _Shift);
275*344a7f5eSAndroid Build Coastguard Worker int _sarx_i32(int, unsigned int);
276*344a7f5eSAndroid Build Coastguard Worker #if __STDC_HOSTED__
277*344a7f5eSAndroid Build Coastguard Worker int __cdecl _setjmp(jmp_buf);
278*344a7f5eSAndroid Build Coastguard Worker #endif
279*344a7f5eSAndroid Build Coastguard Worker unsigned int _shlx_u32(unsigned int, unsigned int);
280*344a7f5eSAndroid Build Coastguard Worker unsigned int _shrx_u32(unsigned int, unsigned int);
281*344a7f5eSAndroid Build Coastguard Worker void _Store_HLERelease(long volatile *, long);
282*344a7f5eSAndroid Build Coastguard Worker void _Store64_HLERelease(__int64 volatile *, __int64);
283*344a7f5eSAndroid Build Coastguard Worker void _StorePointer_HLERelease(void *volatile *, void *);
284*344a7f5eSAndroid Build Coastguard Worker static __inline__
285*344a7f5eSAndroid Build Coastguard Worker void _WriteBarrier(void);
286*344a7f5eSAndroid Build Coastguard Worker unsigned __int32 xbegin(void);
287*344a7f5eSAndroid Build Coastguard Worker void _xend(void);
288*344a7f5eSAndroid Build Coastguard Worker static __inline__
289*344a7f5eSAndroid Build Coastguard Worker #define _XCR_XFEATURE_ENABLED_MASK 0
290*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __cdecl _xgetbv(unsigned int);
291*344a7f5eSAndroid Build Coastguard Worker void __cdecl _xsetbv(unsigned int, unsigned __int64);
292*344a7f5eSAndroid Build Coastguard Worker
293*344a7f5eSAndroid Build Coastguard Worker /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
294*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
295*344a7f5eSAndroid Build Coastguard Worker void __addgsbyte(unsigned long, unsigned char);
296*344a7f5eSAndroid Build Coastguard Worker void __addgsdword(unsigned long, unsigned long);
297*344a7f5eSAndroid Build Coastguard Worker void __addgsqword(unsigned long, unsigned __int64);
298*344a7f5eSAndroid Build Coastguard Worker void __addgsword(unsigned long, unsigned short);
299*344a7f5eSAndroid Build Coastguard Worker static __inline__
300*344a7f5eSAndroid Build Coastguard Worker void __faststorefence(void);
301*344a7f5eSAndroid Build Coastguard Worker void __incgsbyte(unsigned long);
302*344a7f5eSAndroid Build Coastguard Worker void __incgsdword(unsigned long);
303*344a7f5eSAndroid Build Coastguard Worker void __incgsqword(unsigned long);
304*344a7f5eSAndroid Build Coastguard Worker void __incgsword(unsigned long);
305*344a7f5eSAndroid Build Coastguard Worker unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int);
306*344a7f5eSAndroid Build Coastguard Worker void __lwpval64(unsigned __int64, unsigned int, unsigned int);
307*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __lzcnt64(unsigned __int64);
308*344a7f5eSAndroid Build Coastguard Worker static __inline__
309*344a7f5eSAndroid Build Coastguard Worker void __movsq(unsigned long long *, unsigned long long const *, size_t);
310*344a7f5eSAndroid Build Coastguard Worker __int64 __mulh(__int64, __int64);
311*344a7f5eSAndroid Build Coastguard Worker static __inline__
312*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __popcnt64(unsigned __int64);
313*344a7f5eSAndroid Build Coastguard Worker static __inline__
314*344a7f5eSAndroid Build Coastguard Worker unsigned char __readgsbyte(unsigned long);
315*344a7f5eSAndroid Build Coastguard Worker static __inline__
316*344a7f5eSAndroid Build Coastguard Worker unsigned long __readgsdword(unsigned long);
317*344a7f5eSAndroid Build Coastguard Worker static __inline__
318*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __readgsqword(unsigned long);
319*344a7f5eSAndroid Build Coastguard Worker unsigned short __readgsword(unsigned long);
320*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
321*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 _HighPart,
322*344a7f5eSAndroid Build Coastguard Worker unsigned char _Shift);
323*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
324*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 _HighPart,
325*344a7f5eSAndroid Build Coastguard Worker unsigned char _Shift);
326*344a7f5eSAndroid Build Coastguard Worker static __inline__
327*344a7f5eSAndroid Build Coastguard Worker void __stosq(unsigned __int64 *, unsigned __int64, size_t);
328*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_on(unsigned __int64 *);
329*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmclear(unsigned __int64 *);
330*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmlaunch(void);
331*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmptrld(unsigned __int64 *);
332*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmread(size_t, size_t *);
333*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmresume(void);
334*344a7f5eSAndroid Build Coastguard Worker unsigned char __vmx_vmwrite(size_t, size_t);
335*344a7f5eSAndroid Build Coastguard Worker void __writegsbyte(unsigned long, unsigned char);
336*344a7f5eSAndroid Build Coastguard Worker void __writegsdword(unsigned long, unsigned long);
337*344a7f5eSAndroid Build Coastguard Worker void __writegsqword(unsigned long, unsigned __int64);
338*344a7f5eSAndroid Build Coastguard Worker void __writegsword(unsigned long, unsigned short);
339*344a7f5eSAndroid Build Coastguard Worker static __inline__
340*344a7f5eSAndroid Build Coastguard Worker unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
341*344a7f5eSAndroid Build Coastguard Worker static __inline__
342*344a7f5eSAndroid Build Coastguard Worker unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
343*344a7f5eSAndroid Build Coastguard Worker static __inline__
344*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittest64(__int64 const *, __int64);
345*344a7f5eSAndroid Build Coastguard Worker static __inline__
346*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandcomplement64(__int64 *, __int64);
347*344a7f5eSAndroid Build Coastguard Worker static __inline__
348*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandreset64(__int64 *, __int64);
349*344a7f5eSAndroid Build Coastguard Worker static __inline__
350*344a7f5eSAndroid Build Coastguard Worker unsigned char _bittestandset64(__int64 *, __int64);
351*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
352*344a7f5eSAndroid Build Coastguard Worker long _InterlockedAnd_np(long volatile *_Value, long _Mask);
353*344a7f5eSAndroid Build Coastguard Worker short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
354*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
355*344a7f5eSAndroid Build Coastguard Worker char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
356*344a7f5eSAndroid Build Coastguard Worker unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
357*344a7f5eSAndroid Build Coastguard Worker static __inline__
358*344a7f5eSAndroid Build Coastguard Worker unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
359*344a7f5eSAndroid Build Coastguard Worker long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
360*344a7f5eSAndroid Build Coastguard Worker long _Comparand);
361*344a7f5eSAndroid Build Coastguard Worker unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
362*344a7f5eSAndroid Build Coastguard Worker __int64 _ExchangeHigh,
363*344a7f5eSAndroid Build Coastguard Worker __int64 _ExchangeLow,
364*344a7f5eSAndroid Build Coastguard Worker __int64 *_CompareandResult);
365*344a7f5eSAndroid Build Coastguard Worker unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
366*344a7f5eSAndroid Build Coastguard Worker __int64 _ExchangeHigh,
367*344a7f5eSAndroid Build Coastguard Worker __int64 _ExchangeLow,
368*344a7f5eSAndroid Build Coastguard Worker __int64 *_ComparandResult);
369*344a7f5eSAndroid Build Coastguard Worker short _InterlockedCompareExchange16_np(short volatile *_Destination,
370*344a7f5eSAndroid Build Coastguard Worker short _Exchange, short _Comparand);
371*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64,
372*344a7f5eSAndroid Build Coastguard Worker __int64);
373*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64,
374*344a7f5eSAndroid Build Coastguard Worker __int64);
375*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
376*344a7f5eSAndroid Build Coastguard Worker __int64 _Exchange, __int64 _Comparand);
377*344a7f5eSAndroid Build Coastguard Worker void *_InterlockedCompareExchangePointer(void *volatile *_Destination,
378*344a7f5eSAndroid Build Coastguard Worker void *_Exchange, void *_Comparand);
379*344a7f5eSAndroid Build Coastguard Worker void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
380*344a7f5eSAndroid Build Coastguard Worker void *_Exchange, void *_Comparand);
381*344a7f5eSAndroid Build Coastguard Worker static __inline__
382*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
383*344a7f5eSAndroid Build Coastguard Worker static __inline__
384*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
385*344a7f5eSAndroid Build Coastguard Worker static __inline__
386*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
387*344a7f5eSAndroid Build Coastguard Worker void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value);
388*344a7f5eSAndroid Build Coastguard Worker static __inline__
389*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
390*344a7f5eSAndroid Build Coastguard Worker long _InterlockedOr_np(long volatile *_Value, long _Mask);
391*344a7f5eSAndroid Build Coastguard Worker short _InterlockedOr16_np(short volatile *_Value, short _Mask);
392*344a7f5eSAndroid Build Coastguard Worker static __inline__
393*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
394*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
395*344a7f5eSAndroid Build Coastguard Worker char _InterlockedOr8_np(char volatile *_Value, char _Mask);
396*344a7f5eSAndroid Build Coastguard Worker long _InterlockedXor_np(long volatile *_Value, long _Mask);
397*344a7f5eSAndroid Build Coastguard Worker short _InterlockedXor16_np(short volatile *_Value, short _Mask);
398*344a7f5eSAndroid Build Coastguard Worker static __inline__
399*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
400*344a7f5eSAndroid Build Coastguard Worker __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
401*344a7f5eSAndroid Build Coastguard Worker char _InterlockedXor8_np(char volatile *_Value, char _Mask);
402*344a7f5eSAndroid Build Coastguard Worker static __inline__
403*344a7f5eSAndroid Build Coastguard Worker __int64 _mul128(__int64 _Multiplier, __int64 _Multiplicand,
404*344a7f5eSAndroid Build Coastguard Worker __int64 *_HighProduct);
405*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
406*344a7f5eSAndroid Build Coastguard Worker __int64 _sarx_i64(__int64, unsigned int);
407*344a7f5eSAndroid Build Coastguard Worker #if __STDC_HOSTED__
408*344a7f5eSAndroid Build Coastguard Worker int __cdecl _setjmpex(jmp_buf);
409*344a7f5eSAndroid Build Coastguard Worker #endif
410*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
411*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
412*344a7f5eSAndroid Build Coastguard Worker /*
413*344a7f5eSAndroid Build Coastguard Worker * Multiply two 64-bit integers and obtain a 64-bit result.
414*344a7f5eSAndroid Build Coastguard Worker * The low-half is returned directly and the high half is in an out parameter.
415*344a7f5eSAndroid Build Coastguard Worker */
416*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
_umul128(unsigned __int64 _Multiplier,unsigned __int64 _Multiplicand,unsigned __int64 * _HighProduct)417*344a7f5eSAndroid Build Coastguard Worker _umul128(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand,
418*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 *_HighProduct) {
419*344a7f5eSAndroid Build Coastguard Worker unsigned __int128 _FullProduct =
420*344a7f5eSAndroid Build Coastguard Worker (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand;
421*344a7f5eSAndroid Build Coastguard Worker *_HighProduct = _FullProduct >> 64;
422*344a7f5eSAndroid Build Coastguard Worker return _FullProduct;
423*344a7f5eSAndroid Build Coastguard Worker }
424*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__umulh(unsigned __int64 _Multiplier,unsigned __int64 _Multiplicand)425*344a7f5eSAndroid Build Coastguard Worker __umulh(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand) {
426*344a7f5eSAndroid Build Coastguard Worker unsigned __int128 _FullProduct =
427*344a7f5eSAndroid Build Coastguard Worker (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand;
428*344a7f5eSAndroid Build Coastguard Worker return _FullProduct >> 64;
429*344a7f5eSAndroid Build Coastguard Worker }
430*344a7f5eSAndroid Build Coastguard Worker
431*344a7f5eSAndroid Build Coastguard Worker #endif /* __x86_64__ */
432*344a7f5eSAndroid Build Coastguard Worker
433*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
434*344a7f5eSAndroid Build Coastguard Worker |* Multiplication
435*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
436*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
__emul(int __in1,int __in2)437*344a7f5eSAndroid Build Coastguard Worker __emul(int __in1, int __in2) {
438*344a7f5eSAndroid Build Coastguard Worker return (__int64)__in1 * (__int64)__in2;
439*344a7f5eSAndroid Build Coastguard Worker }
440*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__emulu(unsigned int __in1,unsigned int __in2)441*344a7f5eSAndroid Build Coastguard Worker __emulu(unsigned int __in1, unsigned int __in2) {
442*344a7f5eSAndroid Build Coastguard Worker return (unsigned __int64)__in1 * (unsigned __int64)__in2;
443*344a7f5eSAndroid Build Coastguard Worker }
444*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
445*344a7f5eSAndroid Build Coastguard Worker |* Bit Twiddling
446*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
447*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_rotl8(unsigned char _Value,unsigned char _Shift)448*344a7f5eSAndroid Build Coastguard Worker _rotl8(unsigned char _Value, unsigned char _Shift) {
449*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x7;
450*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value << _Shift) | (_Value >> (8 - _Shift)) : _Value;
451*344a7f5eSAndroid Build Coastguard Worker }
452*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_rotr8(unsigned char _Value,unsigned char _Shift)453*344a7f5eSAndroid Build Coastguard Worker _rotr8(unsigned char _Value, unsigned char _Shift) {
454*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x7;
455*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value >> _Shift) | (_Value << (8 - _Shift)) : _Value;
456*344a7f5eSAndroid Build Coastguard Worker }
457*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned short __DEFAULT_FN_ATTRS
_rotl16(unsigned short _Value,unsigned char _Shift)458*344a7f5eSAndroid Build Coastguard Worker _rotl16(unsigned short _Value, unsigned char _Shift) {
459*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0xf;
460*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value << _Shift) | (_Value >> (16 - _Shift)) : _Value;
461*344a7f5eSAndroid Build Coastguard Worker }
462*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned short __DEFAULT_FN_ATTRS
_rotr16(unsigned short _Value,unsigned char _Shift)463*344a7f5eSAndroid Build Coastguard Worker _rotr16(unsigned short _Value, unsigned char _Shift) {
464*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0xf;
465*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value >> _Shift) | (_Value << (16 - _Shift)) : _Value;
466*344a7f5eSAndroid Build Coastguard Worker }
467*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned int __DEFAULT_FN_ATTRS
_rotl(unsigned int _Value,int _Shift)468*344a7f5eSAndroid Build Coastguard Worker _rotl(unsigned int _Value, int _Shift) {
469*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x1f;
470*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value;
471*344a7f5eSAndroid Build Coastguard Worker }
472*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned int __DEFAULT_FN_ATTRS
_rotr(unsigned int _Value,int _Shift)473*344a7f5eSAndroid Build Coastguard Worker _rotr(unsigned int _Value, int _Shift) {
474*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x1f;
475*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value;
476*344a7f5eSAndroid Build Coastguard Worker }
477*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned long __DEFAULT_FN_ATTRS
_lrotl(unsigned long _Value,int _Shift)478*344a7f5eSAndroid Build Coastguard Worker _lrotl(unsigned long _Value, int _Shift) {
479*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x1f;
480*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value;
481*344a7f5eSAndroid Build Coastguard Worker }
482*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned long __DEFAULT_FN_ATTRS
_lrotr(unsigned long _Value,int _Shift)483*344a7f5eSAndroid Build Coastguard Worker _lrotr(unsigned long _Value, int _Shift) {
484*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x1f;
485*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value;
486*344a7f5eSAndroid Build Coastguard Worker }
487*344a7f5eSAndroid Build Coastguard Worker static
488*344a7f5eSAndroid Build Coastguard Worker __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
_rotl64(unsigned __int64 _Value,int _Shift)489*344a7f5eSAndroid Build Coastguard Worker _rotl64(unsigned __int64 _Value, int _Shift) {
490*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x3f;
491*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value << _Shift) | (_Value >> (64 - _Shift)) : _Value;
492*344a7f5eSAndroid Build Coastguard Worker }
493*344a7f5eSAndroid Build Coastguard Worker static
494*344a7f5eSAndroid Build Coastguard Worker __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
_rotr64(unsigned __int64 _Value,int _Shift)495*344a7f5eSAndroid Build Coastguard Worker _rotr64(unsigned __int64 _Value, int _Shift) {
496*344a7f5eSAndroid Build Coastguard Worker _Shift &= 0x3f;
497*344a7f5eSAndroid Build Coastguard Worker return _Shift ? (_Value >> _Shift) | (_Value << (64 - _Shift)) : _Value;
498*344a7f5eSAndroid Build Coastguard Worker }
499*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
500*344a7f5eSAndroid Build Coastguard Worker |* Bit Counting and Testing
501*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
502*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_BitScanForward(unsigned long * _Index,unsigned long _Mask)503*344a7f5eSAndroid Build Coastguard Worker _BitScanForward(unsigned long *_Index, unsigned long _Mask) {
504*344a7f5eSAndroid Build Coastguard Worker if (!_Mask)
505*344a7f5eSAndroid Build Coastguard Worker return 0;
506*344a7f5eSAndroid Build Coastguard Worker *_Index = __builtin_ctzl(_Mask);
507*344a7f5eSAndroid Build Coastguard Worker return 1;
508*344a7f5eSAndroid Build Coastguard Worker }
509*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_BitScanReverse(unsigned long * _Index,unsigned long _Mask)510*344a7f5eSAndroid Build Coastguard Worker _BitScanReverse(unsigned long *_Index, unsigned long _Mask) {
511*344a7f5eSAndroid Build Coastguard Worker if (!_Mask)
512*344a7f5eSAndroid Build Coastguard Worker return 0;
513*344a7f5eSAndroid Build Coastguard Worker *_Index = 31 - __builtin_clzl(_Mask);
514*344a7f5eSAndroid Build Coastguard Worker return 1;
515*344a7f5eSAndroid Build Coastguard Worker }
516*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned short __DEFAULT_FN_ATTRS
__popcnt16(unsigned short _Value)517*344a7f5eSAndroid Build Coastguard Worker __popcnt16(unsigned short _Value) {
518*344a7f5eSAndroid Build Coastguard Worker return __builtin_popcount((int)_Value);
519*344a7f5eSAndroid Build Coastguard Worker }
520*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned int __DEFAULT_FN_ATTRS
__popcnt(unsigned int _Value)521*344a7f5eSAndroid Build Coastguard Worker __popcnt(unsigned int _Value) {
522*344a7f5eSAndroid Build Coastguard Worker return __builtin_popcount(_Value);
523*344a7f5eSAndroid Build Coastguard Worker }
524*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittest(long const * _BitBase,long _BitPos)525*344a7f5eSAndroid Build Coastguard Worker _bittest(long const *_BitBase, long _BitPos) {
526*344a7f5eSAndroid Build Coastguard Worker return (*_BitBase >> _BitPos) & 1;
527*344a7f5eSAndroid Build Coastguard Worker }
528*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandcomplement(long * _BitBase,long _BitPos)529*344a7f5eSAndroid Build Coastguard Worker _bittestandcomplement(long *_BitBase, long _BitPos) {
530*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
531*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase ^ (1 << _BitPos);
532*344a7f5eSAndroid Build Coastguard Worker return _Res;
533*344a7f5eSAndroid Build Coastguard Worker }
534*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandreset(long * _BitBase,long _BitPos)535*344a7f5eSAndroid Build Coastguard Worker _bittestandreset(long *_BitBase, long _BitPos) {
536*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
537*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase & ~(1 << _BitPos);
538*344a7f5eSAndroid Build Coastguard Worker return _Res;
539*344a7f5eSAndroid Build Coastguard Worker }
540*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandset(long * _BitBase,long _BitPos)541*344a7f5eSAndroid Build Coastguard Worker _bittestandset(long *_BitBase, long _BitPos) {
542*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
543*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase | (1 << _BitPos);
544*344a7f5eSAndroid Build Coastguard Worker return _Res;
545*344a7f5eSAndroid Build Coastguard Worker }
546*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_interlockedbittestandset(long volatile * _BitBase,long _BitPos)547*344a7f5eSAndroid Build Coastguard Worker _interlockedbittestandset(long volatile *_BitBase, long _BitPos) {
548*344a7f5eSAndroid Build Coastguard Worker long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST);
549*344a7f5eSAndroid Build Coastguard Worker return (_PrevVal >> _BitPos) & 1;
550*344a7f5eSAndroid Build Coastguard Worker }
551*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
552*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_BitScanForward64(unsigned long * _Index,unsigned __int64 _Mask)553*344a7f5eSAndroid Build Coastguard Worker _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) {
554*344a7f5eSAndroid Build Coastguard Worker if (!_Mask)
555*344a7f5eSAndroid Build Coastguard Worker return 0;
556*344a7f5eSAndroid Build Coastguard Worker *_Index = __builtin_ctzll(_Mask);
557*344a7f5eSAndroid Build Coastguard Worker return 1;
558*344a7f5eSAndroid Build Coastguard Worker }
559*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_BitScanReverse64(unsigned long * _Index,unsigned __int64 _Mask)560*344a7f5eSAndroid Build Coastguard Worker _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) {
561*344a7f5eSAndroid Build Coastguard Worker if (!_Mask)
562*344a7f5eSAndroid Build Coastguard Worker return 0;
563*344a7f5eSAndroid Build Coastguard Worker *_Index = 63 - __builtin_clzll(_Mask);
564*344a7f5eSAndroid Build Coastguard Worker return 1;
565*344a7f5eSAndroid Build Coastguard Worker }
566*344a7f5eSAndroid Build Coastguard Worker static __inline__
567*344a7f5eSAndroid Build Coastguard Worker unsigned __int64 __DEFAULT_FN_ATTRS
__popcnt64(unsigned __int64 _Value)568*344a7f5eSAndroid Build Coastguard Worker __popcnt64(unsigned __int64 _Value) {
569*344a7f5eSAndroid Build Coastguard Worker return __builtin_popcountll(_Value);
570*344a7f5eSAndroid Build Coastguard Worker }
571*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittest64(__int64 const * _BitBase,__int64 _BitPos)572*344a7f5eSAndroid Build Coastguard Worker _bittest64(__int64 const *_BitBase, __int64 _BitPos) {
573*344a7f5eSAndroid Build Coastguard Worker return (*_BitBase >> _BitPos) & 1;
574*344a7f5eSAndroid Build Coastguard Worker }
575*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandcomplement64(__int64 * _BitBase,__int64 _BitPos)576*344a7f5eSAndroid Build Coastguard Worker _bittestandcomplement64(__int64 *_BitBase, __int64 _BitPos) {
577*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
578*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase ^ (1ll << _BitPos);
579*344a7f5eSAndroid Build Coastguard Worker return _Res;
580*344a7f5eSAndroid Build Coastguard Worker }
581*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandreset64(__int64 * _BitBase,__int64 _BitPos)582*344a7f5eSAndroid Build Coastguard Worker _bittestandreset64(__int64 *_BitBase, __int64 _BitPos) {
583*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
584*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase & ~(1ll << _BitPos);
585*344a7f5eSAndroid Build Coastguard Worker return _Res;
586*344a7f5eSAndroid Build Coastguard Worker }
587*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_bittestandset64(__int64 * _BitBase,__int64 _BitPos)588*344a7f5eSAndroid Build Coastguard Worker _bittestandset64(__int64 *_BitBase, __int64 _BitPos) {
589*344a7f5eSAndroid Build Coastguard Worker unsigned char _Res = (*_BitBase >> _BitPos) & 1;
590*344a7f5eSAndroid Build Coastguard Worker *_BitBase = *_BitBase | (1ll << _BitPos);
591*344a7f5eSAndroid Build Coastguard Worker return _Res;
592*344a7f5eSAndroid Build Coastguard Worker }
593*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_interlockedbittestandset64(__int64 volatile * _BitBase,__int64 _BitPos)594*344a7f5eSAndroid Build Coastguard Worker _interlockedbittestandset64(__int64 volatile *_BitBase, __int64 _BitPos) {
595*344a7f5eSAndroid Build Coastguard Worker long long _PrevVal =
596*344a7f5eSAndroid Build Coastguard Worker __atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST);
597*344a7f5eSAndroid Build Coastguard Worker return (_PrevVal >> _BitPos) & 1;
598*344a7f5eSAndroid Build Coastguard Worker }
599*344a7f5eSAndroid Build Coastguard Worker #endif
600*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
601*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Exchange Add
602*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
603*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd8(char volatile * _Addend,char _Value)604*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeAdd8(char volatile *_Addend, char _Value) {
605*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
606*344a7f5eSAndroid Build Coastguard Worker }
607*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd16(short volatile * _Addend,short _Value)608*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeAdd16(short volatile *_Addend, short _Value) {
609*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
610*344a7f5eSAndroid Build Coastguard Worker }
611*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
612*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd64(__int64 volatile * _Addend,__int64 _Value)613*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) {
614*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
615*344a7f5eSAndroid Build Coastguard Worker }
616*344a7f5eSAndroid Build Coastguard Worker #endif
617*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
618*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Exchange Sub
619*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
620*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchangeSub8(char volatile * _Subend,char _Value)621*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeSub8(char volatile *_Subend, char _Value) {
622*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
623*344a7f5eSAndroid Build Coastguard Worker }
624*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchangeSub16(short volatile * _Subend,short _Value)625*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeSub16(short volatile *_Subend, short _Value) {
626*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
627*344a7f5eSAndroid Build Coastguard Worker }
628*344a7f5eSAndroid Build Coastguard Worker static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchangeSub(long volatile * _Subend,long _Value)629*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeSub(long volatile *_Subend, long _Value) {
630*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
631*344a7f5eSAndroid Build Coastguard Worker }
632*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
633*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchangeSub64(__int64 volatile * _Subend,__int64 _Value)634*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) {
635*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
636*344a7f5eSAndroid Build Coastguard Worker }
637*344a7f5eSAndroid Build Coastguard Worker #endif
638*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
639*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Increment
640*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
641*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedIncrement16(short volatile * _Value)642*344a7f5eSAndroid Build Coastguard Worker _InterlockedIncrement16(short volatile *_Value) {
643*344a7f5eSAndroid Build Coastguard Worker return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST);
644*344a7f5eSAndroid Build Coastguard Worker }
645*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
646*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedIncrement64(__int64 volatile * _Value)647*344a7f5eSAndroid Build Coastguard Worker _InterlockedIncrement64(__int64 volatile *_Value) {
648*344a7f5eSAndroid Build Coastguard Worker return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST);
649*344a7f5eSAndroid Build Coastguard Worker }
650*344a7f5eSAndroid Build Coastguard Worker #endif
651*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
652*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Decrement
653*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
654*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedDecrement16(short volatile * _Value)655*344a7f5eSAndroid Build Coastguard Worker _InterlockedDecrement16(short volatile *_Value) {
656*344a7f5eSAndroid Build Coastguard Worker return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST);
657*344a7f5eSAndroid Build Coastguard Worker }
658*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
659*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedDecrement64(__int64 volatile * _Value)660*344a7f5eSAndroid Build Coastguard Worker _InterlockedDecrement64(__int64 volatile *_Value) {
661*344a7f5eSAndroid Build Coastguard Worker return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST);
662*344a7f5eSAndroid Build Coastguard Worker }
663*344a7f5eSAndroid Build Coastguard Worker #endif
664*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
665*344a7f5eSAndroid Build Coastguard Worker |* Interlocked And
666*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
667*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedAnd8(char volatile * _Value,char _Mask)668*344a7f5eSAndroid Build Coastguard Worker _InterlockedAnd8(char volatile *_Value, char _Mask) {
669*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST);
670*344a7f5eSAndroid Build Coastguard Worker }
671*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedAnd16(short volatile * _Value,short _Mask)672*344a7f5eSAndroid Build Coastguard Worker _InterlockedAnd16(short volatile *_Value, short _Mask) {
673*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST);
674*344a7f5eSAndroid Build Coastguard Worker }
675*344a7f5eSAndroid Build Coastguard Worker static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedAnd(long volatile * _Value,long _Mask)676*344a7f5eSAndroid Build Coastguard Worker _InterlockedAnd(long volatile *_Value, long _Mask) {
677*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST);
678*344a7f5eSAndroid Build Coastguard Worker }
679*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
680*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedAnd64(__int64 volatile * _Value,__int64 _Mask)681*344a7f5eSAndroid Build Coastguard Worker _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) {
682*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST);
683*344a7f5eSAndroid Build Coastguard Worker }
684*344a7f5eSAndroid Build Coastguard Worker #endif
685*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
686*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Or
687*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
688*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedOr8(char volatile * _Value,char _Mask)689*344a7f5eSAndroid Build Coastguard Worker _InterlockedOr8(char volatile *_Value, char _Mask) {
690*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST);
691*344a7f5eSAndroid Build Coastguard Worker }
692*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedOr16(short volatile * _Value,short _Mask)693*344a7f5eSAndroid Build Coastguard Worker _InterlockedOr16(short volatile *_Value, short _Mask) {
694*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST);
695*344a7f5eSAndroid Build Coastguard Worker }
696*344a7f5eSAndroid Build Coastguard Worker static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedOr(long volatile * _Value,long _Mask)697*344a7f5eSAndroid Build Coastguard Worker _InterlockedOr(long volatile *_Value, long _Mask) {
698*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST);
699*344a7f5eSAndroid Build Coastguard Worker }
700*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
701*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedOr64(__int64 volatile * _Value,__int64 _Mask)702*344a7f5eSAndroid Build Coastguard Worker _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) {
703*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST);
704*344a7f5eSAndroid Build Coastguard Worker }
705*344a7f5eSAndroid Build Coastguard Worker #endif
706*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
707*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Xor
708*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
709*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedXor8(char volatile * _Value,char _Mask)710*344a7f5eSAndroid Build Coastguard Worker _InterlockedXor8(char volatile *_Value, char _Mask) {
711*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST);
712*344a7f5eSAndroid Build Coastguard Worker }
713*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedXor16(short volatile * _Value,short _Mask)714*344a7f5eSAndroid Build Coastguard Worker _InterlockedXor16(short volatile *_Value, short _Mask) {
715*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST);
716*344a7f5eSAndroid Build Coastguard Worker }
717*344a7f5eSAndroid Build Coastguard Worker static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedXor(long volatile * _Value,long _Mask)718*344a7f5eSAndroid Build Coastguard Worker _InterlockedXor(long volatile *_Value, long _Mask) {
719*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST);
720*344a7f5eSAndroid Build Coastguard Worker }
721*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
722*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedXor64(__int64 volatile * _Value,__int64 _Mask)723*344a7f5eSAndroid Build Coastguard Worker _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) {
724*344a7f5eSAndroid Build Coastguard Worker return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST);
725*344a7f5eSAndroid Build Coastguard Worker }
726*344a7f5eSAndroid Build Coastguard Worker #endif
727*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
728*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Exchange
729*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
730*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchange8(char volatile * _Target,char _Value)731*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchange8(char volatile *_Target, char _Value) {
732*344a7f5eSAndroid Build Coastguard Worker __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
733*344a7f5eSAndroid Build Coastguard Worker return _Value;
734*344a7f5eSAndroid Build Coastguard Worker }
735*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchange16(short volatile * _Target,short _Value)736*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchange16(short volatile *_Target, short _Value) {
737*344a7f5eSAndroid Build Coastguard Worker __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
738*344a7f5eSAndroid Build Coastguard Worker return _Value;
739*344a7f5eSAndroid Build Coastguard Worker }
740*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
741*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchange64(__int64 volatile * _Target,__int64 _Value)742*344a7f5eSAndroid Build Coastguard Worker _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) {
743*344a7f5eSAndroid Build Coastguard Worker __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
744*344a7f5eSAndroid Build Coastguard Worker return _Value;
745*344a7f5eSAndroid Build Coastguard Worker }
746*344a7f5eSAndroid Build Coastguard Worker #endif
747*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
748*344a7f5eSAndroid Build Coastguard Worker |* Interlocked Compare Exchange
749*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
750*344a7f5eSAndroid Build Coastguard Worker static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedCompareExchange8(char volatile * _Destination,char _Exchange,char _Comparand)751*344a7f5eSAndroid Build Coastguard Worker _InterlockedCompareExchange8(char volatile *_Destination,
752*344a7f5eSAndroid Build Coastguard Worker char _Exchange, char _Comparand) {
753*344a7f5eSAndroid Build Coastguard Worker __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
754*344a7f5eSAndroid Build Coastguard Worker __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
755*344a7f5eSAndroid Build Coastguard Worker return _Comparand;
756*344a7f5eSAndroid Build Coastguard Worker }
757*344a7f5eSAndroid Build Coastguard Worker static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedCompareExchange16(short volatile * _Destination,short _Exchange,short _Comparand)758*344a7f5eSAndroid Build Coastguard Worker _InterlockedCompareExchange16(short volatile *_Destination,
759*344a7f5eSAndroid Build Coastguard Worker short _Exchange, short _Comparand) {
760*344a7f5eSAndroid Build Coastguard Worker __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
761*344a7f5eSAndroid Build Coastguard Worker __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
762*344a7f5eSAndroid Build Coastguard Worker return _Comparand;
763*344a7f5eSAndroid Build Coastguard Worker }
764*344a7f5eSAndroid Build Coastguard Worker static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedCompareExchange64(__int64 volatile * _Destination,__int64 _Exchange,__int64 _Comparand)765*344a7f5eSAndroid Build Coastguard Worker _InterlockedCompareExchange64(__int64 volatile *_Destination,
766*344a7f5eSAndroid Build Coastguard Worker __int64 _Exchange, __int64 _Comparand) {
767*344a7f5eSAndroid Build Coastguard Worker __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
768*344a7f5eSAndroid Build Coastguard Worker __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
769*344a7f5eSAndroid Build Coastguard Worker return _Comparand;
770*344a7f5eSAndroid Build Coastguard Worker }
771*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
772*344a7f5eSAndroid Build Coastguard Worker |* Barriers
773*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
774*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
775*344a7f5eSAndroid Build Coastguard Worker __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_ReadWriteBarrier(void)776*344a7f5eSAndroid Build Coastguard Worker _ReadWriteBarrier(void) {
777*344a7f5eSAndroid Build Coastguard Worker __atomic_signal_fence(__ATOMIC_SEQ_CST);
778*344a7f5eSAndroid Build Coastguard Worker }
779*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
780*344a7f5eSAndroid Build Coastguard Worker __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_ReadBarrier(void)781*344a7f5eSAndroid Build Coastguard Worker _ReadBarrier(void) {
782*344a7f5eSAndroid Build Coastguard Worker __atomic_signal_fence(__ATOMIC_SEQ_CST);
783*344a7f5eSAndroid Build Coastguard Worker }
784*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
785*344a7f5eSAndroid Build Coastguard Worker __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_WriteBarrier(void)786*344a7f5eSAndroid Build Coastguard Worker _WriteBarrier(void) {
787*344a7f5eSAndroid Build Coastguard Worker __atomic_signal_fence(__ATOMIC_SEQ_CST);
788*344a7f5eSAndroid Build Coastguard Worker }
789*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
790*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__faststorefence(void)791*344a7f5eSAndroid Build Coastguard Worker __faststorefence(void) {
792*344a7f5eSAndroid Build Coastguard Worker __atomic_thread_fence(__ATOMIC_SEQ_CST);
793*344a7f5eSAndroid Build Coastguard Worker }
794*344a7f5eSAndroid Build Coastguard Worker #endif
795*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
796*344a7f5eSAndroid Build Coastguard Worker |* readfs, readgs
797*344a7f5eSAndroid Build Coastguard Worker |* (Pointers in address space #256 and #257 are relative to the GS and FS
798*344a7f5eSAndroid Build Coastguard Worker |* segment registers, respectively.)
799*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
800*344a7f5eSAndroid Build Coastguard Worker #define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \
801*344a7f5eSAndroid Build Coastguard Worker ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \
802*344a7f5eSAndroid Build Coastguard Worker (__offset))
803*344a7f5eSAndroid Build Coastguard Worker
804*344a7f5eSAndroid Build Coastguard Worker #ifdef __i386__
805*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
__readfsbyte(unsigned long __offset)806*344a7f5eSAndroid Build Coastguard Worker __readfsbyte(unsigned long __offset) {
807*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(257, unsigned char, __offset);
808*344a7f5eSAndroid Build Coastguard Worker }
809*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned short __DEFAULT_FN_ATTRS
__readfsword(unsigned long __offset)810*344a7f5eSAndroid Build Coastguard Worker __readfsword(unsigned long __offset) {
811*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(257, unsigned short, __offset);
812*344a7f5eSAndroid Build Coastguard Worker }
813*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__readfsqword(unsigned long __offset)814*344a7f5eSAndroid Build Coastguard Worker __readfsqword(unsigned long __offset) {
815*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(257, unsigned __int64, __offset);
816*344a7f5eSAndroid Build Coastguard Worker }
817*344a7f5eSAndroid Build Coastguard Worker #endif
818*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
819*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
__readgsbyte(unsigned long __offset)820*344a7f5eSAndroid Build Coastguard Worker __readgsbyte(unsigned long __offset) {
821*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(256, unsigned char, __offset);
822*344a7f5eSAndroid Build Coastguard Worker }
823*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned short __DEFAULT_FN_ATTRS
__readgsword(unsigned long __offset)824*344a7f5eSAndroid Build Coastguard Worker __readgsword(unsigned long __offset) {
825*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(256, unsigned short, __offset);
826*344a7f5eSAndroid Build Coastguard Worker }
827*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned long __DEFAULT_FN_ATTRS
__readgsdword(unsigned long __offset)828*344a7f5eSAndroid Build Coastguard Worker __readgsdword(unsigned long __offset) {
829*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(256, unsigned long, __offset);
830*344a7f5eSAndroid Build Coastguard Worker }
831*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__readgsqword(unsigned long __offset)832*344a7f5eSAndroid Build Coastguard Worker __readgsqword(unsigned long __offset) {
833*344a7f5eSAndroid Build Coastguard Worker return *__ptr_to_addr_space(256, unsigned __int64, __offset);
834*344a7f5eSAndroid Build Coastguard Worker }
835*344a7f5eSAndroid Build Coastguard Worker #endif
836*344a7f5eSAndroid Build Coastguard Worker #undef __ptr_to_addr_space
837*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
838*344a7f5eSAndroid Build Coastguard Worker |* movs, stos
839*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
840*344a7f5eSAndroid Build Coastguard Worker #if defined(__i386__) || defined(__x86_64__)
841*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__movsb(unsigned char * __dst,unsigned char const * __src,size_t __n)842*344a7f5eSAndroid Build Coastguard Worker __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
843*344a7f5eSAndroid Build Coastguard Worker __asm__("rep movsb" : : "D"(__dst), "S"(__src), "c"(__n)
844*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%esi", "%ecx");
845*344a7f5eSAndroid Build Coastguard Worker }
846*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__movsd(unsigned long * __dst,unsigned long const * __src,size_t __n)847*344a7f5eSAndroid Build Coastguard Worker __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
848*344a7f5eSAndroid Build Coastguard Worker __asm__("rep movsl" : : "D"(__dst), "S"(__src), "c"(__n)
849*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%esi", "%ecx");
850*344a7f5eSAndroid Build Coastguard Worker }
851*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__movsw(unsigned short * __dst,unsigned short const * __src,size_t __n)852*344a7f5eSAndroid Build Coastguard Worker __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
853*344a7f5eSAndroid Build Coastguard Worker __asm__("rep movsw" : : "D"(__dst), "S"(__src), "c"(__n)
854*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%esi", "%ecx");
855*344a7f5eSAndroid Build Coastguard Worker }
856*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__stosb(unsigned char * __dst,unsigned char __x,size_t __n)857*344a7f5eSAndroid Build Coastguard Worker __stosb(unsigned char *__dst, unsigned char __x, size_t __n) {
858*344a7f5eSAndroid Build Coastguard Worker __asm__("rep stosb" : : "D"(__dst), "a"(__x), "c"(__n)
859*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%ecx");
860*344a7f5eSAndroid Build Coastguard Worker }
861*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__stosd(unsigned long * __dst,unsigned long __x,size_t __n)862*344a7f5eSAndroid Build Coastguard Worker __stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
863*344a7f5eSAndroid Build Coastguard Worker __asm__("rep stosl" : : "D"(__dst), "a"(__x), "c"(__n)
864*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%ecx");
865*344a7f5eSAndroid Build Coastguard Worker }
866*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__stosw(unsigned short * __dst,unsigned short __x,size_t __n)867*344a7f5eSAndroid Build Coastguard Worker __stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
868*344a7f5eSAndroid Build Coastguard Worker __asm__("rep stosw" : : "D"(__dst), "a"(__x), "c"(__n)
869*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%ecx");
870*344a7f5eSAndroid Build Coastguard Worker }
871*344a7f5eSAndroid Build Coastguard Worker #endif
872*344a7f5eSAndroid Build Coastguard Worker #ifdef __x86_64__
873*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__movsq(unsigned long long * __dst,unsigned long long const * __src,size_t __n)874*344a7f5eSAndroid Build Coastguard Worker __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
875*344a7f5eSAndroid Build Coastguard Worker __asm__("rep movsq" : : "D"(__dst), "S"(__src), "c"(__n)
876*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%esi", "%ecx");
877*344a7f5eSAndroid Build Coastguard Worker }
878*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__stosq(unsigned __int64 * __dst,unsigned __int64 __x,size_t __n)879*344a7f5eSAndroid Build Coastguard Worker __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
880*344a7f5eSAndroid Build Coastguard Worker __asm__("rep stosq" : : "D"(__dst), "a"(__x), "c"(__n)
881*344a7f5eSAndroid Build Coastguard Worker : "%edi", "%ecx");
882*344a7f5eSAndroid Build Coastguard Worker }
883*344a7f5eSAndroid Build Coastguard Worker #endif
884*344a7f5eSAndroid Build Coastguard Worker
885*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
886*344a7f5eSAndroid Build Coastguard Worker |* Misc
887*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
888*344a7f5eSAndroid Build Coastguard Worker static __inline__ void * __DEFAULT_FN_ATTRS
_AddressOfReturnAddress(void)889*344a7f5eSAndroid Build Coastguard Worker _AddressOfReturnAddress(void) {
890*344a7f5eSAndroid Build Coastguard Worker return (void*)((char*)__builtin_frame_address(0) + sizeof(void*));
891*344a7f5eSAndroid Build Coastguard Worker }
892*344a7f5eSAndroid Build Coastguard Worker static __inline__ void * __DEFAULT_FN_ATTRS
_ReturnAddress(void)893*344a7f5eSAndroid Build Coastguard Worker _ReturnAddress(void) {
894*344a7f5eSAndroid Build Coastguard Worker return __builtin_return_address(0);
895*344a7f5eSAndroid Build Coastguard Worker }
896*344a7f5eSAndroid Build Coastguard Worker #if defined(__i386__) || defined(__x86_64__)
897*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__cpuid(int __info[4],int __level)898*344a7f5eSAndroid Build Coastguard Worker __cpuid(int __info[4], int __level) {
899*344a7f5eSAndroid Build Coastguard Worker __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
900*344a7f5eSAndroid Build Coastguard Worker : "a"(__level));
901*344a7f5eSAndroid Build Coastguard Worker }
902*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__cpuidex(int __info[4],int __level,int __ecx)903*344a7f5eSAndroid Build Coastguard Worker __cpuidex(int __info[4], int __level, int __ecx) {
904*344a7f5eSAndroid Build Coastguard Worker __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
905*344a7f5eSAndroid Build Coastguard Worker : "a"(__level), "c"(__ecx));
906*344a7f5eSAndroid Build Coastguard Worker }
907*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS
_xgetbv(unsigned int __xcr_no)908*344a7f5eSAndroid Build Coastguard Worker _xgetbv(unsigned int __xcr_no) {
909*344a7f5eSAndroid Build Coastguard Worker unsigned int __eax, __edx;
910*344a7f5eSAndroid Build Coastguard Worker __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
911*344a7f5eSAndroid Build Coastguard Worker return ((unsigned __int64)__edx << 32) | __eax;
912*344a7f5eSAndroid Build Coastguard Worker }
913*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__halt(void)914*344a7f5eSAndroid Build Coastguard Worker __halt(void) {
915*344a7f5eSAndroid Build Coastguard Worker __asm__ volatile ("hlt");
916*344a7f5eSAndroid Build Coastguard Worker }
917*344a7f5eSAndroid Build Coastguard Worker #endif
918*344a7f5eSAndroid Build Coastguard Worker
919*344a7f5eSAndroid Build Coastguard Worker /*----------------------------------------------------------------------------*\
920*344a7f5eSAndroid Build Coastguard Worker |* Privileged intrinsics
921*344a7f5eSAndroid Build Coastguard Worker \*----------------------------------------------------------------------------*/
922*344a7f5eSAndroid Build Coastguard Worker #if defined(__i386__) || defined(__x86_64__)
923*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__readmsr(unsigned long __register)924*344a7f5eSAndroid Build Coastguard Worker __readmsr(unsigned long __register) {
925*344a7f5eSAndroid Build Coastguard Worker // Loads the contents of a 64-bit model specific register (MSR) specified in
926*344a7f5eSAndroid Build Coastguard Worker // the ECX register into registers EDX:EAX. The EDX register is loaded with
927*344a7f5eSAndroid Build Coastguard Worker // the high-order 32 bits of the MSR and the EAX register is loaded with the
928*344a7f5eSAndroid Build Coastguard Worker // low-order 32 bits. If less than 64 bits are implemented in the MSR being
929*344a7f5eSAndroid Build Coastguard Worker // read, the values returned to EDX:EAX in unimplemented bit locations are
930*344a7f5eSAndroid Build Coastguard Worker // undefined.
931*344a7f5eSAndroid Build Coastguard Worker unsigned long __edx;
932*344a7f5eSAndroid Build Coastguard Worker unsigned long __eax;
933*344a7f5eSAndroid Build Coastguard Worker __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
934*344a7f5eSAndroid Build Coastguard Worker return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
935*344a7f5eSAndroid Build Coastguard Worker }
936*344a7f5eSAndroid Build Coastguard Worker
937*344a7f5eSAndroid Build Coastguard Worker static __inline__ unsigned long __DEFAULT_FN_ATTRS
__readcr3(void)938*344a7f5eSAndroid Build Coastguard Worker __readcr3(void) {
939*344a7f5eSAndroid Build Coastguard Worker unsigned long __cr3_val;
940*344a7f5eSAndroid Build Coastguard Worker __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory");
941*344a7f5eSAndroid Build Coastguard Worker return __cr3_val;
942*344a7f5eSAndroid Build Coastguard Worker }
943*344a7f5eSAndroid Build Coastguard Worker
944*344a7f5eSAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
__writecr3(unsigned int __cr3_val)945*344a7f5eSAndroid Build Coastguard Worker __writecr3(unsigned int __cr3_val) {
946*344a7f5eSAndroid Build Coastguard Worker __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory");
947*344a7f5eSAndroid Build Coastguard Worker }
948*344a7f5eSAndroid Build Coastguard Worker #endif
949*344a7f5eSAndroid Build Coastguard Worker
950*344a7f5eSAndroid Build Coastguard Worker #ifdef __cplusplus
951*344a7f5eSAndroid Build Coastguard Worker }
952*344a7f5eSAndroid Build Coastguard Worker #endif
953*344a7f5eSAndroid Build Coastguard Worker
954*344a7f5eSAndroid Build Coastguard Worker #undef __DEFAULT_FN_ATTRS
955*344a7f5eSAndroid Build Coastguard Worker
956*344a7f5eSAndroid Build Coastguard Worker #endif /* __INTRIN_H */
957*344a7f5eSAndroid Build Coastguard Worker #endif /* _MSC_VER */
958