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