xref: /freebsd/contrib/llvm-project/clang/lib/Headers/intrin.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric /* ===-------- intrin.h ---------------------------------------------------===
20b57cec5SDimitry Andric  *
30b57cec5SDimitry Andric  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric  * See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric  *
70b57cec5SDimitry Andric  *===-----------------------------------------------------------------------===
80b57cec5SDimitry Andric  */
90b57cec5SDimitry Andric 
100b57cec5SDimitry Andric /* Only include this if we're compiling for the windows platform. */
110b57cec5SDimitry Andric #ifndef _MSC_VER
120b57cec5SDimitry Andric #include_next <intrin.h>
130b57cec5SDimitry Andric #else
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifndef __INTRIN_H
160b57cec5SDimitry Andric #define __INTRIN_H
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric /* First include the standard intrinsics. */
190b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
200b57cec5SDimitry Andric #include <x86intrin.h>
210b57cec5SDimitry Andric #endif
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric #if defined(__arm__)
240b57cec5SDimitry Andric #include <armintr.h>
250b57cec5SDimitry Andric #endif
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric #if defined(__aarch64__)
280b57cec5SDimitry Andric #include <arm64intr.h>
290b57cec5SDimitry Andric #endif
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric /* For the definition of jmp_buf. */
320b57cec5SDimitry Andric #if __STDC_HOSTED__
330b57cec5SDimitry Andric #include <setjmp.h>
340b57cec5SDimitry Andric #endif
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric /* Define the default attributes for the functions in this file. */
370b57cec5SDimitry Andric #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
380b57cec5SDimitry Andric 
39480093f4SDimitry Andric #if __x86_64__
40480093f4SDimitry Andric #define __LPTRINT_TYPE__ __int64
41480093f4SDimitry Andric #else
42480093f4SDimitry Andric #define __LPTRINT_TYPE__ long
43480093f4SDimitry Andric #endif
44480093f4SDimitry Andric 
450b57cec5SDimitry Andric #ifdef __cplusplus
460b57cec5SDimitry Andric extern "C" {
470b57cec5SDimitry Andric #endif
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric #if defined(__MMX__)
500b57cec5SDimitry Andric /* And the random ones that aren't in those files. */
510b57cec5SDimitry Andric __m64 _m_from_float(float);
520b57cec5SDimitry Andric float _m_to_float(__m64);
530b57cec5SDimitry Andric #endif
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric /* Other assorted instruction intrinsics. */
560b57cec5SDimitry Andric void __addfsbyte(unsigned long, unsigned char);
570b57cec5SDimitry Andric void __addfsdword(unsigned long, unsigned long);
580b57cec5SDimitry Andric void __addfsword(unsigned long, unsigned short);
590b57cec5SDimitry Andric void __code_seg(const char *);
600b57cec5SDimitry Andric void __cpuid(int[4], int);
610b57cec5SDimitry Andric void __cpuidex(int[4], int, int);
620b57cec5SDimitry Andric __int64 __emul(int, int);
630b57cec5SDimitry Andric unsigned __int64 __emulu(unsigned int, unsigned int);
640b57cec5SDimitry Andric unsigned int __getcallerseflags(void);
650b57cec5SDimitry Andric void __halt(void);
660b57cec5SDimitry Andric unsigned char __inbyte(unsigned short);
670b57cec5SDimitry Andric void __inbytestring(unsigned short, unsigned char *, unsigned long);
680b57cec5SDimitry Andric void __incfsbyte(unsigned long);
690b57cec5SDimitry Andric void __incfsdword(unsigned long);
700b57cec5SDimitry Andric void __incfsword(unsigned long);
710b57cec5SDimitry Andric unsigned long __indword(unsigned short);
720b57cec5SDimitry Andric void __indwordstring(unsigned short, unsigned long *, unsigned long);
730b57cec5SDimitry Andric void __int2c(void);
740b57cec5SDimitry Andric void __invlpg(void *);
750b57cec5SDimitry Andric unsigned short __inword(unsigned short);
760b57cec5SDimitry Andric void __inwordstring(unsigned short, unsigned short *, unsigned long);
770b57cec5SDimitry Andric void __lidt(void *);
780b57cec5SDimitry Andric unsigned __int64 __ll_lshift(unsigned __int64, int);
790b57cec5SDimitry Andric __int64 __ll_rshift(__int64, int);
800b57cec5SDimitry Andric void __movsb(unsigned char *, unsigned char const *, size_t);
810b57cec5SDimitry Andric void __movsd(unsigned long *, unsigned long const *, size_t);
820b57cec5SDimitry Andric void __movsw(unsigned short *, unsigned short const *, size_t);
830b57cec5SDimitry Andric void __nop(void);
840b57cec5SDimitry Andric void __nvreg_restore_fence(void);
850b57cec5SDimitry Andric void __nvreg_save_fence(void);
860b57cec5SDimitry Andric void __outbyte(unsigned short, unsigned char);
870b57cec5SDimitry Andric void __outbytestring(unsigned short, unsigned char *, unsigned long);
880b57cec5SDimitry Andric void __outdword(unsigned short, unsigned long);
890b57cec5SDimitry Andric void __outdwordstring(unsigned short, unsigned long *, unsigned long);
900b57cec5SDimitry Andric void __outword(unsigned short, unsigned short);
910b57cec5SDimitry Andric void __outwordstring(unsigned short, unsigned short *, unsigned long);
920b57cec5SDimitry Andric unsigned long __readcr0(void);
930b57cec5SDimitry Andric unsigned long __readcr2(void);
94480093f4SDimitry Andric unsigned __LPTRINT_TYPE__ __readcr3(void);
950b57cec5SDimitry Andric unsigned long __readcr4(void);
960b57cec5SDimitry Andric unsigned long __readcr8(void);
970b57cec5SDimitry Andric unsigned int __readdr(unsigned int);
980b57cec5SDimitry Andric #ifdef __i386__
990b57cec5SDimitry Andric unsigned char __readfsbyte(unsigned long);
1000b57cec5SDimitry Andric unsigned __int64 __readfsqword(unsigned long);
1010b57cec5SDimitry Andric unsigned short __readfsword(unsigned long);
1020b57cec5SDimitry Andric #endif
1030b57cec5SDimitry Andric unsigned __int64 __readmsr(unsigned long);
1040b57cec5SDimitry Andric unsigned __int64 __readpmc(unsigned long);
1050b57cec5SDimitry Andric unsigned long __segmentlimit(unsigned long);
1060b57cec5SDimitry Andric void __sidt(void *);
1070b57cec5SDimitry Andric void __stosb(unsigned char *, unsigned char, size_t);
1080b57cec5SDimitry Andric void __stosd(unsigned long *, unsigned long, size_t);
1090b57cec5SDimitry Andric void __stosw(unsigned short *, unsigned short, size_t);
1100b57cec5SDimitry Andric void __svm_clgi(void);
1110b57cec5SDimitry Andric void __svm_invlpga(void *, int);
1120b57cec5SDimitry Andric void __svm_skinit(int);
1130b57cec5SDimitry Andric void __svm_stgi(void);
1140b57cec5SDimitry Andric void __svm_vmload(size_t);
1150b57cec5SDimitry Andric void __svm_vmrun(size_t);
1160b57cec5SDimitry Andric void __svm_vmsave(size_t);
1170b57cec5SDimitry Andric void __ud2(void);
1180b57cec5SDimitry Andric unsigned __int64 __ull_rshift(unsigned __int64, int);
1190b57cec5SDimitry Andric void __vmx_off(void);
1200b57cec5SDimitry Andric void __vmx_vmptrst(unsigned __int64 *);
1210b57cec5SDimitry Andric void __wbinvd(void);
1220b57cec5SDimitry Andric void __writecr0(unsigned int);
123480093f4SDimitry Andric void __writecr3(unsigned __INTPTR_TYPE__);
1240b57cec5SDimitry Andric void __writecr4(unsigned int);
1250b57cec5SDimitry Andric void __writecr8(unsigned int);
1260b57cec5SDimitry Andric void __writedr(unsigned int, unsigned int);
1270b57cec5SDimitry Andric void __writefsbyte(unsigned long, unsigned char);
1280b57cec5SDimitry Andric void __writefsdword(unsigned long, unsigned long);
1290b57cec5SDimitry Andric void __writefsqword(unsigned long, unsigned __int64);
1300b57cec5SDimitry Andric void __writefsword(unsigned long, unsigned short);
1310b57cec5SDimitry Andric void __writemsr(unsigned long, unsigned __int64);
1320b57cec5SDimitry Andric void *_AddressOfReturnAddress(void);
1330b57cec5SDimitry Andric unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
1340b57cec5SDimitry Andric unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
1350b57cec5SDimitry Andric unsigned char _bittest(long const *, long);
1360b57cec5SDimitry Andric unsigned char _bittestandcomplement(long *, long);
1370b57cec5SDimitry Andric unsigned char _bittestandreset(long *, long);
1380b57cec5SDimitry Andric unsigned char _bittestandset(long *, long);
1390b57cec5SDimitry Andric void __cdecl _disable(void);
1400b57cec5SDimitry Andric void __cdecl _enable(void);
1410b57cec5SDimitry Andric long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
1420b57cec5SDimitry Andric unsigned char _interlockedbittestandreset(long volatile *, long);
1430b57cec5SDimitry Andric unsigned char _interlockedbittestandset(long volatile *, long);
1440b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
1450b57cec5SDimitry Andric                                                     void *);
1460b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
1470b57cec5SDimitry Andric                                                     void *);
1480b57cec5SDimitry Andric long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
1490b57cec5SDimitry Andric long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
1500b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
1510b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
152927c847dSDimitry Andric void __attribute__((__deprecated__(
153927c847dSDimitry Andric     "use other intrinsics or C++11 atomics instead"))) _ReadBarrier(void);
154927c847dSDimitry Andric void __attribute__((__deprecated__(
155927c847dSDimitry Andric     "use other intrinsics or C++11 atomics instead"))) _ReadWriteBarrier(void);
1560b57cec5SDimitry Andric unsigned int _rorx_u32(unsigned int, const unsigned int);
1570b57cec5SDimitry Andric int _sarx_i32(int, unsigned int);
1580b57cec5SDimitry Andric #if __STDC_HOSTED__
1590b57cec5SDimitry Andric int __cdecl _setjmp(jmp_buf);
1600b57cec5SDimitry Andric #endif
1610b57cec5SDimitry Andric unsigned int _shlx_u32(unsigned int, unsigned int);
1620b57cec5SDimitry Andric unsigned int _shrx_u32(unsigned int, unsigned int);
1630b57cec5SDimitry Andric void _Store_HLERelease(long volatile *, long);
1640b57cec5SDimitry Andric void _Store64_HLERelease(__int64 volatile *, __int64);
1650b57cec5SDimitry Andric void _StorePointer_HLERelease(void *volatile *, void *);
166927c847dSDimitry Andric void __attribute__((__deprecated__(
167927c847dSDimitry Andric     "use other intrinsics or C++11 atomics instead"))) _WriteBarrier(void);
1680b57cec5SDimitry Andric unsigned __int32 xbegin(void);
1690b57cec5SDimitry Andric void _xend(void);
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
1720b57cec5SDimitry Andric #ifdef __x86_64__
1730b57cec5SDimitry Andric void __addgsbyte(unsigned long, unsigned char);
1740b57cec5SDimitry Andric void __addgsdword(unsigned long, unsigned long);
1750b57cec5SDimitry Andric void __addgsqword(unsigned long, unsigned __int64);
1760b57cec5SDimitry Andric void __addgsword(unsigned long, unsigned short);
1770b57cec5SDimitry Andric void __faststorefence(void);
1780b57cec5SDimitry Andric void __incgsbyte(unsigned long);
1790b57cec5SDimitry Andric void __incgsdword(unsigned long);
1800b57cec5SDimitry Andric void __incgsqword(unsigned long);
1810b57cec5SDimitry Andric void __incgsword(unsigned long);
1820b57cec5SDimitry Andric void __movsq(unsigned long long *, unsigned long long const *, size_t);
1830b57cec5SDimitry Andric unsigned char __readgsbyte(unsigned long);
1840b57cec5SDimitry Andric unsigned long __readgsdword(unsigned long);
1850b57cec5SDimitry Andric unsigned __int64 __readgsqword(unsigned long);
1860b57cec5SDimitry Andric unsigned short __readgsword(unsigned long);
1870b57cec5SDimitry Andric unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
1880b57cec5SDimitry Andric                                 unsigned __int64 _HighPart,
1890b57cec5SDimitry Andric                                 unsigned char _Shift);
1900b57cec5SDimitry Andric unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
1910b57cec5SDimitry Andric                                  unsigned __int64 _HighPart,
1920b57cec5SDimitry Andric                                  unsigned char _Shift);
1930b57cec5SDimitry Andric void __stosq(unsigned __int64 *, unsigned __int64, size_t);
1940b57cec5SDimitry Andric unsigned char __vmx_on(unsigned __int64 *);
1950b57cec5SDimitry Andric unsigned char __vmx_vmclear(unsigned __int64 *);
1960b57cec5SDimitry Andric unsigned char __vmx_vmlaunch(void);
1970b57cec5SDimitry Andric unsigned char __vmx_vmptrld(unsigned __int64 *);
1980b57cec5SDimitry Andric unsigned char __vmx_vmread(size_t, size_t *);
1990b57cec5SDimitry Andric unsigned char __vmx_vmresume(void);
2000b57cec5SDimitry Andric unsigned char __vmx_vmwrite(size_t, size_t);
2010b57cec5SDimitry Andric void __writegsbyte(unsigned long, unsigned char);
2020b57cec5SDimitry Andric void __writegsdword(unsigned long, unsigned long);
2030b57cec5SDimitry Andric void __writegsqword(unsigned long, unsigned __int64);
2040b57cec5SDimitry Andric void __writegsword(unsigned long, unsigned short);
2050b57cec5SDimitry Andric unsigned char _bittest64(__int64 const *, __int64);
2060b57cec5SDimitry Andric unsigned char _bittestandcomplement64(__int64 *, __int64);
2070b57cec5SDimitry Andric unsigned char _bittestandreset64(__int64 *, __int64);
2080b57cec5SDimitry Andric unsigned char _bittestandset64(__int64 *, __int64);
2090b57cec5SDimitry Andric long _InterlockedAnd_np(long volatile *_Value, long _Mask);
2100b57cec5SDimitry Andric short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
2110b57cec5SDimitry Andric __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
2120b57cec5SDimitry Andric char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
2130b57cec5SDimitry Andric unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
2140b57cec5SDimitry Andric unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
2150b57cec5SDimitry Andric long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
2160b57cec5SDimitry Andric                                     long _Comparand);
2170b57cec5SDimitry Andric unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
2180b57cec5SDimitry Andric                                                 __int64 _ExchangeHigh,
2190b57cec5SDimitry Andric                                                 __int64 _ExchangeLow,
2200b57cec5SDimitry Andric                                                 __int64 *_ComparandResult);
2210b57cec5SDimitry Andric short _InterlockedCompareExchange16_np(short volatile *_Destination,
2220b57cec5SDimitry Andric                                        short _Exchange, short _Comparand);
2230b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
2240b57cec5SDimitry Andric                                          __int64 _Exchange, __int64 _Comparand);
2250b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
2260b57cec5SDimitry Andric                                             void *_Exchange, void *_Comparand);
2270b57cec5SDimitry Andric long _InterlockedOr_np(long volatile *_Value, long _Mask);
2280b57cec5SDimitry Andric short _InterlockedOr16_np(short volatile *_Value, short _Mask);
2290b57cec5SDimitry Andric __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
2300b57cec5SDimitry Andric char _InterlockedOr8_np(char volatile *_Value, char _Mask);
2310b57cec5SDimitry Andric long _InterlockedXor_np(long volatile *_Value, long _Mask);
2320b57cec5SDimitry Andric short _InterlockedXor16_np(short volatile *_Value, short _Mask);
2330b57cec5SDimitry Andric __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
2340b57cec5SDimitry Andric char _InterlockedXor8_np(char volatile *_Value, char _Mask);
2350b57cec5SDimitry Andric unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
2360b57cec5SDimitry Andric __int64 _sarx_i64(__int64, unsigned int);
2370b57cec5SDimitry Andric unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
2380b57cec5SDimitry Andric unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
2390b57cec5SDimitry Andric __int64 __mulh(__int64, __int64);
2400b57cec5SDimitry Andric unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
2410b57cec5SDimitry Andric __int64 _mul128(__int64, __int64, __int64*);
2420b57cec5SDimitry Andric unsigned __int64 _umul128(unsigned __int64,
2430b57cec5SDimitry Andric                           unsigned __int64,
2440b57cec5SDimitry Andric                           unsigned __int64*);
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric #endif /* __x86_64__ */
2470b57cec5SDimitry Andric 
2480b57cec5SDimitry Andric #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2490b57cec5SDimitry Andric 
2500b57cec5SDimitry Andric unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
2510b57cec5SDimitry Andric unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
2520b57cec5SDimitry Andric 
2535ffd83dbSDimitry Andric #endif
2545ffd83dbSDimitry Andric 
2555ffd83dbSDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2560b57cec5SDimitry Andric __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
2570b57cec5SDimitry Andric __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
2580b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
2590b57cec5SDimitry Andric __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
2600b57cec5SDimitry Andric __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
2610b57cec5SDimitry Andric __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
2620b57cec5SDimitry Andric __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
2630b57cec5SDimitry Andric __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric #endif
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2680b57cec5SDimitry Andric |* Interlocked Exchange Add
2690b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2700b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2710b57cec5SDimitry Andric char _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value);
2720b57cec5SDimitry Andric char _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value);
2730b57cec5SDimitry Andric char _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value);
2740b57cec5SDimitry Andric short _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value);
2750b57cec5SDimitry Andric short _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value);
2760b57cec5SDimitry Andric short _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value);
2770b57cec5SDimitry Andric long _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value);
2780b57cec5SDimitry Andric long _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value);
2790b57cec5SDimitry Andric long _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value);
2800b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value);
2810b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value);
2820b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value);
2830b57cec5SDimitry Andric #endif
2840b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2850b57cec5SDimitry Andric |* Interlocked Increment
2860b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2870b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2880b57cec5SDimitry Andric short _InterlockedIncrement16_acq(short volatile *_Value);
2890b57cec5SDimitry Andric short _InterlockedIncrement16_nf(short volatile *_Value);
2900b57cec5SDimitry Andric short _InterlockedIncrement16_rel(short volatile *_Value);
2910b57cec5SDimitry Andric long _InterlockedIncrement_acq(long volatile *_Value);
2920b57cec5SDimitry Andric long _InterlockedIncrement_nf(long volatile *_Value);
2930b57cec5SDimitry Andric long _InterlockedIncrement_rel(long volatile *_Value);
2940b57cec5SDimitry Andric __int64 _InterlockedIncrement64_acq(__int64 volatile *_Value);
2950b57cec5SDimitry Andric __int64 _InterlockedIncrement64_nf(__int64 volatile *_Value);
2960b57cec5SDimitry Andric __int64 _InterlockedIncrement64_rel(__int64 volatile *_Value);
2970b57cec5SDimitry Andric #endif
2980b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2990b57cec5SDimitry Andric |* Interlocked Decrement
3000b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3010b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3020b57cec5SDimitry Andric short _InterlockedDecrement16_acq(short volatile *_Value);
3030b57cec5SDimitry Andric short _InterlockedDecrement16_nf(short volatile *_Value);
3040b57cec5SDimitry Andric short _InterlockedDecrement16_rel(short volatile *_Value);
3050b57cec5SDimitry Andric long _InterlockedDecrement_acq(long volatile *_Value);
3060b57cec5SDimitry Andric long _InterlockedDecrement_nf(long volatile *_Value);
3070b57cec5SDimitry Andric long _InterlockedDecrement_rel(long volatile *_Value);
3080b57cec5SDimitry Andric __int64 _InterlockedDecrement64_acq(__int64 volatile *_Value);
3090b57cec5SDimitry Andric __int64 _InterlockedDecrement64_nf(__int64 volatile *_Value);
3100b57cec5SDimitry Andric __int64 _InterlockedDecrement64_rel(__int64 volatile *_Value);
3110b57cec5SDimitry Andric #endif
3120b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3130b57cec5SDimitry Andric |* Interlocked And
3140b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3150b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3160b57cec5SDimitry Andric char _InterlockedAnd8_acq(char volatile *_Value, char _Mask);
3170b57cec5SDimitry Andric char _InterlockedAnd8_nf(char volatile *_Value, char _Mask);
3180b57cec5SDimitry Andric char _InterlockedAnd8_rel(char volatile *_Value, char _Mask);
3190b57cec5SDimitry Andric short _InterlockedAnd16_acq(short volatile *_Value, short _Mask);
3200b57cec5SDimitry Andric short _InterlockedAnd16_nf(short volatile *_Value, short _Mask);
3210b57cec5SDimitry Andric short _InterlockedAnd16_rel(short volatile *_Value, short _Mask);
3220b57cec5SDimitry Andric long _InterlockedAnd_acq(long volatile *_Value, long _Mask);
3230b57cec5SDimitry Andric long _InterlockedAnd_nf(long volatile *_Value, long _Mask);
3240b57cec5SDimitry Andric long _InterlockedAnd_rel(long volatile *_Value, long _Mask);
3250b57cec5SDimitry Andric __int64 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask);
3260b57cec5SDimitry Andric __int64 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask);
3270b57cec5SDimitry Andric __int64 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask);
3280b57cec5SDimitry Andric #endif
3290b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3300b57cec5SDimitry Andric |* Bit Counting and Testing
3310b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3320b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3330b57cec5SDimitry Andric unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
3340b57cec5SDimitry Andric                                             long _BitPos);
3350b57cec5SDimitry Andric unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
3360b57cec5SDimitry Andric                                            long _BitPos);
3370b57cec5SDimitry Andric unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
3380b57cec5SDimitry Andric                                             long _BitPos);
3390b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
3400b57cec5SDimitry Andric                                               long _BitPos);
3410b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
3420b57cec5SDimitry Andric                                              long _BitPos);
3430b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
3440b57cec5SDimitry Andric                                               long _BitPos);
3450b57cec5SDimitry Andric #endif
3460b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3470b57cec5SDimitry Andric |* Interlocked Or
3480b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3490b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3500b57cec5SDimitry Andric char _InterlockedOr8_acq(char volatile *_Value, char _Mask);
3510b57cec5SDimitry Andric char _InterlockedOr8_nf(char volatile *_Value, char _Mask);
3520b57cec5SDimitry Andric char _InterlockedOr8_rel(char volatile *_Value, char _Mask);
3530b57cec5SDimitry Andric short _InterlockedOr16_acq(short volatile *_Value, short _Mask);
3540b57cec5SDimitry Andric short _InterlockedOr16_nf(short volatile *_Value, short _Mask);
3550b57cec5SDimitry Andric short _InterlockedOr16_rel(short volatile *_Value, short _Mask);
3560b57cec5SDimitry Andric long _InterlockedOr_acq(long volatile *_Value, long _Mask);
3570b57cec5SDimitry Andric long _InterlockedOr_nf(long volatile *_Value, long _Mask);
3580b57cec5SDimitry Andric long _InterlockedOr_rel(long volatile *_Value, long _Mask);
3590b57cec5SDimitry Andric __int64 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask);
3600b57cec5SDimitry Andric __int64 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask);
3610b57cec5SDimitry Andric __int64 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask);
3620b57cec5SDimitry Andric #endif
3630b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3640b57cec5SDimitry Andric |* Interlocked Xor
3650b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3660b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3670b57cec5SDimitry Andric char _InterlockedXor8_acq(char volatile *_Value, char _Mask);
3680b57cec5SDimitry Andric char _InterlockedXor8_nf(char volatile *_Value, char _Mask);
3690b57cec5SDimitry Andric char _InterlockedXor8_rel(char volatile *_Value, char _Mask);
3700b57cec5SDimitry Andric short _InterlockedXor16_acq(short volatile *_Value, short _Mask);
3710b57cec5SDimitry Andric short _InterlockedXor16_nf(short volatile *_Value, short _Mask);
3720b57cec5SDimitry Andric short _InterlockedXor16_rel(short volatile *_Value, short _Mask);
3730b57cec5SDimitry Andric long _InterlockedXor_acq(long volatile *_Value, long _Mask);
3740b57cec5SDimitry Andric long _InterlockedXor_nf(long volatile *_Value, long _Mask);
3750b57cec5SDimitry Andric long _InterlockedXor_rel(long volatile *_Value, long _Mask);
3760b57cec5SDimitry Andric __int64 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask);
3770b57cec5SDimitry Andric __int64 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask);
3780b57cec5SDimitry Andric __int64 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask);
3790b57cec5SDimitry Andric #endif
3800b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3810b57cec5SDimitry Andric |* Interlocked Exchange
3820b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3830b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3840b57cec5SDimitry Andric char _InterlockedExchange8_acq(char volatile *_Target, char _Value);
3850b57cec5SDimitry Andric char _InterlockedExchange8_nf(char volatile *_Target, char _Value);
3860b57cec5SDimitry Andric char _InterlockedExchange8_rel(char volatile *_Target, char _Value);
3870b57cec5SDimitry Andric short _InterlockedExchange16_acq(short volatile *_Target, short _Value);
3880b57cec5SDimitry Andric short _InterlockedExchange16_nf(short volatile *_Target, short _Value);
3890b57cec5SDimitry Andric short _InterlockedExchange16_rel(short volatile *_Target, short _Value);
3900b57cec5SDimitry Andric long _InterlockedExchange_acq(long volatile *_Target, long _Value);
3910b57cec5SDimitry Andric long _InterlockedExchange_nf(long volatile *_Target, long _Value);
3920b57cec5SDimitry Andric long _InterlockedExchange_rel(long volatile *_Target, long _Value);
3930b57cec5SDimitry Andric __int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
3940b57cec5SDimitry Andric __int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
3950b57cec5SDimitry Andric __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
3960b57cec5SDimitry Andric #endif
3970b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3980b57cec5SDimitry Andric |* Interlocked Compare Exchange
3990b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4000b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
4010b57cec5SDimitry Andric char _InterlockedCompareExchange8_acq(char volatile *_Destination,
4020b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4030b57cec5SDimitry Andric char _InterlockedCompareExchange8_nf(char volatile *_Destination,
4040b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4050b57cec5SDimitry Andric char _InterlockedCompareExchange8_rel(char volatile *_Destination,
4060b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4070b57cec5SDimitry Andric short _InterlockedCompareExchange16_acq(short volatile *_Destination,
4080b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4090b57cec5SDimitry Andric short _InterlockedCompareExchange16_nf(short volatile *_Destination,
4100b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4110b57cec5SDimitry Andric short _InterlockedCompareExchange16_rel(short volatile *_Destination,
4120b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4130b57cec5SDimitry Andric long _InterlockedCompareExchange_acq(long volatile *_Destination,
4140b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4150b57cec5SDimitry Andric long _InterlockedCompareExchange_nf(long volatile *_Destination,
4160b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4170b57cec5SDimitry Andric long _InterlockedCompareExchange_rel(long volatile *_Destination,
4180b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4190b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
4200b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4210b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
4220b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4230b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
4240b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4250b57cec5SDimitry Andric #endif
426e8d8bef9SDimitry Andric #if defined(__x86_64__) || defined(__aarch64__)
427e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
428e8d8bef9SDimitry Andric                                              __int64 _ExchangeHigh,
429e8d8bef9SDimitry Andric                                              __int64 _ExchangeLow,
430e8d8bef9SDimitry Andric                                              __int64 *_ComparandResult);
431e8d8bef9SDimitry Andric #endif
432e8d8bef9SDimitry Andric #if defined(__aarch64__)
433e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_acq(__int64 volatile *_Destination,
434e8d8bef9SDimitry Andric                                                  __int64 _ExchangeHigh,
435e8d8bef9SDimitry Andric                                                  __int64 _ExchangeLow,
436e8d8bef9SDimitry Andric                                                  __int64 *_ComparandResult);
437e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_nf(__int64 volatile *_Destination,
438e8d8bef9SDimitry Andric                                                 __int64 _ExchangeHigh,
439e8d8bef9SDimitry Andric                                                 __int64 _ExchangeLow,
440e8d8bef9SDimitry Andric                                                 __int64 *_ComparandResult);
441e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_rel(__int64 volatile *_Destination,
442e8d8bef9SDimitry Andric                                                  __int64 _ExchangeHigh,
443e8d8bef9SDimitry Andric                                                  __int64 _ExchangeLow,
444e8d8bef9SDimitry Andric                                                  __int64 *_ComparandResult);
445e8d8bef9SDimitry Andric #endif
4460b57cec5SDimitry Andric 
4470b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
4480b57cec5SDimitry Andric |* movs, stos
4490b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4500b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
451927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
452927c847dSDimitry Andric                                                   unsigned char const *__src,
453927c847dSDimitry Andric                                                   size_t __n) {
454*fe6060f1SDimitry Andric #if defined(__x86_64__)
455*fe6060f1SDimitry Andric   __asm__ __volatile__("rep movsb"
456*fe6060f1SDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
457*fe6060f1SDimitry Andric                        :
458*fe6060f1SDimitry Andric                        : "memory");
459*fe6060f1SDimitry Andric #else
460*fe6060f1SDimitry Andric   __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1"
461*fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
462*fe6060f1SDimitry Andric                        :
463*fe6060f1SDimitry Andric                        : "memory");
464*fe6060f1SDimitry Andric #endif
4650b57cec5SDimitry Andric }
466927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
467927c847dSDimitry Andric                                                   unsigned long const *__src,
468927c847dSDimitry Andric                                                   size_t __n) {
469*fe6060f1SDimitry Andric #if defined(__x86_64__)
470927c847dSDimitry Andric   __asm__ __volatile__("rep movsl"
471927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
472927c847dSDimitry Andric                        :
4730b57cec5SDimitry Andric                        : "memory");
474*fe6060f1SDimitry Andric #else
475*fe6060f1SDimitry Andric   __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1"
476*fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
477*fe6060f1SDimitry Andric                        :
478*fe6060f1SDimitry Andric                        : "memory");
479*fe6060f1SDimitry Andric #endif
4800b57cec5SDimitry Andric }
481927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
482927c847dSDimitry Andric                                                   unsigned short const *__src,
483927c847dSDimitry Andric                                                   size_t __n) {
484*fe6060f1SDimitry Andric #if defined(__x86_64__)
485927c847dSDimitry Andric   __asm__ __volatile__("rep movsw"
486927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
487927c847dSDimitry Andric                        :
488927c847dSDimitry Andric                        : "memory");
489*fe6060f1SDimitry Andric #else
490*fe6060f1SDimitry Andric   __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1"
491*fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
492*fe6060f1SDimitry Andric                        :
493*fe6060f1SDimitry Andric                        : "memory");
494*fe6060f1SDimitry Andric #endif
495927c847dSDimitry Andric }
496927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
497927c847dSDimitry Andric                                                   unsigned long __x,
498927c847dSDimitry Andric                                                   size_t __n) {
499927c847dSDimitry Andric   __asm__ __volatile__("rep stosl"
500927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
501927c847dSDimitry Andric                        : "a"(__x)
502927c847dSDimitry Andric                        : "memory");
503927c847dSDimitry Andric }
504927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
505927c847dSDimitry Andric                                                   unsigned short __x,
506927c847dSDimitry Andric                                                   size_t __n) {
507927c847dSDimitry Andric   __asm__ __volatile__("rep stosw"
508927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
509927c847dSDimitry Andric                        : "a"(__x)
5100b57cec5SDimitry Andric                        : "memory");
5110b57cec5SDimitry Andric }
5120b57cec5SDimitry Andric #endif
5130b57cec5SDimitry Andric #ifdef __x86_64__
514927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsq(
515927c847dSDimitry Andric     unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
516927c847dSDimitry Andric   __asm__ __volatile__("rep movsq"
517927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
518927c847dSDimitry Andric                        :
519927c847dSDimitry Andric                        : "memory");
5200b57cec5SDimitry Andric }
521927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
522927c847dSDimitry Andric                                                   unsigned __int64 __x,
523927c847dSDimitry Andric                                                   size_t __n) {
5240b57cec5SDimitry Andric   __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
5250b57cec5SDimitry Andric                        : "memory");
5260b57cec5SDimitry Andric }
5270b57cec5SDimitry Andric #endif
5280b57cec5SDimitry Andric 
5290b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5300b57cec5SDimitry Andric |* Misc
5310b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5320b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
533*fe6060f1SDimitry Andric #if defined(__i386__)
534*fe6060f1SDimitry Andric #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx)             \
535*fe6060f1SDimitry Andric   __asm("cpuid"                                                                \
536*fe6060f1SDimitry Andric         : "=a"(__eax), "=b"(__ebx), "=c"(__ecx), "=d"(__edx)                   \
537*fe6060f1SDimitry Andric         : "0"(__leaf), "2"(__count))
538*fe6060f1SDimitry Andric #else
539*fe6060f1SDimitry Andric /* x86-64 uses %rbx as the base register, so preserve it. */
540*fe6060f1SDimitry Andric #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx)             \
541*fe6060f1SDimitry Andric   __asm("xchgq %%rbx,%q1\n"                                                    \
542*fe6060f1SDimitry Andric         "cpuid\n"                                                              \
543*fe6060f1SDimitry Andric         "xchgq %%rbx,%q1"                                                      \
544*fe6060f1SDimitry Andric         : "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)                   \
545*fe6060f1SDimitry Andric         : "0"(__leaf), "2"(__count))
546*fe6060f1SDimitry Andric #endif
547927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) {
548*fe6060f1SDimitry Andric   __cpuid_count(__level, 0, __info[0], __info[1], __info[2], __info[3]);
5490b57cec5SDimitry Andric }
550927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level,
551927c847dSDimitry Andric                                                     int __ecx) {
552*fe6060f1SDimitry Andric   __cpuid_count(__level, __ecx, __info[0], __info[1], __info[2], __info[3]);
5530b57cec5SDimitry Andric }
554927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
5550b57cec5SDimitry Andric   __asm__ volatile("hlt");
5560b57cec5SDimitry Andric }
5570b57cec5SDimitry Andric #endif
5580b57cec5SDimitry Andric 
5590b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
560927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
5610b57cec5SDimitry Andric   __asm__ volatile("nop");
5620b57cec5SDimitry Andric }
5630b57cec5SDimitry Andric #endif
5640b57cec5SDimitry Andric 
5650b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5660b57cec5SDimitry Andric |* MS AArch64 specific
5670b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5680b57cec5SDimitry Andric #if defined(__aarch64__)
5690b57cec5SDimitry Andric unsigned __int64 __getReg(int);
5700b57cec5SDimitry Andric long _InterlockedAdd(long volatile *Addend, long Value);
5710b57cec5SDimitry Andric __int64 _ReadStatusReg(int);
5720b57cec5SDimitry Andric void _WriteStatusReg(int, __int64);
5730b57cec5SDimitry Andric 
5740b57cec5SDimitry Andric unsigned short __cdecl _byteswap_ushort(unsigned short val);
5750b57cec5SDimitry Andric unsigned long __cdecl _byteswap_ulong (unsigned long val);
5760b57cec5SDimitry Andric unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
5770b57cec5SDimitry Andric #endif
5780b57cec5SDimitry Andric 
5790b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5800b57cec5SDimitry Andric |* Privileged intrinsics
5810b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5820b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
5830b57cec5SDimitry Andric static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
5840b57cec5SDimitry Andric __readmsr(unsigned long __register) {
5850b57cec5SDimitry Andric   // Loads the contents of a 64-bit model specific register (MSR) specified in
5860b57cec5SDimitry Andric   // the ECX register into registers EDX:EAX. The EDX register is loaded with
5870b57cec5SDimitry Andric   // the high-order 32 bits of the MSR and the EAX register is loaded with the
5880b57cec5SDimitry Andric   // low-order 32 bits. If less than 64 bits are implemented in the MSR being
5890b57cec5SDimitry Andric   // read, the values returned to EDX:EAX in unimplemented bit locations are
5900b57cec5SDimitry Andric   // undefined.
5910b57cec5SDimitry Andric   unsigned long __edx;
5920b57cec5SDimitry Andric   unsigned long __eax;
5930b57cec5SDimitry Andric   __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
5940b57cec5SDimitry Andric   return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
5950b57cec5SDimitry Andric }
596480093f4SDimitry Andric #endif
5970b57cec5SDimitry Andric 
598927c847dSDimitry Andric static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
599480093f4SDimitry Andric   unsigned __LPTRINT_TYPE__ __cr3_val;
600480093f4SDimitry Andric   __asm__ __volatile__ ("mov %%cr3, %0" : "=r"(__cr3_val) : : "memory");
6010b57cec5SDimitry Andric   return __cr3_val;
6020b57cec5SDimitry Andric }
6030b57cec5SDimitry Andric 
6040b57cec5SDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS
605480093f4SDimitry Andric __writecr3(unsigned __INTPTR_TYPE__ __cr3_val) {
606480093f4SDimitry Andric   __asm__ ("mov %0, %%cr3" : : "r"(__cr3_val) : "memory");
6070b57cec5SDimitry Andric }
6080b57cec5SDimitry Andric 
6090b57cec5SDimitry Andric #ifdef __cplusplus
6100b57cec5SDimitry Andric }
6110b57cec5SDimitry Andric #endif
6120b57cec5SDimitry Andric 
613480093f4SDimitry Andric #undef __LPTRINT_TYPE__
614480093f4SDimitry Andric 
6150b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS
6160b57cec5SDimitry Andric 
6170b57cec5SDimitry Andric #endif /* __INTRIN_H */
6180b57cec5SDimitry Andric #endif /* _MSC_VER */
619