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