xref: /freebsd/contrib/llvm-project/clang/lib/Headers/intrin.h (revision 927c847d5f351ca027865d4c0f2f279f9b963a72)
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);
152*927c847dSDimitry Andric void __attribute__((__deprecated__(
153*927c847dSDimitry Andric     "use other intrinsics or C++11 atomics instead"))) _ReadBarrier(void);
154*927c847dSDimitry Andric void __attribute__((__deprecated__(
155*927c847dSDimitry 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 *);
166*927c847dSDimitry Andric void __attribute__((__deprecated__(
167*927c847dSDimitry 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(__int64 volatile *_Destination,
2180b57cec5SDimitry Andric                                              __int64 _ExchangeHigh,
2190b57cec5SDimitry Andric                                              __int64 _ExchangeLow,
2200b57cec5SDimitry Andric                                              __int64 *_CompareandResult);
2210b57cec5SDimitry Andric unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
2220b57cec5SDimitry Andric                                                 __int64 _ExchangeHigh,
2230b57cec5SDimitry Andric                                                 __int64 _ExchangeLow,
2240b57cec5SDimitry Andric                                                 __int64 *_ComparandResult);
2250b57cec5SDimitry Andric short _InterlockedCompareExchange16_np(short volatile *_Destination,
2260b57cec5SDimitry Andric                                        short _Exchange, short _Comparand);
2270b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
2280b57cec5SDimitry Andric                                          __int64 _Exchange, __int64 _Comparand);
2290b57cec5SDimitry Andric void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
2300b57cec5SDimitry Andric                                             void *_Exchange, void *_Comparand);
2310b57cec5SDimitry Andric long _InterlockedOr_np(long volatile *_Value, long _Mask);
2320b57cec5SDimitry Andric short _InterlockedOr16_np(short volatile *_Value, short _Mask);
2330b57cec5SDimitry Andric __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
2340b57cec5SDimitry Andric char _InterlockedOr8_np(char volatile *_Value, char _Mask);
2350b57cec5SDimitry Andric long _InterlockedXor_np(long volatile *_Value, long _Mask);
2360b57cec5SDimitry Andric short _InterlockedXor16_np(short volatile *_Value, short _Mask);
2370b57cec5SDimitry Andric __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
2380b57cec5SDimitry Andric char _InterlockedXor8_np(char volatile *_Value, char _Mask);
2390b57cec5SDimitry Andric unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
2400b57cec5SDimitry Andric __int64 _sarx_i64(__int64, unsigned int);
2410b57cec5SDimitry Andric unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
2420b57cec5SDimitry Andric unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
2430b57cec5SDimitry Andric __int64 __mulh(__int64, __int64);
2440b57cec5SDimitry Andric unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
2450b57cec5SDimitry Andric __int64 _mul128(__int64, __int64, __int64*);
2460b57cec5SDimitry Andric unsigned __int64 _umul128(unsigned __int64,
2470b57cec5SDimitry Andric                           unsigned __int64,
2480b57cec5SDimitry Andric                           unsigned __int64*);
2490b57cec5SDimitry Andric 
2500b57cec5SDimitry Andric #endif /* __x86_64__ */
2510b57cec5SDimitry Andric 
2520b57cec5SDimitry Andric #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
2550b57cec5SDimitry Andric unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
2560b57cec5SDimitry Andric 
2575ffd83dbSDimitry Andric #endif
2585ffd83dbSDimitry Andric 
2595ffd83dbSDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
2600b57cec5SDimitry Andric __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
2610b57cec5SDimitry Andric __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
2620b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
2630b57cec5SDimitry Andric __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
2640b57cec5SDimitry Andric __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
2650b57cec5SDimitry Andric __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
2660b57cec5SDimitry Andric __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
2670b57cec5SDimitry Andric __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
2680b57cec5SDimitry Andric 
2690b57cec5SDimitry Andric #endif
2700b57cec5SDimitry Andric 
2710b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2720b57cec5SDimitry Andric |* Interlocked Exchange Add
2730b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2740b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2750b57cec5SDimitry Andric char _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value);
2760b57cec5SDimitry Andric char _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value);
2770b57cec5SDimitry Andric char _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value);
2780b57cec5SDimitry Andric short _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value);
2790b57cec5SDimitry Andric short _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value);
2800b57cec5SDimitry Andric short _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value);
2810b57cec5SDimitry Andric long _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value);
2820b57cec5SDimitry Andric long _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value);
2830b57cec5SDimitry Andric long _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value);
2840b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value);
2850b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value);
2860b57cec5SDimitry Andric __int64 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value);
2870b57cec5SDimitry Andric #endif
2880b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
2890b57cec5SDimitry Andric |* Interlocked Increment
2900b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
2910b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
2920b57cec5SDimitry Andric short _InterlockedIncrement16_acq(short volatile *_Value);
2930b57cec5SDimitry Andric short _InterlockedIncrement16_nf(short volatile *_Value);
2940b57cec5SDimitry Andric short _InterlockedIncrement16_rel(short volatile *_Value);
2950b57cec5SDimitry Andric long _InterlockedIncrement_acq(long volatile *_Value);
2960b57cec5SDimitry Andric long _InterlockedIncrement_nf(long volatile *_Value);
2970b57cec5SDimitry Andric long _InterlockedIncrement_rel(long volatile *_Value);
2980b57cec5SDimitry Andric __int64 _InterlockedIncrement64_acq(__int64 volatile *_Value);
2990b57cec5SDimitry Andric __int64 _InterlockedIncrement64_nf(__int64 volatile *_Value);
3000b57cec5SDimitry Andric __int64 _InterlockedIncrement64_rel(__int64 volatile *_Value);
3010b57cec5SDimitry Andric #endif
3020b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3030b57cec5SDimitry Andric |* Interlocked Decrement
3040b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3050b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3060b57cec5SDimitry Andric short _InterlockedDecrement16_acq(short volatile *_Value);
3070b57cec5SDimitry Andric short _InterlockedDecrement16_nf(short volatile *_Value);
3080b57cec5SDimitry Andric short _InterlockedDecrement16_rel(short volatile *_Value);
3090b57cec5SDimitry Andric long _InterlockedDecrement_acq(long volatile *_Value);
3100b57cec5SDimitry Andric long _InterlockedDecrement_nf(long volatile *_Value);
3110b57cec5SDimitry Andric long _InterlockedDecrement_rel(long volatile *_Value);
3120b57cec5SDimitry Andric __int64 _InterlockedDecrement64_acq(__int64 volatile *_Value);
3130b57cec5SDimitry Andric __int64 _InterlockedDecrement64_nf(__int64 volatile *_Value);
3140b57cec5SDimitry Andric __int64 _InterlockedDecrement64_rel(__int64 volatile *_Value);
3150b57cec5SDimitry Andric #endif
3160b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3170b57cec5SDimitry Andric |* Interlocked And
3180b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3190b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3200b57cec5SDimitry Andric char _InterlockedAnd8_acq(char volatile *_Value, char _Mask);
3210b57cec5SDimitry Andric char _InterlockedAnd8_nf(char volatile *_Value, char _Mask);
3220b57cec5SDimitry Andric char _InterlockedAnd8_rel(char volatile *_Value, char _Mask);
3230b57cec5SDimitry Andric short _InterlockedAnd16_acq(short volatile *_Value, short _Mask);
3240b57cec5SDimitry Andric short _InterlockedAnd16_nf(short volatile *_Value, short _Mask);
3250b57cec5SDimitry Andric short _InterlockedAnd16_rel(short volatile *_Value, short _Mask);
3260b57cec5SDimitry Andric long _InterlockedAnd_acq(long volatile *_Value, long _Mask);
3270b57cec5SDimitry Andric long _InterlockedAnd_nf(long volatile *_Value, long _Mask);
3280b57cec5SDimitry Andric long _InterlockedAnd_rel(long volatile *_Value, long _Mask);
3290b57cec5SDimitry Andric __int64 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask);
3300b57cec5SDimitry Andric __int64 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask);
3310b57cec5SDimitry Andric __int64 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask);
3320b57cec5SDimitry Andric #endif
3330b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3340b57cec5SDimitry Andric |* Bit Counting and Testing
3350b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3360b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3370b57cec5SDimitry Andric unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
3380b57cec5SDimitry Andric                                             long _BitPos);
3390b57cec5SDimitry Andric unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
3400b57cec5SDimitry Andric                                            long _BitPos);
3410b57cec5SDimitry Andric unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
3420b57cec5SDimitry Andric                                             long _BitPos);
3430b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
3440b57cec5SDimitry Andric                                               long _BitPos);
3450b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
3460b57cec5SDimitry Andric                                              long _BitPos);
3470b57cec5SDimitry Andric unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
3480b57cec5SDimitry Andric                                               long _BitPos);
3490b57cec5SDimitry Andric #endif
3500b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3510b57cec5SDimitry Andric |* Interlocked Or
3520b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3530b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3540b57cec5SDimitry Andric char _InterlockedOr8_acq(char volatile *_Value, char _Mask);
3550b57cec5SDimitry Andric char _InterlockedOr8_nf(char volatile *_Value, char _Mask);
3560b57cec5SDimitry Andric char _InterlockedOr8_rel(char volatile *_Value, char _Mask);
3570b57cec5SDimitry Andric short _InterlockedOr16_acq(short volatile *_Value, short _Mask);
3580b57cec5SDimitry Andric short _InterlockedOr16_nf(short volatile *_Value, short _Mask);
3590b57cec5SDimitry Andric short _InterlockedOr16_rel(short volatile *_Value, short _Mask);
3600b57cec5SDimitry Andric long _InterlockedOr_acq(long volatile *_Value, long _Mask);
3610b57cec5SDimitry Andric long _InterlockedOr_nf(long volatile *_Value, long _Mask);
3620b57cec5SDimitry Andric long _InterlockedOr_rel(long volatile *_Value, long _Mask);
3630b57cec5SDimitry Andric __int64 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask);
3640b57cec5SDimitry Andric __int64 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask);
3650b57cec5SDimitry Andric __int64 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask);
3660b57cec5SDimitry Andric #endif
3670b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3680b57cec5SDimitry Andric |* Interlocked Xor
3690b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3700b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3710b57cec5SDimitry Andric char _InterlockedXor8_acq(char volatile *_Value, char _Mask);
3720b57cec5SDimitry Andric char _InterlockedXor8_nf(char volatile *_Value, char _Mask);
3730b57cec5SDimitry Andric char _InterlockedXor8_rel(char volatile *_Value, char _Mask);
3740b57cec5SDimitry Andric short _InterlockedXor16_acq(short volatile *_Value, short _Mask);
3750b57cec5SDimitry Andric short _InterlockedXor16_nf(short volatile *_Value, short _Mask);
3760b57cec5SDimitry Andric short _InterlockedXor16_rel(short volatile *_Value, short _Mask);
3770b57cec5SDimitry Andric long _InterlockedXor_acq(long volatile *_Value, long _Mask);
3780b57cec5SDimitry Andric long _InterlockedXor_nf(long volatile *_Value, long _Mask);
3790b57cec5SDimitry Andric long _InterlockedXor_rel(long volatile *_Value, long _Mask);
3800b57cec5SDimitry Andric __int64 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask);
3810b57cec5SDimitry Andric __int64 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask);
3820b57cec5SDimitry Andric __int64 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask);
3830b57cec5SDimitry Andric #endif
3840b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
3850b57cec5SDimitry Andric |* Interlocked Exchange
3860b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
3870b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
3880b57cec5SDimitry Andric char _InterlockedExchange8_acq(char volatile *_Target, char _Value);
3890b57cec5SDimitry Andric char _InterlockedExchange8_nf(char volatile *_Target, char _Value);
3900b57cec5SDimitry Andric char _InterlockedExchange8_rel(char volatile *_Target, char _Value);
3910b57cec5SDimitry Andric short _InterlockedExchange16_acq(short volatile *_Target, short _Value);
3920b57cec5SDimitry Andric short _InterlockedExchange16_nf(short volatile *_Target, short _Value);
3930b57cec5SDimitry Andric short _InterlockedExchange16_rel(short volatile *_Target, short _Value);
3940b57cec5SDimitry Andric long _InterlockedExchange_acq(long volatile *_Target, long _Value);
3950b57cec5SDimitry Andric long _InterlockedExchange_nf(long volatile *_Target, long _Value);
3960b57cec5SDimitry Andric long _InterlockedExchange_rel(long volatile *_Target, long _Value);
3970b57cec5SDimitry Andric __int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
3980b57cec5SDimitry Andric __int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
3990b57cec5SDimitry Andric __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
4000b57cec5SDimitry Andric #endif
4010b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
4020b57cec5SDimitry Andric |* Interlocked Compare Exchange
4030b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4040b57cec5SDimitry Andric #if defined(__arm__) || defined(__aarch64__)
4050b57cec5SDimitry Andric char _InterlockedCompareExchange8_acq(char volatile *_Destination,
4060b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4070b57cec5SDimitry Andric char _InterlockedCompareExchange8_nf(char volatile *_Destination,
4080b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4090b57cec5SDimitry Andric char _InterlockedCompareExchange8_rel(char volatile *_Destination,
4100b57cec5SDimitry Andric                              char _Exchange, char _Comparand);
4110b57cec5SDimitry Andric short _InterlockedCompareExchange16_acq(short volatile *_Destination,
4120b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4130b57cec5SDimitry Andric short _InterlockedCompareExchange16_nf(short volatile *_Destination,
4140b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4150b57cec5SDimitry Andric short _InterlockedCompareExchange16_rel(short volatile *_Destination,
4160b57cec5SDimitry Andric                               short _Exchange, short _Comparand);
4170b57cec5SDimitry Andric long _InterlockedCompareExchange_acq(long volatile *_Destination,
4180b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4190b57cec5SDimitry Andric long _InterlockedCompareExchange_nf(long volatile *_Destination,
4200b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4210b57cec5SDimitry Andric long _InterlockedCompareExchange_rel(long volatile *_Destination,
4220b57cec5SDimitry Andric                               long _Exchange, long _Comparand);
4230b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
4240b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4250b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
4260b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4270b57cec5SDimitry Andric __int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
4280b57cec5SDimitry Andric                               __int64 _Exchange, __int64 _Comparand);
4290b57cec5SDimitry Andric #endif
4300b57cec5SDimitry Andric 
4310b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
4320b57cec5SDimitry Andric |* movs, stos
4330b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4340b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
435*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
436*927c847dSDimitry Andric                                                   unsigned char const *__src,
437*927c847dSDimitry Andric                                                   size_t __n) {
4380b57cec5SDimitry Andric   __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
4390b57cec5SDimitry Andric                        : : "memory");
4400b57cec5SDimitry Andric }
441*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
442*927c847dSDimitry Andric                                                   unsigned long const *__src,
443*927c847dSDimitry Andric                                                   size_t __n) {
444*927c847dSDimitry Andric   __asm__ __volatile__("rep movsl"
445*927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
446*927c847dSDimitry Andric                        :
4470b57cec5SDimitry Andric                        : "memory");
4480b57cec5SDimitry Andric }
449*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
450*927c847dSDimitry Andric                                                   unsigned short const *__src,
451*927c847dSDimitry Andric                                                   size_t __n) {
452*927c847dSDimitry Andric   __asm__ __volatile__("rep movsw"
453*927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
454*927c847dSDimitry Andric                        :
455*927c847dSDimitry Andric                        : "memory");
456*927c847dSDimitry Andric }
457*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
458*927c847dSDimitry Andric                                                   unsigned long __x,
459*927c847dSDimitry Andric                                                   size_t __n) {
460*927c847dSDimitry Andric   __asm__ __volatile__("rep stosl"
461*927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
462*927c847dSDimitry Andric                        : "a"(__x)
463*927c847dSDimitry Andric                        : "memory");
464*927c847dSDimitry Andric }
465*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
466*927c847dSDimitry Andric                                                   unsigned short __x,
467*927c847dSDimitry Andric                                                   size_t __n) {
468*927c847dSDimitry Andric   __asm__ __volatile__("rep stosw"
469*927c847dSDimitry Andric                        : "+D"(__dst), "+c"(__n)
470*927c847dSDimitry Andric                        : "a"(__x)
4710b57cec5SDimitry Andric                        : "memory");
4720b57cec5SDimitry Andric }
4730b57cec5SDimitry Andric #endif
4740b57cec5SDimitry Andric #ifdef __x86_64__
475*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __movsq(
476*927c847dSDimitry Andric     unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
477*927c847dSDimitry Andric   __asm__ __volatile__("rep movsq"
478*927c847dSDimitry Andric                        : "+D"(__dst), "+S"(__src), "+c"(__n)
479*927c847dSDimitry Andric                        :
480*927c847dSDimitry Andric                        : "memory");
4810b57cec5SDimitry Andric }
482*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
483*927c847dSDimitry Andric                                                   unsigned __int64 __x,
484*927c847dSDimitry Andric                                                   size_t __n) {
4850b57cec5SDimitry Andric   __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
4860b57cec5SDimitry Andric                        : "memory");
4870b57cec5SDimitry Andric }
4880b57cec5SDimitry Andric #endif
4890b57cec5SDimitry Andric 
4900b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
4910b57cec5SDimitry Andric |* Misc
4920b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
4930b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
494*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) {
495*927c847dSDimitry Andric   __asm__("cpuid"
496*927c847dSDimitry Andric           : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])
4970b57cec5SDimitry Andric           : "a"(__level), "c"(0));
4980b57cec5SDimitry Andric }
499*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level,
500*927c847dSDimitry Andric                                                     int __ecx) {
501*927c847dSDimitry Andric   __asm__("cpuid"
502*927c847dSDimitry Andric           : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])
5030b57cec5SDimitry Andric           : "a"(__level), "c"(__ecx));
5040b57cec5SDimitry Andric }
505*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
5060b57cec5SDimitry Andric   __asm__ volatile("hlt");
5070b57cec5SDimitry Andric }
5080b57cec5SDimitry Andric #endif
5090b57cec5SDimitry Andric 
5100b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
511*927c847dSDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
5120b57cec5SDimitry Andric   __asm__ volatile("nop");
5130b57cec5SDimitry Andric }
5140b57cec5SDimitry Andric #endif
5150b57cec5SDimitry Andric 
5160b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5170b57cec5SDimitry Andric |* MS AArch64 specific
5180b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5190b57cec5SDimitry Andric #if defined(__aarch64__)
5200b57cec5SDimitry Andric unsigned __int64 __getReg(int);
5210b57cec5SDimitry Andric long _InterlockedAdd(long volatile *Addend, long Value);
5220b57cec5SDimitry Andric __int64 _ReadStatusReg(int);
5230b57cec5SDimitry Andric void _WriteStatusReg(int, __int64);
5240b57cec5SDimitry Andric 
5250b57cec5SDimitry Andric unsigned short __cdecl _byteswap_ushort(unsigned short val);
5260b57cec5SDimitry Andric unsigned long __cdecl _byteswap_ulong (unsigned long val);
5270b57cec5SDimitry Andric unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
5280b57cec5SDimitry Andric #endif
5290b57cec5SDimitry Andric 
5300b57cec5SDimitry Andric /*----------------------------------------------------------------------------*\
5310b57cec5SDimitry Andric |* Privileged intrinsics
5320b57cec5SDimitry Andric \*----------------------------------------------------------------------------*/
5330b57cec5SDimitry Andric #if defined(__i386__) || defined(__x86_64__)
5340b57cec5SDimitry Andric static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
5350b57cec5SDimitry Andric __readmsr(unsigned long __register) {
5360b57cec5SDimitry Andric   // Loads the contents of a 64-bit model specific register (MSR) specified in
5370b57cec5SDimitry Andric   // the ECX register into registers EDX:EAX. The EDX register is loaded with
5380b57cec5SDimitry Andric   // the high-order 32 bits of the MSR and the EAX register is loaded with the
5390b57cec5SDimitry Andric   // low-order 32 bits. If less than 64 bits are implemented in the MSR being
5400b57cec5SDimitry Andric   // read, the values returned to EDX:EAX in unimplemented bit locations are
5410b57cec5SDimitry Andric   // undefined.
5420b57cec5SDimitry Andric   unsigned long __edx;
5430b57cec5SDimitry Andric   unsigned long __eax;
5440b57cec5SDimitry Andric   __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
5450b57cec5SDimitry Andric   return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
5460b57cec5SDimitry Andric }
547480093f4SDimitry Andric #endif
5480b57cec5SDimitry Andric 
549*927c847dSDimitry Andric static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
550480093f4SDimitry Andric   unsigned __LPTRINT_TYPE__ __cr3_val;
551480093f4SDimitry Andric   __asm__ __volatile__ ("mov %%cr3, %0" : "=r"(__cr3_val) : : "memory");
5520b57cec5SDimitry Andric   return __cr3_val;
5530b57cec5SDimitry Andric }
5540b57cec5SDimitry Andric 
5550b57cec5SDimitry Andric static __inline__ void __DEFAULT_FN_ATTRS
556480093f4SDimitry Andric __writecr3(unsigned __INTPTR_TYPE__ __cr3_val) {
557480093f4SDimitry Andric   __asm__ ("mov %0, %%cr3" : : "r"(__cr3_val) : "memory");
5580b57cec5SDimitry Andric }
5590b57cec5SDimitry Andric 
5600b57cec5SDimitry Andric #ifdef __cplusplus
5610b57cec5SDimitry Andric }
5620b57cec5SDimitry Andric #endif
5630b57cec5SDimitry Andric 
564480093f4SDimitry Andric #undef __LPTRINT_TYPE__
565480093f4SDimitry Andric 
5660b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS
5670b57cec5SDimitry Andric 
5680b57cec5SDimitry Andric #endif /* __INTRIN_H */
5690b57cec5SDimitry Andric #endif /* _MSC_VER */
570