xref: /freebsd/contrib/llvm-project/clang/lib/Headers/intrin.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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 short __readfsword(unsigned long);
101349cc55cSDimitry Andric unsigned long __readfsdword(unsigned long);
102349cc55cSDimitry Andric unsigned __int64 __readfsqword(unsigned long);
1030b57cec5SDimitry Andric #endif
1040b57cec5SDimitry Andric unsigned __int64 __readmsr(unsigned long);
1050b57cec5SDimitry Andric unsigned __int64 __readpmc(unsigned long);
1060b57cec5SDimitry Andric unsigned long __segmentlimit(unsigned long);
1070b57cec5SDimitry Andric void __sidt(void *);
1080b57cec5SDimitry Andric void __stosb(unsigned char *, unsigned char, size_t);
1090b57cec5SDimitry Andric void __stosd(unsigned long *, unsigned long, size_t);
1100b57cec5SDimitry Andric void __stosw(unsigned short *, unsigned short, size_t);
1110b57cec5SDimitry Andric void __svm_clgi(void);
1120b57cec5SDimitry Andric void __svm_invlpga(void *, int);
1130b57cec5SDimitry Andric void __svm_skinit(int);
1140b57cec5SDimitry Andric void __svm_stgi(void);
1150b57cec5SDimitry Andric void __svm_vmload(size_t);
1160b57cec5SDimitry Andric void __svm_vmrun(size_t);
1170b57cec5SDimitry Andric void __svm_vmsave(size_t);
1180b57cec5SDimitry Andric void __ud2(void);
1190b57cec5SDimitry Andric unsigned __int64 __ull_rshift(unsigned __int64, int);
1200b57cec5SDimitry Andric void __vmx_off(void);
1210b57cec5SDimitry Andric void __vmx_vmptrst(unsigned __int64 *);
1220b57cec5SDimitry Andric void __wbinvd(void);
1230b57cec5SDimitry Andric void __writecr0(unsigned int);
124480093f4SDimitry Andric void __writecr3(unsigned __INTPTR_TYPE__);
1250b57cec5SDimitry Andric void __writecr4(unsigned int);
1260b57cec5SDimitry Andric void __writecr8(unsigned int);
1270b57cec5SDimitry Andric void __writedr(unsigned int, unsigned int);
1280b57cec5SDimitry Andric void __writefsbyte(unsigned long, unsigned char);
1290b57cec5SDimitry Andric void __writefsdword(unsigned long, unsigned long);
1300b57cec5SDimitry Andric void __writefsqword(unsigned long, unsigned __int64);
1310b57cec5SDimitry Andric void __writefsword(unsigned long, unsigned short);
1320b57cec5SDimitry Andric void __writemsr(unsigned long, unsigned __int64);
1330b57cec5SDimitry Andric void *_AddressOfReturnAddress(void);
1340b57cec5SDimitry Andric unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
1350b57cec5SDimitry Andric unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
1360b57cec5SDimitry Andric unsigned char _bittest(long const *, long);
1370b57cec5SDimitry Andric unsigned char _bittestandcomplement(long *, long);
1380b57cec5SDimitry Andric unsigned char _bittestandreset(long *, long);
1390b57cec5SDimitry Andric unsigned char _bittestandset(long *, long);
1400b57cec5SDimitry Andric void __cdecl _disable(void);
1410b57cec5SDimitry Andric void __cdecl _enable(void);
1420b57cec5SDimitry Andric long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
1430b57cec5SDimitry Andric unsigned char _interlockedbittestandreset(long volatile *, long);
1440b57cec5SDimitry Andric unsigned char _interlockedbittestandset(long volatile *, long);
1450b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
1460b57cec5SDimitry Andric                                                     void *);
1470b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
1480b57cec5SDimitry Andric                                                     void *);
1490b57cec5SDimitry Andric long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
1500b57cec5SDimitry Andric long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
1510b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
1520b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
153349cc55cSDimitry Andric void _ReadBarrier(void);
154349cc55cSDimitry Andric void _ReadWriteBarrier(void);
1550b57cec5SDimitry Andric unsigned int _rorx_u32(unsigned int, const unsigned int);
1560b57cec5SDimitry Andric int _sarx_i32(int, unsigned int);
1570b57cec5SDimitry Andric #if __STDC_HOSTED__
1580b57cec5SDimitry Andric int __cdecl _setjmp(jmp_buf);
1590b57cec5SDimitry Andric #endif
1600b57cec5SDimitry Andric unsigned int _shlx_u32(unsigned int, unsigned int);
1610b57cec5SDimitry Andric unsigned int _shrx_u32(unsigned int, unsigned int);
1620b57cec5SDimitry Andric void _Store_HLERelease(long volatile *, long);
1630b57cec5SDimitry Andric void _Store64_HLERelease(__int64 volatile *, __int64);
1640b57cec5SDimitry Andric void _StorePointer_HLERelease(void *volatile *, void *);
165349cc55cSDimitry Andric void _WriteBarrier(void);
1660b57cec5SDimitry Andric unsigned __int32 xbegin(void);
1670b57cec5SDimitry Andric void _xend(void);
1680b57cec5SDimitry Andric 
1690b57cec5SDimitry Andric /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
1700b57cec5SDimitry Andric #ifdef __x86_64__
1710b57cec5SDimitry Andric void __addgsbyte(unsigned long, unsigned char);
1720b57cec5SDimitry Andric void __addgsdword(unsigned long, unsigned long);
1730b57cec5SDimitry Andric void __addgsqword(unsigned long, unsigned __int64);
1740b57cec5SDimitry Andric void __addgsword(unsigned long, unsigned short);
1750b57cec5SDimitry Andric void __faststorefence(void);
1760b57cec5SDimitry Andric void __incgsbyte(unsigned long);
1770b57cec5SDimitry Andric void __incgsdword(unsigned long);
1780b57cec5SDimitry Andric void __incgsqword(unsigned long);
1790b57cec5SDimitry Andric void __incgsword(unsigned long);
1800b57cec5SDimitry Andric void __movsq(unsigned long long *, unsigned long long const *, size_t);
1810b57cec5SDimitry Andric unsigned char __readgsbyte(unsigned long);
1820b57cec5SDimitry Andric unsigned long __readgsdword(unsigned long);
1830b57cec5SDimitry Andric unsigned __int64 __readgsqword(unsigned long);
1840b57cec5SDimitry Andric unsigned short __readgsword(unsigned long);
1850b57cec5SDimitry Andric unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
1860b57cec5SDimitry Andric                                 unsigned __int64 _HighPart,
1870b57cec5SDimitry Andric                                 unsigned char _Shift);
1880b57cec5SDimitry Andric unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
1890b57cec5SDimitry Andric                                  unsigned __int64 _HighPart,
1900b57cec5SDimitry Andric                                  unsigned char _Shift);
1910b57cec5SDimitry Andric void __stosq(unsigned __int64 *, unsigned __int64, size_t);
1920b57cec5SDimitry Andric unsigned char __vmx_on(unsigned __int64 *);
1930b57cec5SDimitry Andric unsigned char __vmx_vmclear(unsigned __int64 *);
1940b57cec5SDimitry Andric unsigned char __vmx_vmlaunch(void);
1950b57cec5SDimitry Andric unsigned char __vmx_vmptrld(unsigned __int64 *);
1960b57cec5SDimitry Andric unsigned char __vmx_vmread(size_t, size_t *);
1970b57cec5SDimitry Andric unsigned char __vmx_vmresume(void);
1980b57cec5SDimitry Andric unsigned char __vmx_vmwrite(size_t, size_t);
1990b57cec5SDimitry Andric void __writegsbyte(unsigned long, unsigned char);
2000b57cec5SDimitry Andric void __writegsdword(unsigned long, unsigned long);
2010b57cec5SDimitry Andric void __writegsqword(unsigned long, unsigned __int64);
2020b57cec5SDimitry Andric void __writegsword(unsigned long, unsigned short);
2030b57cec5SDimitry Andric unsigned char _bittest64(__int64 const *, __int64);
2040b57cec5SDimitry Andric unsigned char _bittestandcomplement64(__int64 *, __int64);
2050b57cec5SDimitry Andric unsigned char _bittestandreset64(__int64 *, __int64);
2060b57cec5SDimitry Andric unsigned char _bittestandset64(__int64 *, __int64);
2070b57cec5SDimitry Andric long _InterlockedAnd_np(long volatile *_Value, long _Mask);
2080b57cec5SDimitry Andric short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
2090b57cec5SDimitry Andric __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
2100b57cec5SDimitry Andric char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
2110b57cec5SDimitry Andric unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
2120b57cec5SDimitry Andric unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
2130b57cec5SDimitry Andric long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
2140b57cec5SDimitry Andric                                     long _Comparand);
2150b57cec5SDimitry Andric unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
2160b57cec5SDimitry Andric                                                 __int64 _ExchangeHigh,
2170b57cec5SDimitry Andric                                                 __int64 _ExchangeLow,
2180b57cec5SDimitry Andric                                                 __int64 *_ComparandResult);
2190b57cec5SDimitry Andric short _InterlockedCompareExchange16_np(short volatile *_Destination,
2200b57cec5SDimitry Andric                                        short _Exchange, short _Comparand);
2210b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
2220b57cec5SDimitry Andric                                          __int64 _Exchange, __int64 _Comparand);
2230b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
2240b57cec5SDimitry Andric                                             void *_Exchange, void *_Comparand);
2250b57cec5SDimitry Andric long _InterlockedOr_np(long volatile *_Value, long _Mask);
2260b57cec5SDimitry Andric short _InterlockedOr16_np(short volatile *_Value, short _Mask);
2270b57cec5SDimitry Andric __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
2280b57cec5SDimitry Andric char _InterlockedOr8_np(char volatile *_Value, char _Mask);
2290b57cec5SDimitry Andric long _InterlockedXor_np(long volatile *_Value, long _Mask);
2300b57cec5SDimitry Andric short _InterlockedXor16_np(short volatile *_Value, short _Mask);
2310b57cec5SDimitry Andric __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
2320b57cec5SDimitry Andric char _InterlockedXor8_np(char volatile *_Value, char _Mask);
2330b57cec5SDimitry Andric unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
2340b57cec5SDimitry Andric __int64 _sarx_i64(__int64, unsigned int);
2350b57cec5SDimitry Andric unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
2360b57cec5SDimitry Andric unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
2370b57cec5SDimitry Andric __int64 __mulh(__int64, __int64);
2380b57cec5SDimitry Andric unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
2390b57cec5SDimitry Andric __int64 _mul128(__int64, __int64, __int64*);
2400b57cec5SDimitry Andric unsigned __int64 _umul128(unsigned __int64,
2410b57cec5SDimitry Andric                           unsigned __int64,
2420b57cec5SDimitry Andric                           unsigned __int64*);
2430b57cec5SDimitry Andric 
2440b57cec5SDimitry Andric #endif /* __x86_64__ */
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2470b57cec5SDimitry Andric 
2480b57cec5SDimitry Andric unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
2490b57cec5SDimitry Andric unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
2500b57cec5SDimitry Andric 
2515ffd83dbSDimitry Andric #endif
2525ffd83dbSDimitry Andric 
2535ffd83dbSDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2540b57cec5SDimitry Andric __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
2550b57cec5SDimitry Andric __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
2560b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
2570b57cec5SDimitry Andric __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
2580b57cec5SDimitry Andric __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
2590b57cec5SDimitry Andric __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
2600b57cec5SDimitry Andric __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
2610b57cec5SDimitry Andric __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
2620b57cec5SDimitry Andric 
2630b57cec5SDimitry Andric #endif
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2660b57cec5SDimitry Andric |* Interlocked Exchange Add
2670b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2680b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2690b57cec5SDimitry Andric char _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value);
2700b57cec5SDimitry Andric char _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value);
2710b57cec5SDimitry Andric char _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value);
2720b57cec5SDimitry Andric short _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value);
2730b57cec5SDimitry Andric short _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value);
2740b57cec5SDimitry Andric short _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value);
2750b57cec5SDimitry Andric long _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value);
2760b57cec5SDimitry Andric long _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value);
2770b57cec5SDimitry Andric long _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value);
2780b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value);
2790b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value);
2800b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value);
2810b57cec5SDimitry Andric #endif
2820b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2830b57cec5SDimitry Andric |* Interlocked Increment
2840b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2850b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2860b57cec5SDimitry Andric short _InterlockedIncrement16_acq(short volatile *_Value);
2870b57cec5SDimitry Andric short _InterlockedIncrement16_nf(short volatile *_Value);
2880b57cec5SDimitry Andric short _InterlockedIncrement16_rel(short volatile *_Value);
2890b57cec5SDimitry Andric long _InterlockedIncrement_acq(long volatile *_Value);
2900b57cec5SDimitry Andric long _InterlockedIncrement_nf(long volatile *_Value);
2910b57cec5SDimitry Andric long _InterlockedIncrement_rel(long volatile *_Value);
2920b57cec5SDimitry Andric __int64 _InterlockedIncrement64_acq(__int64 volatile *_Value);
2930b57cec5SDimitry Andric __int64 _InterlockedIncrement64_nf(__int64 volatile *_Value);
2940b57cec5SDimitry Andric __int64 _InterlockedIncrement64_rel(__int64 volatile *_Value);
2950b57cec5SDimitry Andric #endif
2960b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2970b57cec5SDimitry Andric |* Interlocked Decrement
2980b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2990b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3000b57cec5SDimitry Andric short _InterlockedDecrement16_acq(short volatile *_Value);
3010b57cec5SDimitry Andric short _InterlockedDecrement16_nf(short volatile *_Value);
3020b57cec5SDimitry Andric short _InterlockedDecrement16_rel(short volatile *_Value);
3030b57cec5SDimitry Andric long _InterlockedDecrement_acq(long volatile *_Value);
3040b57cec5SDimitry Andric long _InterlockedDecrement_nf(long volatile *_Value);
3050b57cec5SDimitry Andric long _InterlockedDecrement_rel(long volatile *_Value);
3060b57cec5SDimitry Andric __int64 _InterlockedDecrement64_acq(__int64 volatile *_Value);
3070b57cec5SDimitry Andric __int64 _InterlockedDecrement64_nf(__int64 volatile *_Value);
3080b57cec5SDimitry Andric __int64 _InterlockedDecrement64_rel(__int64 volatile *_Value);
3090b57cec5SDimitry Andric #endif
3100b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3110b57cec5SDimitry Andric |* Interlocked And
3120b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3130b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3140b57cec5SDimitry Andric char _InterlockedAnd8_acq(char volatile *_Value, char _Mask);
3150b57cec5SDimitry Andric char _InterlockedAnd8_nf(char volatile *_Value, char _Mask);
3160b57cec5SDimitry Andric char _InterlockedAnd8_rel(char volatile *_Value, char _Mask);
3170b57cec5SDimitry Andric short _InterlockedAnd16_acq(short volatile *_Value, short _Mask);
3180b57cec5SDimitry Andric short _InterlockedAnd16_nf(short volatile *_Value, short _Mask);
3190b57cec5SDimitry Andric short _InterlockedAnd16_rel(short volatile *_Value, short _Mask);
3200b57cec5SDimitry Andric long _InterlockedAnd_acq(long volatile *_Value, long _Mask);
3210b57cec5SDimitry Andric long _InterlockedAnd_nf(long volatile *_Value, long _Mask);
3220b57cec5SDimitry Andric long _InterlockedAnd_rel(long volatile *_Value, long _Mask);
3230b57cec5SDimitry Andric __int64 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask);
3240b57cec5SDimitry Andric __int64 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask);
3250b57cec5SDimitry Andric __int64 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask);
3260b57cec5SDimitry Andric #endif
3270b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3280b57cec5SDimitry Andric |* Bit Counting and Testing
3290b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3300b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3310b57cec5SDimitry Andric unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
3320b57cec5SDimitry Andric                                             long _BitPos);
3330b57cec5SDimitry Andric unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
3340b57cec5SDimitry Andric                                            long _BitPos);
3350b57cec5SDimitry Andric unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
3360b57cec5SDimitry Andric                                             long _BitPos);
3370b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
3380b57cec5SDimitry Andric                                               long _BitPos);
3390b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
3400b57cec5SDimitry Andric                                              long _BitPos);
3410b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
3420b57cec5SDimitry Andric                                               long _BitPos);
3430b57cec5SDimitry Andric #endif
3440b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3450b57cec5SDimitry Andric |* Interlocked Or
3460b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3470b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3480b57cec5SDimitry Andric char _InterlockedOr8_acq(char volatile *_Value, char _Mask);
3490b57cec5SDimitry Andric char _InterlockedOr8_nf(char volatile *_Value, char _Mask);
3500b57cec5SDimitry Andric char _InterlockedOr8_rel(char volatile *_Value, char _Mask);
3510b57cec5SDimitry Andric short _InterlockedOr16_acq(short volatile *_Value, short _Mask);
3520b57cec5SDimitry Andric short _InterlockedOr16_nf(short volatile *_Value, short _Mask);
3530b57cec5SDimitry Andric short _InterlockedOr16_rel(short volatile *_Value, short _Mask);
3540b57cec5SDimitry Andric long _InterlockedOr_acq(long volatile *_Value, long _Mask);
3550b57cec5SDimitry Andric long _InterlockedOr_nf(long volatile *_Value, long _Mask);
3560b57cec5SDimitry Andric long _InterlockedOr_rel(long volatile *_Value, long _Mask);
3570b57cec5SDimitry Andric __int64 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask);
3580b57cec5SDimitry Andric __int64 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask);
3590b57cec5SDimitry Andric __int64 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask);
3600b57cec5SDimitry Andric #endif
3610b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3620b57cec5SDimitry Andric |* Interlocked Xor
3630b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3640b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3650b57cec5SDimitry Andric char _InterlockedXor8_acq(char volatile *_Value, char _Mask);
3660b57cec5SDimitry Andric char _InterlockedXor8_nf(char volatile *_Value, char _Mask);
3670b57cec5SDimitry Andric char _InterlockedXor8_rel(char volatile *_Value, char _Mask);
3680b57cec5SDimitry Andric short _InterlockedXor16_acq(short volatile *_Value, short _Mask);
3690b57cec5SDimitry Andric short _InterlockedXor16_nf(short volatile *_Value, short _Mask);
3700b57cec5SDimitry Andric short _InterlockedXor16_rel(short volatile *_Value, short _Mask);
3710b57cec5SDimitry Andric long _InterlockedXor_acq(long volatile *_Value, long _Mask);
3720b57cec5SDimitry Andric long _InterlockedXor_nf(long volatile *_Value, long _Mask);
3730b57cec5SDimitry Andric long _InterlockedXor_rel(long volatile *_Value, long _Mask);
3740b57cec5SDimitry Andric __int64 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask);
3750b57cec5SDimitry Andric __int64 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask);
3760b57cec5SDimitry Andric __int64 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask);
3770b57cec5SDimitry Andric #endif
3780b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3790b57cec5SDimitry Andric |* Interlocked Exchange
3800b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3810b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3820b57cec5SDimitry Andric char _InterlockedExchange8_acq(char volatile *_Target, char _Value);
3830b57cec5SDimitry Andric char _InterlockedExchange8_nf(char volatile *_Target, char _Value);
3840b57cec5SDimitry Andric char _InterlockedExchange8_rel(char volatile *_Target, char _Value);
3850b57cec5SDimitry Andric short _InterlockedExchange16_acq(short volatile *_Target, short _Value);
3860b57cec5SDimitry Andric short _InterlockedExchange16_nf(short volatile *_Target, short _Value);
3870b57cec5SDimitry Andric short _InterlockedExchange16_rel(short volatile *_Target, short _Value);
3880b57cec5SDimitry Andric long _InterlockedExchange_acq(long volatile *_Target, long _Value);
3890b57cec5SDimitry Andric long _InterlockedExchange_nf(long volatile *_Target, long _Value);
3900b57cec5SDimitry Andric long _InterlockedExchange_rel(long volatile *_Target, long _Value);
3910b57cec5SDimitry Andric __int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
3920b57cec5SDimitry Andric __int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
3930b57cec5SDimitry Andric __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
3940b57cec5SDimitry Andric #endif
3950b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3960b57cec5SDimitry Andric |* Interlocked Compare Exchange
3970b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3980b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3990b57cec5SDimitry Andric char _InterlockedCompareExchange8_acq(char volatile *_Destination,
4000b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4010b57cec5SDimitry Andric char _InterlockedCompareExchange8_nf(char volatile *_Destination,
4020b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4030b57cec5SDimitry Andric char _InterlockedCompareExchange8_rel(char volatile *_Destination,
4040b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4050b57cec5SDimitry Andric short _InterlockedCompareExchange16_acq(short volatile *_Destination,
4060b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4070b57cec5SDimitry Andric short _InterlockedCompareExchange16_nf(short volatile *_Destination,
4080b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4090b57cec5SDimitry Andric short _InterlockedCompareExchange16_rel(short volatile *_Destination,
4100b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4110b57cec5SDimitry Andric long _InterlockedCompareExchange_acq(long volatile *_Destination,
4120b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4130b57cec5SDimitry Andric long _InterlockedCompareExchange_nf(long volatile *_Destination,
4140b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4150b57cec5SDimitry Andric long _InterlockedCompareExchange_rel(long volatile *_Destination,
4160b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4170b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
4180b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4190b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
4200b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4210b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
4220b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4230b57cec5SDimitry Andric #endif
424e8d8bef9SDimitry Andric #if defined(__x86_64__) || defined(__aarch64__)
425e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
426e8d8bef9SDimitry Andric                                              __int64 _ExchangeHigh,
427e8d8bef9SDimitry Andric                                              __int64 _ExchangeLow,
428e8d8bef9SDimitry Andric                                              __int64 *_ComparandResult);
429e8d8bef9SDimitry Andric #endif
430e8d8bef9SDimitry Andric #if defined(__aarch64__)
431e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_acq(__int64 volatile *_Destination,
432e8d8bef9SDimitry Andric                                                  __int64 _ExchangeHigh,
433e8d8bef9SDimitry Andric                                                  __int64 _ExchangeLow,
434e8d8bef9SDimitry Andric                                                  __int64 *_ComparandResult);
435e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_nf(__int64 volatile *_Destination,
436e8d8bef9SDimitry Andric                                                 __int64 _ExchangeHigh,
437e8d8bef9SDimitry Andric                                                 __int64 _ExchangeLow,
438e8d8bef9SDimitry Andric                                                 __int64 *_ComparandResult);
439e8d8bef9SDimitry Andric unsigned char _InterlockedCompareExchange128_rel(__int64 volatile *_Destination,
440e8d8bef9SDimitry Andric                                                  __int64 _ExchangeHigh,
441e8d8bef9SDimitry Andric                                                  __int64 _ExchangeLow,
442e8d8bef9SDimitry Andric                                                  __int64 *_ComparandResult);
443e8d8bef9SDimitry Andric #endif
4440b57cec5SDimitry Andric 
4450b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
4460b57cec5SDimitry Andric |* movs, stos
4470b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4480b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
449927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
450927c847dSDimitry Andric                                                   unsigned char const *__src,
451927c847dSDimitry Andric                                                   size_t __n) {
452fe6060f1SDimitry Andric #if defined(__x86_64__)
453fe6060f1SDimitry Andric   __asm__ __volatile__("rep movsb"
454fe6060f1SDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
455fe6060f1SDimitry Andric                        :
456fe6060f1SDimitry Andric                        : "memory");
457fe6060f1SDimitry Andric #else
458349cc55cSDimitry Andric   __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
459349cc55cSDimitry Andric                        "rep movsb\n"
460349cc55cSDimitry Andric                        "xchg {%%esi, %1|%1, esi}"
461fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
462fe6060f1SDimitry Andric                        :
463fe6060f1SDimitry Andric                        : "memory");
464fe6060f1SDimitry 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) {
469fe6060f1SDimitry Andric #if defined(__x86_64__)
470349cc55cSDimitry Andric   __asm__ __volatile__("rep movs{l|d}"
471927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
472927c847dSDimitry Andric                        :
4730b57cec5SDimitry Andric                        : "memory");
474fe6060f1SDimitry Andric #else
475349cc55cSDimitry Andric   __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
476349cc55cSDimitry Andric                        "rep movs{l|d}\n"
477349cc55cSDimitry Andric                        "xchg {%%esi, %1|%1, esi}"
478fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
479fe6060f1SDimitry Andric                        :
480fe6060f1SDimitry Andric                        : "memory");
481fe6060f1SDimitry Andric #endif
4820b57cec5SDimitry Andric }
483927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
484927c847dSDimitry Andric                                                   unsigned short const *__src,
485927c847dSDimitry Andric                                                   size_t __n) {
486fe6060f1SDimitry Andric #if defined(__x86_64__)
487927c847dSDimitry Andric   __asm__ __volatile__("rep movsw"
488927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
489927c847dSDimitry Andric                        :
490927c847dSDimitry Andric                        : "memory");
491fe6060f1SDimitry Andric #else
492349cc55cSDimitry Andric   __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
493349cc55cSDimitry Andric                        "rep movsw\n"
494349cc55cSDimitry Andric                        "xchg {%%esi, %1|%1, esi}"
495fe6060f1SDimitry Andric                        : "+D"(__dst), "+r"(__src), "+c"(__n)
496fe6060f1SDimitry Andric                        :
497fe6060f1SDimitry Andric                        : "memory");
498fe6060f1SDimitry Andric #endif
499927c847dSDimitry Andric }
500927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
501927c847dSDimitry Andric                                                   unsigned long __x,
502927c847dSDimitry Andric                                                   size_t __n) {
503349cc55cSDimitry Andric   __asm__ __volatile__("rep stos{l|d}"
504927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
505927c847dSDimitry Andric                        : "a"(__x)
506927c847dSDimitry Andric                        : "memory");
507927c847dSDimitry Andric }
508927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
509927c847dSDimitry Andric                                                   unsigned short __x,
510927c847dSDimitry Andric                                                   size_t __n) {
511927c847dSDimitry Andric   __asm__ __volatile__("rep stosw"
512927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
513927c847dSDimitry Andric                        : "a"(__x)
5140b57cec5SDimitry Andric                        : "memory");
5150b57cec5SDimitry Andric }
5160b57cec5SDimitry Andric #endif
5170b57cec5SDimitry Andric #ifdef __x86_64__
518927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsq(
519927c847dSDimitry Andric     unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
520927c847dSDimitry Andric   __asm__ __volatile__("rep movsq"
521927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
522927c847dSDimitry Andric                        :
523927c847dSDimitry Andric                        : "memory");
5240b57cec5SDimitry Andric }
525927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
526927c847dSDimitry Andric                                                   unsigned __int64 __x,
527927c847dSDimitry Andric                                                   size_t __n) {
5280b57cec5SDimitry Andric   __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
5290b57cec5SDimitry Andric                        : "memory");
5300b57cec5SDimitry Andric }
5310b57cec5SDimitry Andric #endif
5320b57cec5SDimitry Andric 
5330b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5340b57cec5SDimitry Andric |* Misc
5350b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5360b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
537927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
5380b57cec5SDimitry Andric   __asm__ volatile("hlt");
5390b57cec5SDimitry Andric }
5400b57cec5SDimitry Andric #endif
5410b57cec5SDimitry Andric 
5420b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
543927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
5440b57cec5SDimitry Andric   __asm__ volatile("nop");
5450b57cec5SDimitry Andric }
5460b57cec5SDimitry Andric #endif
5470b57cec5SDimitry Andric 
5480b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5490b57cec5SDimitry Andric |* MS AArch64 specific
5500b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5510b57cec5SDimitry Andric #if defined(__aarch64__)
5520b57cec5SDimitry Andric unsigned __int64 __getReg(int);
5530b57cec5SDimitry Andric long _InterlockedAdd(long volatile *Addend, long Value);
5540b57cec5SDimitry Andric __int64 _ReadStatusReg(int);
5550b57cec5SDimitry Andric void _WriteStatusReg(int, __int64);
5560b57cec5SDimitry Andric 
5570b57cec5SDimitry Andric unsigned short __cdecl _byteswap_ushort(unsigned short val);
5580b57cec5SDimitry Andric unsigned long __cdecl _byteswap_ulong (unsigned long val);
5590b57cec5SDimitry Andric unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
5606e75b2fbSDimitry Andric 
5616e75b2fbSDimitry Andric __int64 __mulh(__int64 __a, __int64 __b);
5626e75b2fbSDimitry Andric unsigned __int64 __umulh(unsigned __int64 __a, unsigned __int64 __b);
56381ad6265SDimitry Andric 
56481ad6265SDimitry Andric void __break(int);
56581ad6265SDimitry Andric 
56681ad6265SDimitry Andric void __writex18byte(unsigned long offset, unsigned char data);
56781ad6265SDimitry Andric void __writex18word(unsigned long offset, unsigned short data);
56881ad6265SDimitry Andric void __writex18dword(unsigned long offset, unsigned long data);
56981ad6265SDimitry Andric void __writex18qword(unsigned long offset, unsigned __int64 data);
57081ad6265SDimitry Andric 
57181ad6265SDimitry Andric unsigned char __readx18byte(unsigned long offset);
57281ad6265SDimitry Andric unsigned short __readx18word(unsigned long offset);
57381ad6265SDimitry Andric unsigned long __readx18dword(unsigned long offset);
57481ad6265SDimitry Andric unsigned __int64 __readx18qword(unsigned long offset);
575*5f757f3fSDimitry Andric 
576*5f757f3fSDimitry Andric double _CopyDoubleFromInt64(__int64);
577*5f757f3fSDimitry Andric float _CopyFloatFromInt32(__int32);
578*5f757f3fSDimitry Andric __int32 _CopyInt32FromFloat(float);
579*5f757f3fSDimitry Andric __int64 _CopyInt64FromDouble(double);
580*5f757f3fSDimitry Andric 
581*5f757f3fSDimitry Andric unsigned int _CountLeadingOnes(unsigned long);
582*5f757f3fSDimitry Andric unsigned int _CountLeadingOnes64(unsigned __int64);
583*5f757f3fSDimitry Andric unsigned int _CountLeadingSigns(long);
584*5f757f3fSDimitry Andric unsigned int _CountLeadingSigns64(__int64);
585*5f757f3fSDimitry Andric unsigned int _CountLeadingZeros(unsigned long);
586*5f757f3fSDimitry Andric unsigned int _CountLeadingZeros64(unsigned _int64);
587*5f757f3fSDimitry Andric unsigned int _CountOneBits(unsigned long);
588*5f757f3fSDimitry Andric unsigned int _CountOneBits64(unsigned __int64);
589*5f757f3fSDimitry Andric 
590*5f757f3fSDimitry Andric void __cdecl __prefetch(void *);
5910b57cec5SDimitry Andric #endif
5920b57cec5SDimitry Andric 
5930b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5940b57cec5SDimitry Andric |* Privileged intrinsics
5950b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5960b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
5970b57cec5SDimitry Andric static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
5980b57cec5SDimitry Andric __readmsr(unsigned long __register) {
5990b57cec5SDimitry Andric   // Loads the contents of a 64-bit model specific register (MSR) specified in
6000b57cec5SDimitry Andric   // the ECX register into registers EDX:EAX. The EDX register is loaded with
6010b57cec5SDimitry Andric   // the high-order 32 bits of the MSR and the EAX register is loaded with the
6020b57cec5SDimitry Andric   // low-order 32 bits. If less than 64 bits are implemented in the MSR being
6030b57cec5SDimitry Andric   // read, the values returned to EDX:EAX in unimplemented bit locations are
6040b57cec5SDimitry Andric   // undefined.
6050b57cec5SDimitry Andric   unsigned long __edx;
6060b57cec5SDimitry Andric   unsigned long __eax;
6070b57cec5SDimitry Andric   __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
6080b57cec5SDimitry Andric   return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
6090b57cec5SDimitry Andric }
610480093f4SDimitry Andric #endif
6110b57cec5SDimitry Andric 
612927c847dSDimitry Andric static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
613480093f4SDimitry Andric   unsigned __LPTRINT_TYPE__ __cr3_val;
614349cc55cSDimitry Andric   __asm__ __volatile__(
615349cc55cSDimitry Andric                        "mov {%%cr3, %0|%0, cr3}"
616349cc55cSDimitry Andric                        : "=r"(__cr3_val)
617349cc55cSDimitry Andric                        :
618349cc55cSDimitry Andric                        : "memory");
6190b57cec5SDimitry Andric   return __cr3_val;
6200b57cec5SDimitry Andric }
6210b57cec5SDimitry Andric 
6220b57cec5SDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS
623480093f4SDimitry Andric __writecr3(unsigned __INTPTR_TYPE__ __cr3_val) {
624349cc55cSDimitry Andric   __asm__ ("mov {%0, %%cr3|cr3, %0}" : : "r"(__cr3_val) : "memory");
6250b57cec5SDimitry Andric }
6260b57cec5SDimitry Andric 
6270b57cec5SDimitry Andric #ifdef __cplusplus
6280b57cec5SDimitry Andric }
6290b57cec5SDimitry Andric #endif
6300b57cec5SDimitry Andric 
631480093f4SDimitry Andric #undef __LPTRINT_TYPE__
632480093f4SDimitry Andric 
6330b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS
6340b57cec5SDimitry Andric 
6350b57cec5SDimitry Andric #endif /* __INTRIN_H */
6360b57cec5SDimitry Andric #endif /* _MSC_VER */
637