2016-06-15 04:14:24 +08:00
|
|
|
/* ===-------- intrin.h ---------------------------------------------------===
|
2013-08-31 08:22:48 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*===-----------------------------------------------------------------------===
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Only include this if we're compiling for the windows platform. */
|
|
|
|
#ifndef _MSC_VER
|
2016-06-15 04:14:24 +08:00
|
|
|
#include_next <intrin.h>
|
2013-08-31 08:22:48 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
#ifndef __INTRIN_H
|
|
|
|
#define __INTRIN_H
|
|
|
|
|
|
|
|
/* First include the standard intrinsics. */
|
2014-06-26 00:48:40 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2013-08-31 08:22:48 +08:00
|
|
|
#include <x86intrin.h>
|
2014-06-26 00:48:40 +08:00
|
|
|
#endif
|
2013-08-31 08:22:48 +08:00
|
|
|
|
2014-01-29 07:01:59 +08:00
|
|
|
/* For the definition of jmp_buf. */
|
2014-07-09 02:34:46 +08:00
|
|
|
#if __STDC_HOSTED__
|
2014-01-29 07:01:59 +08:00
|
|
|
#include <setjmp.h>
|
2014-07-09 02:34:46 +08:00
|
|
|
#endif
|
2014-01-29 07:01:59 +08:00
|
|
|
|
2015-06-16 07:20:35 +08:00
|
|
|
/* Define the default attributes for the functions in this file. */
|
2015-06-30 21:36:19 +08:00
|
|
|
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
|
2015-06-16 07:20:35 +08:00
|
|
|
|
2013-09-19 06:24:01 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-07-08 13:46:04 +08:00
|
|
|
#if defined(__MMX__)
|
2013-08-31 08:22:48 +08:00
|
|
|
/* And the random ones that aren't in those files. */
|
|
|
|
__m64 _m_from_float(float);
|
|
|
|
float _m_to_float(__m64);
|
2014-07-08 13:46:04 +08:00
|
|
|
#endif
|
2013-08-31 08:22:48 +08:00
|
|
|
|
|
|
|
/* Other assorted instruction intrinsics. */
|
|
|
|
void __addfsbyte(unsigned long, unsigned char);
|
|
|
|
void __addfsdword(unsigned long, unsigned long);
|
|
|
|
void __addfsword(unsigned long, unsigned short);
|
|
|
|
void __code_seg(const char *);
|
2014-01-17 07:39:35 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __cpuid(int[4], int);
|
2014-02-01 03:44:55 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __cpuidex(int[4], int, int);
|
2013-09-19 06:24:01 +08:00
|
|
|
void __debugbreak(void);
|
2013-08-31 08:22:48 +08:00
|
|
|
__int64 __emul(int, int);
|
|
|
|
unsigned __int64 __emulu(unsigned int, unsigned int);
|
2013-09-19 06:24:01 +08:00
|
|
|
void __cdecl __fastfail(unsigned int);
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned int __getcallerseflags(void);
|
2014-01-29 06:55:01 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __halt(void);
|
|
|
|
unsigned char __inbyte(unsigned short);
|
|
|
|
void __inbytestring(unsigned short, unsigned char *, unsigned long);
|
|
|
|
void __incfsbyte(unsigned long);
|
|
|
|
void __incfsdword(unsigned long);
|
|
|
|
void __incfsword(unsigned long);
|
|
|
|
unsigned long __indword(unsigned short);
|
|
|
|
void __indwordstring(unsigned short, unsigned long *, unsigned long);
|
|
|
|
void __int2c(void);
|
|
|
|
void __invlpg(void *);
|
|
|
|
unsigned short __inword(unsigned short);
|
|
|
|
void __inwordstring(unsigned short, unsigned short *, unsigned long);
|
|
|
|
void __lidt(void *);
|
|
|
|
unsigned __int64 __ll_lshift(unsigned __int64, int);
|
|
|
|
__int64 __ll_rshift(__int64, int);
|
|
|
|
void __llwpcb(void *);
|
|
|
|
unsigned char __lwpins32(unsigned int, unsigned int, unsigned int);
|
|
|
|
void __lwpval32(unsigned int, unsigned int, unsigned int);
|
|
|
|
unsigned int __lzcnt(unsigned int);
|
|
|
|
unsigned short __lzcnt16(unsigned short);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __movsb(unsigned char *, unsigned char const *, size_t);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __movsd(unsigned long *, unsigned long const *, size_t);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __movsw(unsigned short *, unsigned short const *, size_t);
|
|
|
|
void __nop(void);
|
|
|
|
void __nvreg_restore_fence(void);
|
|
|
|
void __nvreg_save_fence(void);
|
|
|
|
void __outbyte(unsigned short, unsigned char);
|
|
|
|
void __outbytestring(unsigned short, unsigned char *, unsigned long);
|
|
|
|
void __outdword(unsigned short, unsigned long);
|
|
|
|
void __outdwordstring(unsigned short, unsigned long *, unsigned long);
|
|
|
|
void __outword(unsigned short, unsigned short);
|
|
|
|
void __outwordstring(unsigned short, unsigned short *, unsigned long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned int __popcnt(unsigned int);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned short __popcnt16(unsigned short);
|
|
|
|
unsigned long __readcr0(void);
|
|
|
|
unsigned long __readcr2(void);
|
2014-04-08 08:28:22 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned long __readcr3(void);
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned long __readcr4(void);
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned long __readcr8(void);
|
|
|
|
unsigned int __readdr(unsigned int);
|
2014-01-24 08:52:39 +08:00
|
|
|
#ifdef __i386__
|
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char __readfsbyte(unsigned long);
|
2014-01-24 08:52:39 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned long __readfsdword(unsigned long);
|
2014-01-24 08:52:39 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __readfsqword(unsigned long);
|
2014-01-24 08:52:39 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned short __readfsword(unsigned long);
|
2014-01-24 08:52:39 +08:00
|
|
|
#endif
|
2014-04-08 08:28:22 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __readmsr(unsigned long);
|
|
|
|
unsigned __int64 __readpmc(unsigned long);
|
|
|
|
unsigned long __segmentlimit(unsigned long);
|
|
|
|
void __sidt(void *);
|
|
|
|
void *__slwpcb(void);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __stosb(unsigned char *, unsigned char, size_t);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __stosd(unsigned long *, unsigned long, size_t);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __stosw(unsigned short *, unsigned short, size_t);
|
|
|
|
void __svm_clgi(void);
|
|
|
|
void __svm_invlpga(void *, int);
|
|
|
|
void __svm_skinit(int);
|
|
|
|
void __svm_stgi(void);
|
|
|
|
void __svm_vmload(size_t);
|
|
|
|
void __svm_vmrun(size_t);
|
|
|
|
void __svm_vmsave(size_t);
|
|
|
|
void __ud2(void);
|
|
|
|
unsigned __int64 __ull_rshift(unsigned __int64, int);
|
|
|
|
void __vmx_off(void);
|
|
|
|
void __vmx_vmptrst(unsigned __int64 *);
|
|
|
|
void __wbinvd(void);
|
|
|
|
void __writecr0(unsigned int);
|
2014-04-08 08:28:22 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __writecr3(unsigned int);
|
|
|
|
void __writecr4(unsigned int);
|
|
|
|
void __writecr8(unsigned int);
|
|
|
|
void __writedr(unsigned int, unsigned int);
|
|
|
|
void __writefsbyte(unsigned long, unsigned char);
|
|
|
|
void __writefsdword(unsigned long, unsigned long);
|
|
|
|
void __writefsqword(unsigned long, unsigned __int64);
|
|
|
|
void __writefsword(unsigned long, unsigned short);
|
|
|
|
void __writemsr(unsigned long, unsigned __int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void *_AddressOfReturnAddress(void);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittest(long const *, long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandcomplement(long *, long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandreset(long *, long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandset(long *, long);
|
|
|
|
unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
|
|
|
|
unsigned long __cdecl _byteswap_ulong(unsigned long);
|
|
|
|
unsigned short __cdecl _byteswap_ushort(unsigned short);
|
|
|
|
void __cdecl _disable(void);
|
|
|
|
void __cdecl _enable(void);
|
|
|
|
long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long _InterlockedAnd(long volatile *_Value, long _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedAnd16(short volatile *_Value, short _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedAnd8(char volatile *_Value, char _Mask);
|
|
|
|
unsigned char _interlockedbittestandreset(long volatile *, long);
|
2014-03-14 01:05:09 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _interlockedbittestandset(long volatile *, long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long __cdecl _InterlockedCompareExchange(long volatile *_Destination,
|
|
|
|
long _Exchange, long _Comparand);
|
|
|
|
long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long);
|
|
|
|
long _InterlockedCompareExchange_HLERelease(long volatile *, long, long);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedCompareExchange16(short volatile *_Destination,
|
|
|
|
short _Exchange, short _Comparand);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
__int64 _InterlockedCompareExchange64(__int64 volatile *_Destination,
|
|
|
|
__int64 _Exchange, __int64 _Comparand);
|
|
|
|
__int64 _InterlockedcompareExchange64_HLEAcquire(__int64 volatile *, __int64,
|
|
|
|
__int64);
|
|
|
|
__int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64,
|
|
|
|
__int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange,
|
|
|
|
char _Comparand);
|
|
|
|
void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
|
|
|
|
void *);
|
|
|
|
void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
|
|
|
|
void *);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long __cdecl _InterlockedDecrement(long volatile *_Addend);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedDecrement16(short volatile *_Addend);
|
2014-06-19 04:51:10 +08:00
|
|
|
long _InterlockedExchange(long volatile *_Target, long _Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedExchange16(short volatile *_Target, short _Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedExchange8(char volatile *_Target, char _Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long __cdecl _InterlockedExchangeAdd(long volatile *_Addend, long _Value);
|
|
|
|
long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
|
|
|
|
long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
short _InterlockedExchangeAdd16(short volatile *_Addend, short _Value);
|
|
|
|
__int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
|
|
|
|
__int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedExchangeAdd8(char volatile *_Addend, char _Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long __cdecl _InterlockedIncrement(long volatile *_Addend);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedIncrement16(short volatile *_Addend);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long _InterlockedOr(long volatile *_Value, long _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedOr16(short volatile *_Value, short _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedOr8(char volatile *_Value, char _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
long _InterlockedXor(long volatile *_Value, long _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
short _InterlockedXor16(short volatile *_Value, short _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedXor8(char volatile *_Value, char _Mask);
|
|
|
|
void __cdecl _invpcid(unsigned int, void *);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned long __cdecl _lrotl(unsigned long, int);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned long __cdecl _lrotr(unsigned long, int);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void _ReadBarrier(void);
|
2013-10-17 09:29:48 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void _ReadWriteBarrier(void);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void *_ReturnAddress(void);
|
|
|
|
unsigned int _rorx_u32(unsigned int, const unsigned int);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:27:38 +08:00
|
|
|
unsigned int __cdecl _rotl(unsigned int _Value, int _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned short _rotl16(unsigned short _Value, unsigned char _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __cdecl _rotl64(unsigned __int64 _Value, int _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _rotl8(unsigned char _Value, unsigned char _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned int __cdecl _rotr(unsigned int _Value, int _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned short _rotr16(unsigned short _Value, unsigned char _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __cdecl _rotr64(unsigned __int64 _Value, int _Shift);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _rotr8(unsigned char _Value, unsigned char _Shift);
|
|
|
|
int _sarx_i32(int, unsigned int);
|
2014-07-09 02:34:46 +08:00
|
|
|
#if __STDC_HOSTED__
|
2014-01-29 07:01:59 +08:00
|
|
|
int __cdecl _setjmp(jmp_buf);
|
2014-07-09 02:34:46 +08:00
|
|
|
#endif
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned int _shlx_u32(unsigned int, unsigned int);
|
|
|
|
unsigned int _shrx_u32(unsigned int, unsigned int);
|
|
|
|
void _Store_HLERelease(long volatile *, long);
|
|
|
|
void _Store64_HLERelease(__int64 volatile *, __int64);
|
|
|
|
void _StorePointer_HLERelease(void *volatile *, void *);
|
2013-10-17 09:29:48 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void _WriteBarrier(void);
|
|
|
|
unsigned __int32 xbegin(void);
|
|
|
|
void _xend(void);
|
2014-01-17 07:39:35 +08:00
|
|
|
static __inline__
|
2015-01-28 07:34:35 +08:00
|
|
|
#define _XCR_XFEATURE_ENABLED_MASK 0
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __cdecl _xgetbv(unsigned int);
|
|
|
|
void __cdecl _xsetbv(unsigned int, unsigned __int64);
|
|
|
|
|
|
|
|
/* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __addgsbyte(unsigned long, unsigned char);
|
|
|
|
void __addgsdword(unsigned long, unsigned long);
|
|
|
|
void __addgsqword(unsigned long, unsigned __int64);
|
|
|
|
void __addgsword(unsigned long, unsigned short);
|
2014-01-28 03:16:35 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __faststorefence(void);
|
|
|
|
void __incgsbyte(unsigned long);
|
|
|
|
void __incgsdword(unsigned long);
|
|
|
|
void __incgsqword(unsigned long);
|
|
|
|
void __incgsword(unsigned long);
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int);
|
|
|
|
void __lwpval64(unsigned __int64, unsigned int, unsigned int);
|
|
|
|
unsigned __int64 __lzcnt64(unsigned __int64);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
void __movsq(unsigned long long *, unsigned long long const *, size_t);
|
|
|
|
__int64 __mulh(__int64, __int64);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __popcnt64(unsigned __int64);
|
2014-03-13 05:09:05 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned char __readgsbyte(unsigned long);
|
2014-03-13 05:09:05 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned long __readgsdword(unsigned long);
|
2014-03-13 05:09:05 +08:00
|
|
|
static __inline__
|
|
|
|
unsigned __int64 __readgsqword(unsigned long);
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned short __readgsword(unsigned long);
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
|
|
|
|
unsigned __int64 _HighPart,
|
|
|
|
unsigned char _Shift);
|
|
|
|
unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
|
|
|
|
unsigned __int64 _HighPart,
|
|
|
|
unsigned char _Shift);
|
2014-03-13 06:00:32 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
void __stosq(unsigned __int64 *, unsigned __int64, size_t);
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned char __vmx_on(unsigned __int64 *);
|
|
|
|
unsigned char __vmx_vmclear(unsigned __int64 *);
|
|
|
|
unsigned char __vmx_vmlaunch(void);
|
|
|
|
unsigned char __vmx_vmptrld(unsigned __int64 *);
|
|
|
|
unsigned char __vmx_vmread(size_t, size_t *);
|
|
|
|
unsigned char __vmx_vmresume(void);
|
|
|
|
unsigned char __vmx_vmwrite(size_t, size_t);
|
|
|
|
void __writegsbyte(unsigned long, unsigned char);
|
|
|
|
void __writegsdword(unsigned long, unsigned long);
|
|
|
|
void __writegsqword(unsigned long, unsigned __int64);
|
|
|
|
void __writegsword(unsigned long, unsigned short);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittest64(__int64 const *, __int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandcomplement64(__int64 *, __int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandreset64(__int64 *, __int64);
|
2013-09-28 07:57:26 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _bittestandset64(__int64 *, __int64);
|
|
|
|
unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
|
|
|
|
long _InterlockedAnd_np(long volatile *_Value, long _Mask);
|
|
|
|
short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
|
|
|
|
__int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
|
|
|
|
char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
|
|
|
|
unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
|
2014-03-14 01:05:09 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
|
|
|
|
long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
|
|
|
|
long _Comparand);
|
|
|
|
unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
|
|
|
|
__int64 _ExchangeHigh,
|
|
|
|
__int64 _ExchangeLow,
|
|
|
|
__int64 *_CompareandResult);
|
|
|
|
unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
|
|
|
|
__int64 _ExchangeHigh,
|
|
|
|
__int64 _ExchangeLow,
|
|
|
|
__int64 *_ComparandResult);
|
|
|
|
short _InterlockedCompareExchange16_np(short volatile *_Destination,
|
|
|
|
short _Exchange, short _Comparand);
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64,
|
|
|
|
__int64);
|
|
|
|
__int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64,
|
|
|
|
__int64);
|
2013-08-31 08:22:48 +08:00
|
|
|
__int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
|
|
|
|
__int64 _Exchange, __int64 _Comparand);
|
2014-01-25 09:38:30 +08:00
|
|
|
void *_InterlockedCompareExchangePointer(void *volatile *_Destination,
|
|
|
|
void *_Exchange, void *_Comparand);
|
2013-08-31 08:22:48 +08:00
|
|
|
void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
|
|
|
|
void *_Exchange, void *_Comparand);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedDecrement64(__int64 volatile *_Addend);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
|
|
|
|
void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedIncrement64(__int64 volatile *_Addend);
|
2013-08-31 08:22:48 +08:00
|
|
|
long _InterlockedOr_np(long volatile *_Value, long _Mask);
|
|
|
|
short _InterlockedOr16_np(short volatile *_Value, short _Mask);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
|
2013-09-28 08:15:41 +08:00
|
|
|
__int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
|
2013-08-31 08:22:48 +08:00
|
|
|
char _InterlockedOr8_np(char volatile *_Value, char _Mask);
|
|
|
|
long _InterlockedXor_np(long volatile *_Value, long _Mask);
|
|
|
|
short _InterlockedXor16_np(short volatile *_Value, short _Mask);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
|
2013-08-31 08:22:48 +08:00
|
|
|
__int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
|
|
|
|
char _InterlockedXor8_np(char volatile *_Value, char _Mask);
|
2014-01-28 02:48:02 +08:00
|
|
|
static __inline__
|
2013-08-31 08:22:48 +08:00
|
|
|
__int64 _mul128(__int64 _Multiplier, __int64 _Multiplicand,
|
|
|
|
__int64 *_HighProduct);
|
|
|
|
unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
|
2014-01-24 20:13:47 +08:00
|
|
|
__int64 _sarx_i64(__int64, unsigned int);
|
2014-07-09 02:34:46 +08:00
|
|
|
#if __STDC_HOSTED__
|
|
|
|
int __cdecl _setjmpex(jmp_buf);
|
|
|
|
#endif
|
2014-01-24 20:13:47 +08:00
|
|
|
unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
|
2014-12-03 07:30:26 +08:00
|
|
|
unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
|
2014-12-03 07:30:24 +08:00
|
|
|
/*
|
|
|
|
* Multiply two 64-bit integers and obtain a 64-bit result.
|
|
|
|
* The low-half is returned directly and the high half is in an out parameter.
|
|
|
|
*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2014-12-03 07:30:24 +08:00
|
|
|
_umul128(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand,
|
|
|
|
unsigned __int64 *_HighProduct) {
|
|
|
|
unsigned __int128 _FullProduct =
|
|
|
|
(unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand;
|
2014-12-03 07:44:40 +08:00
|
|
|
*_HighProduct = _FullProduct >> 64;
|
|
|
|
return _FullProduct;
|
2014-12-03 07:30:24 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2014-12-04 07:36:14 +08:00
|
|
|
__umulh(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand) {
|
|
|
|
unsigned __int128 _FullProduct =
|
|
|
|
(unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand;
|
|
|
|
return _FullProduct >> 64;
|
|
|
|
}
|
2013-09-19 06:24:01 +08:00
|
|
|
|
2013-10-01 05:08:05 +08:00
|
|
|
#endif /* __x86_64__ */
|
2013-09-19 08:19:53 +08:00
|
|
|
|
2015-10-15 00:24:28 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Multiplication
|
|
|
|
\*----------------------------------------------------------------------------*/
|
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
|
|
|
__emul(int __in1, int __in2) {
|
|
|
|
return (__int64)__in1 * (__int64)__in2;
|
|
|
|
}
|
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
|
|
|
__emulu(unsigned int __in1, unsigned int __in2) {
|
|
|
|
return (unsigned __int64)__in1 * (unsigned __int64)__in2;
|
|
|
|
}
|
2013-09-28 07:57:26 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Bit Twiddling
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotl8(unsigned char _Value, unsigned char _Shift) {
|
|
|
|
_Shift &= 0x7;
|
|
|
|
return _Shift ? (_Value << _Shift) | (_Value >> (8 - _Shift)) : _Value;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotr8(unsigned char _Value, unsigned char _Shift) {
|
|
|
|
_Shift &= 0x7;
|
|
|
|
return _Shift ? (_Value >> _Shift) | (_Value << (8 - _Shift)) : _Value;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotl16(unsigned short _Value, unsigned char _Shift) {
|
|
|
|
_Shift &= 0xf;
|
|
|
|
return _Shift ? (_Value << _Shift) | (_Value >> (16 - _Shift)) : _Value;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotr16(unsigned short _Value, unsigned char _Shift) {
|
|
|
|
_Shift &= 0xf;
|
|
|
|
return _Shift ? (_Value >> _Shift) | (_Value << (16 - _Shift)) : _Value;
|
|
|
|
}
|
2015-08-25 19:42:31 +08:00
|
|
|
static __inline__ unsigned int __DEFAULT_FN_ATTRS
|
|
|
|
_rotl(unsigned int _Value, int _Shift) {
|
|
|
|
_Shift &= 0x1f;
|
|
|
|
return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value;
|
|
|
|
}
|
|
|
|
static __inline__ unsigned int __DEFAULT_FN_ATTRS
|
|
|
|
_rotr(unsigned int _Value, int _Shift) {
|
|
|
|
_Shift &= 0x1f;
|
|
|
|
return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value;
|
|
|
|
}
|
|
|
|
static __inline__ unsigned long __DEFAULT_FN_ATTRS
|
|
|
|
_lrotl(unsigned long _Value, int _Shift) {
|
|
|
|
_Shift &= 0x1f;
|
|
|
|
return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value;
|
|
|
|
}
|
|
|
|
static __inline__ unsigned long __DEFAULT_FN_ATTRS
|
|
|
|
_lrotr(unsigned long _Value, int _Shift) {
|
|
|
|
_Shift &= 0x1f;
|
|
|
|
return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value;
|
|
|
|
}
|
2013-09-28 07:57:26 +08:00
|
|
|
static
|
2015-06-30 21:36:19 +08:00
|
|
|
__inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotl64(unsigned __int64 _Value, int _Shift) {
|
|
|
|
_Shift &= 0x3f;
|
|
|
|
return _Shift ? (_Value << _Shift) | (_Value >> (64 - _Shift)) : _Value;
|
|
|
|
}
|
|
|
|
static
|
2015-06-30 21:36:19 +08:00
|
|
|
__inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_rotr64(unsigned __int64 _Value, int _Shift) {
|
|
|
|
_Shift &= 0x3f;
|
|
|
|
return _Shift ? (_Value >> _Shift) | (_Value << (64 - _Shift)) : _Value;
|
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Bit Counting and Testing
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_BitScanForward(unsigned long *_Index, unsigned long _Mask) {
|
|
|
|
if (!_Mask)
|
|
|
|
return 0;
|
|
|
|
*_Index = __builtin_ctzl(_Mask);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_BitScanReverse(unsigned long *_Index, unsigned long _Mask) {
|
|
|
|
if (!_Mask)
|
|
|
|
return 0;
|
|
|
|
*_Index = 31 - __builtin_clzl(_Mask);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned short __DEFAULT_FN_ATTRS
|
2015-07-13 10:53:23 +08:00
|
|
|
__popcnt16(unsigned short _Value) {
|
|
|
|
return __builtin_popcount((int)_Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned int __DEFAULT_FN_ATTRS
|
2015-07-13 10:53:23 +08:00
|
|
|
__popcnt(unsigned int _Value) {
|
|
|
|
return __builtin_popcount(_Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittest(long const *_BitBase, long _BitPos) {
|
|
|
|
return (*_BitBase >> _BitPos) & 1;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandcomplement(long *_BitBase, long _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase ^ (1 << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandreset(long *_BitBase, long _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase & ~(1 << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandset(long *_BitBase, long _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase | (1 << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_interlockedbittestandset(long volatile *_BitBase, long _BitPos) {
|
2015-07-14 07:39:37 +08:00
|
|
|
long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST);
|
|
|
|
return (_PrevVal >> _BitPos) & 1;
|
2014-03-14 01:05:09 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) {
|
|
|
|
if (!_Mask)
|
|
|
|
return 0;
|
|
|
|
*_Index = __builtin_ctzll(_Mask);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) {
|
|
|
|
if (!_Mask)
|
|
|
|
return 0;
|
|
|
|
*_Index = 63 - __builtin_clzll(_Mask);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static __inline__
|
2015-06-30 21:36:19 +08:00
|
|
|
unsigned __int64 __DEFAULT_FN_ATTRS
|
2015-07-13 10:53:23 +08:00
|
|
|
__popcnt64(unsigned __int64 _Value) {
|
|
|
|
return __builtin_popcountll(_Value);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittest64(__int64 const *_BitBase, __int64 _BitPos) {
|
|
|
|
return (*_BitBase >> _BitPos) & 1;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandcomplement64(__int64 *_BitBase, __int64 _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase ^ (1ll << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandreset64(__int64 *_BitBase, __int64 _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase & ~(1ll << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_bittestandset64(__int64 *_BitBase, __int64 _BitPos) {
|
|
|
|
unsigned char _Res = (*_BitBase >> _BitPos) & 1;
|
|
|
|
*_BitBase = *_BitBase | (1ll << _BitPos);
|
|
|
|
return _Res;
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2015-07-14 07:38:56 +08:00
|
|
|
_interlockedbittestandset64(__int64 volatile *_BitBase, __int64 _BitPos) {
|
2015-07-14 07:39:37 +08:00
|
|
|
long long _PrevVal =
|
|
|
|
__atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST);
|
|
|
|
return (_PrevVal >> _BitPos) & 1;
|
2014-03-14 01:05:09 +08:00
|
|
|
}
|
2013-09-28 07:57:26 +08:00
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Exchange Add
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeAdd8(char volatile *_Addend, char _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeAdd16(short volatile *_Addend, short _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Exchange Sub
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeSub8(char volatile *_Subend, char _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeSub16(short volatile *_Subend, short _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ long __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeSub(long volatile *_Subend, long _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Increment
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2014-01-24 03:15:39 +08:00
|
|
|
_InterlockedIncrement16(short volatile *_Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedIncrement64(__int64 volatile *_Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Decrement
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2014-01-24 03:15:39 +08:00
|
|
|
_InterlockedDecrement16(short volatile *_Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedDecrement64(__int64 volatile *_Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked And
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedAnd8(char volatile *_Value, char _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedAnd16(short volatile *_Value, short _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ long __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedAnd(long volatile *_Value, long _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Or
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedOr8(char volatile *_Value, char _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedOr16(short volatile *_Value, short _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ long __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedOr(long volatile *_Value, long _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Xor
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedXor8(char volatile *_Value, char _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedXor16(short volatile *_Value, short _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ long __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedXor(long volatile *_Value, long _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) {
|
2015-07-14 07:39:37 +08:00
|
|
|
return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Exchange
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchange8(char volatile *_Target, char _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Value;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchange16(short volatile *_Target, short _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Value;
|
|
|
|
}
|
2013-10-01 05:08:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Value;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Interlocked Compare Exchange
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ char __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedCompareExchange8(char volatile *_Destination,
|
|
|
|
char _Exchange, char _Comparand) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
|
|
|
|
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Comparand;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ short __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedCompareExchange16(short volatile *_Destination,
|
|
|
|
short _Exchange, short _Comparand) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
|
|
|
|
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Comparand;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ __int64 __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_InterlockedCompareExchange64(__int64 volatile *_Destination,
|
|
|
|
__int64 _Exchange, __int64 _Comparand) {
|
2015-07-14 07:39:37 +08:00
|
|
|
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
|
|
|
|
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
2013-09-28 07:57:26 +08:00
|
|
|
return _Comparand;
|
|
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*\
|
2013-10-17 09:29:48 +08:00
|
|
|
|* Barriers
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
2013-10-17 09:29:48 +08:00
|
|
|
_ReadWriteBarrier(void) {
|
2015-07-16 11:13:02 +08:00
|
|
|
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
2013-10-17 09:29:48 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
2013-10-17 09:29:48 +08:00
|
|
|
_ReadBarrier(void) {
|
2015-07-16 11:13:02 +08:00
|
|
|
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
2013-10-17 09:29:48 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
2013-10-17 09:29:48 +08:00
|
|
|
_WriteBarrier(void) {
|
2015-07-16 11:13:02 +08:00
|
|
|
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
2013-10-17 09:29:48 +08:00
|
|
|
}
|
2014-01-28 03:16:35 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-01-28 03:16:35 +08:00
|
|
|
__faststorefence(void) {
|
2015-07-16 11:13:02 +08:00
|
|
|
__atomic_thread_fence(__ATOMIC_SEQ_CST);
|
2014-01-28 03:16:35 +08:00
|
|
|
}
|
|
|
|
#endif
|
2013-10-17 09:29:48 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
2014-03-13 05:09:05 +08:00
|
|
|
|* readfs, readgs
|
|
|
|
|* (Pointers in address space #256 and #257 are relative to the GS and FS
|
|
|
|
|* segment registers, respectively.)
|
2014-01-24 08:52:39 +08:00
|
|
|
\*----------------------------------------------------------------------------*/
|
|
|
|
#define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \
|
|
|
|
((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \
|
|
|
|
(__offset))
|
|
|
|
|
2014-03-13 05:09:05 +08:00
|
|
|
#ifdef __i386__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2014-01-24 08:52:39 +08:00
|
|
|
__readfsbyte(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(257, unsigned char, __offset);
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned short __DEFAULT_FN_ATTRS
|
2014-01-24 08:52:39 +08:00
|
|
|
__readfsword(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(257, unsigned short, __offset);
|
|
|
|
}
|
2016-05-27 10:06:14 +08:00
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
|
|
|
__readfsqword(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(257, unsigned __int64, __offset);
|
|
|
|
}
|
2014-01-24 08:52:39 +08:00
|
|
|
#endif
|
2014-03-13 05:09:05 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned char __DEFAULT_FN_ATTRS
|
2014-03-13 05:09:05 +08:00
|
|
|
__readgsbyte(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(256, unsigned char, __offset);
|
|
|
|
}
|
2016-05-27 10:06:14 +08:00
|
|
|
static __inline__ unsigned short __DEFAULT_FN_ATTRS
|
|
|
|
__readgsword(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(256, unsigned short, __offset);
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned long __DEFAULT_FN_ATTRS
|
2014-03-13 05:09:05 +08:00
|
|
|
__readgsdword(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(256, unsigned long, __offset);
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2014-03-13 05:09:05 +08:00
|
|
|
__readgsqword(unsigned long __offset) {
|
|
|
|
return *__ptr_to_addr_space(256, unsigned __int64, __offset);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#undef __ptr_to_addr_space
|
2014-03-13 06:00:32 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* movs, stos
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2014-06-26 00:48:40 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
|
|
|
|
__asm__("rep movsb" : : "D"(__dst), "S"(__src), "c"(__n)
|
|
|
|
: "%edi", "%esi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
|
|
|
|
__asm__("rep movsl" : : "D"(__dst), "S"(__src), "c"(__n)
|
|
|
|
: "%edi", "%esi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
|
2015-09-22 08:46:21 +08:00
|
|
|
__asm__("rep movsw" : : "D"(__dst), "S"(__src), "c"(__n)
|
2014-03-13 06:00:32 +08:00
|
|
|
: "%edi", "%esi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__stosb(unsigned char *__dst, unsigned char __x, size_t __n) {
|
|
|
|
__asm__("rep stosb" : : "D"(__dst), "a"(__x), "c"(__n)
|
|
|
|
: "%edi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
|
|
|
|
__asm__("rep stosl" : : "D"(__dst), "a"(__x), "c"(__n)
|
|
|
|
: "%edi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
|
2015-09-22 08:46:21 +08:00
|
|
|
__asm__("rep stosw" : : "D"(__dst), "a"(__x), "c"(__n)
|
2014-03-13 06:00:32 +08:00
|
|
|
: "%edi", "%ecx");
|
|
|
|
}
|
2014-06-26 00:48:40 +08:00
|
|
|
#endif
|
2014-03-13 06:00:32 +08:00
|
|
|
#ifdef __x86_64__
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
|
|
|
|
__asm__("rep movsq" : : "D"(__dst), "S"(__src), "c"(__n)
|
|
|
|
: "%edi", "%esi", "%ecx");
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-03-13 06:00:32 +08:00
|
|
|
__stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
|
|
|
|
__asm__("rep stosq" : : "D"(__dst), "a"(__x), "c"(__n)
|
|
|
|
: "%edi", "%ecx");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-24 08:52:39 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
2013-09-28 07:57:26 +08:00
|
|
|
|* Misc
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void * __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_AddressOfReturnAddress(void) {
|
|
|
|
return (void*)((char*)__builtin_frame_address(0) + sizeof(void*));
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void * __DEFAULT_FN_ATTRS
|
2013-09-28 07:57:26 +08:00
|
|
|
_ReturnAddress(void) {
|
|
|
|
return __builtin_return_address(0);
|
|
|
|
}
|
2014-06-26 00:48:40 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-01-17 07:39:35 +08:00
|
|
|
__cpuid(int __info[4], int __level) {
|
|
|
|
__asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
|
2014-02-01 03:44:55 +08:00
|
|
|
: "a"(__level));
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-02-01 03:44:55 +08:00
|
|
|
__cpuidex(int __info[4], int __level, int __ecx) {
|
|
|
|
__asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
|
|
|
|
: "a"(__level), "c"(__ecx));
|
2014-01-17 07:39:35 +08:00
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS
|
2014-01-17 07:39:35 +08:00
|
|
|
_xgetbv(unsigned int __xcr_no) {
|
|
|
|
unsigned int __eax, __edx;
|
|
|
|
__asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
|
|
|
|
return ((unsigned __int64)__edx << 32) | __eax;
|
|
|
|
}
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-01-29 06:55:01 +08:00
|
|
|
__halt(void) {
|
|
|
|
__asm__ volatile ("hlt");
|
|
|
|
}
|
2014-06-26 00:48:40 +08:00
|
|
|
#endif
|
2013-09-28 07:57:26 +08:00
|
|
|
|
2014-04-08 08:28:22 +08:00
|
|
|
/*----------------------------------------------------------------------------*\
|
|
|
|
|* Privileged intrinsics
|
|
|
|
\*----------------------------------------------------------------------------*/
|
2014-06-26 00:48:40 +08:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
|
2014-04-08 08:28:22 +08:00
|
|
|
__readmsr(unsigned long __register) {
|
|
|
|
// Loads the contents of a 64-bit model specific register (MSR) specified in
|
|
|
|
// the ECX register into registers EDX:EAX. The EDX register is loaded with
|
|
|
|
// the high-order 32 bits of the MSR and the EAX register is loaded with the
|
|
|
|
// low-order 32 bits. If less than 64 bits are implemented in the MSR being
|
|
|
|
// read, the values returned to EDX:EAX in unimplemented bit locations are
|
|
|
|
// undefined.
|
|
|
|
unsigned long __edx;
|
|
|
|
unsigned long __eax;
|
2014-04-09 01:49:16 +08:00
|
|
|
__asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
|
2014-04-08 08:28:22 +08:00
|
|
|
return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
|
|
|
|
}
|
|
|
|
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ unsigned long __DEFAULT_FN_ATTRS
|
2014-04-08 08:28:22 +08:00
|
|
|
__readcr3(void) {
|
2014-04-09 01:49:16 +08:00
|
|
|
unsigned long __cr3_val;
|
|
|
|
__asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory");
|
|
|
|
return __cr3_val;
|
2014-04-08 08:28:22 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 21:36:19 +08:00
|
|
|
static __inline__ void __DEFAULT_FN_ATTRS
|
2014-04-09 01:49:16 +08:00
|
|
|
__writecr3(unsigned int __cr3_val) {
|
|
|
|
__asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory");
|
2014-04-08 08:28:22 +08:00
|
|
|
}
|
2014-06-26 00:48:40 +08:00
|
|
|
#endif
|
2014-04-08 08:28:22 +08:00
|
|
|
|
2013-09-19 06:40:18 +08:00
|
|
|
#ifdef __cplusplus
|
2013-09-19 06:24:01 +08:00
|
|
|
}
|
2013-08-31 08:22:48 +08:00
|
|
|
#endif
|
2013-09-19 08:19:53 +08:00
|
|
|
|
2015-06-30 21:36:19 +08:00
|
|
|
#undef __DEFAULT_FN_ATTRS
|
2015-06-16 07:20:35 +08:00
|
|
|
|
2013-09-19 08:19:53 +08:00
|
|
|
#endif /* __INTRIN_H */
|
|
|
|
#endif /* _MSC_VER */
|