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 | |
Reid Kleckner | 9b8dceb | 2014-01-27 19:14:09 +0000 | [diff] [blame] | 35 | #include <setjmp.h> |
| 36 | |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 37 | #ifdef __cplusplus |
| 38 | extern "C" { |
| 39 | #endif |
| 40 | |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 41 | /* And the random ones that aren't in those files. */ |
| 42 | __m64 _m_from_float(float); |
| 43 | __m64 _m_from_int(int _l); |
| 44 | void _m_prefetch(void *); |
| 45 | float _m_to_float(__m64); |
| 46 | int _m_to_int(__m64 _M); |
| 47 | |
| 48 | /* Other assorted instruction intrinsics. */ |
| 49 | void __addfsbyte(unsigned long, unsigned char); |
| 50 | void __addfsdword(unsigned long, unsigned long); |
| 51 | void __addfsword(unsigned long, unsigned short); |
| 52 | void __code_seg(const char *); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 53 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 54 | void __cpuid(int[4], int); |
| 55 | void __cpuidex(int[4], int, int); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 56 | void __debugbreak(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 57 | __int64 __emul(int, int); |
| 58 | unsigned __int64 __emulu(unsigned int, unsigned int); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 59 | void __cdecl __fastfail(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 60 | unsigned int __getcallerseflags(void); |
| 61 | void __halt(void); |
| 62 | unsigned char __inbyte(unsigned short); |
| 63 | void __inbytestring(unsigned short, unsigned char *, unsigned long); |
| 64 | void __incfsbyte(unsigned long); |
| 65 | void __incfsdword(unsigned long); |
| 66 | void __incfsword(unsigned long); |
| 67 | unsigned long __indword(unsigned short); |
| 68 | void __indwordstring(unsigned short, unsigned long *, unsigned long); |
| 69 | void __int2c(void); |
| 70 | void __invlpg(void *); |
| 71 | unsigned short __inword(unsigned short); |
| 72 | void __inwordstring(unsigned short, unsigned short *, unsigned long); |
| 73 | void __lidt(void *); |
| 74 | unsigned __int64 __ll_lshift(unsigned __int64, int); |
| 75 | __int64 __ll_rshift(__int64, int); |
| 76 | void __llwpcb(void *); |
| 77 | unsigned char __lwpins32(unsigned int, unsigned int, unsigned int); |
| 78 | void __lwpval32(unsigned int, unsigned int, unsigned int); |
| 79 | unsigned int __lzcnt(unsigned int); |
| 80 | unsigned short __lzcnt16(unsigned short); |
| 81 | void __movsb(unsigned char *, unsigned char const *, size_t); |
| 82 | void __movsd(unsigned long *, unsigned long const *, size_t); |
| 83 | void __movsw(unsigned short *, unsigned short const *, size_t); |
| 84 | void __nop(void); |
| 85 | void __nvreg_restore_fence(void); |
| 86 | void __nvreg_save_fence(void); |
| 87 | void __outbyte(unsigned short, unsigned char); |
| 88 | void __outbytestring(unsigned short, unsigned char *, unsigned long); |
| 89 | void __outdword(unsigned short, unsigned long); |
| 90 | void __outdwordstring(unsigned short, unsigned long *, unsigned long); |
| 91 | void __outword(unsigned short, unsigned short); |
| 92 | void __outwordstring(unsigned short, unsigned short *, unsigned long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 93 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 94 | unsigned int __popcnt(unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 95 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 96 | unsigned short __popcnt16(unsigned short); |
| 97 | unsigned __int64 __rdtsc(void); |
| 98 | unsigned __int64 __rdtscp(unsigned int *); |
| 99 | unsigned long __readcr0(void); |
| 100 | unsigned long __readcr2(void); |
| 101 | unsigned long __readcr3(void); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 102 | unsigned long __readcr4(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 103 | unsigned long __readcr8(void); |
| 104 | unsigned int __readdr(unsigned int); |
| 105 | unsigned int __readeflags(void); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 106 | #ifdef __i386__ |
| 107 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 108 | unsigned char __readfsbyte(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 109 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 110 | unsigned long __readfsdword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 111 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 112 | unsigned __int64 __readfsqword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 113 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 114 | unsigned short __readfsword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 115 | #endif |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 116 | unsigned __int64 __readmsr(unsigned long); |
| 117 | unsigned __int64 __readpmc(unsigned long); |
| 118 | unsigned long __segmentlimit(unsigned long); |
| 119 | void __sidt(void *); |
| 120 | void *__slwpcb(void); |
| 121 | void __stosb(unsigned char *, unsigned char, size_t); |
| 122 | void __stosd(unsigned long *, unsigned long, size_t); |
| 123 | void __stosw(unsigned short *, unsigned short, size_t); |
| 124 | void __svm_clgi(void); |
| 125 | void __svm_invlpga(void *, int); |
| 126 | void __svm_skinit(int); |
| 127 | void __svm_stgi(void); |
| 128 | void __svm_vmload(size_t); |
| 129 | void __svm_vmrun(size_t); |
| 130 | void __svm_vmsave(size_t); |
| 131 | void __ud2(void); |
| 132 | unsigned __int64 __ull_rshift(unsigned __int64, int); |
| 133 | void __vmx_off(void); |
| 134 | void __vmx_vmptrst(unsigned __int64 *); |
| 135 | void __wbinvd(void); |
| 136 | void __writecr0(unsigned int); |
| 137 | void __writecr3(unsigned int); |
| 138 | void __writecr4(unsigned int); |
| 139 | void __writecr8(unsigned int); |
| 140 | void __writedr(unsigned int, unsigned int); |
| 141 | void __writeeflags(unsigned int); |
| 142 | void __writefsbyte(unsigned long, unsigned char); |
| 143 | void __writefsdword(unsigned long, unsigned long); |
| 144 | void __writefsqword(unsigned long, unsigned __int64); |
| 145 | void __writefsword(unsigned long, unsigned short); |
| 146 | void __writemsr(unsigned long, unsigned __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 147 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 148 | void *_AddressOfReturnAddress(void); |
| 149 | unsigned int _andn_u32(unsigned int, unsigned int); |
| 150 | unsigned int _bextr_u32(unsigned int, unsigned int, unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 151 | unsigned int _bextri_u32(unsigned int, unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 152 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 153 | unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 154 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 155 | unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 156 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 157 | unsigned char _bittest(long const *, long); |
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 | unsigned char _bittestandcomplement(long *, long); |
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 _bittestandreset(long *, long); |
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 _bittestandset(long *, long); |
| 164 | unsigned int _blcfill_u32(unsigned int); |
| 165 | unsigned int _blci_u32(unsigned int); |
| 166 | unsigned int _blcic_u32(unsigned int); |
| 167 | unsigned int _blcmsk_u32(unsigned int); |
| 168 | unsigned int _blcs_u32(unsigned int); |
| 169 | unsigned int _blsfill_u32(unsigned int); |
| 170 | unsigned int _blsi_u32(unsigned int); |
| 171 | unsigned int _blsic_u32(unsigned int); |
| 172 | unsigned int _blsmsk_u32(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 173 | unsigned int _blsr_u32(unsigned int); |
| 174 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
| 175 | unsigned long __cdecl _byteswap_ulong(unsigned long); |
| 176 | unsigned short __cdecl _byteswap_ushort(unsigned short); |
| 177 | unsigned _bzhi_u32(unsigned int, unsigned int); |
| 178 | void __cdecl _disable(void); |
| 179 | void __cdecl _enable(void); |
| 180 | void __cdecl _fxrstor(void const *); |
| 181 | void __cdecl _fxsave(void *); |
| 182 | long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 183 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 184 | long _InterlockedAnd(long volatile *_Value, long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 185 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 186 | short _InterlockedAnd16(short volatile *_Value, short _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 187 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 188 | char _InterlockedAnd8(char volatile *_Value, char _Mask); |
| 189 | unsigned char _interlockedbittestandreset(long volatile *, long); |
| 190 | unsigned char _interlockedbittestandset(long volatile *, long); |
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 __cdecl _InterlockedCompareExchange(long volatile *_Destination, |
| 193 | long _Exchange, long _Comparand); |
| 194 | long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long); |
| 195 | long _InterlockedCompareExchange_HLERelease(long volatile *, long, long); |
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 _InterlockedCompareExchange16(short volatile *_Destination, |
| 198 | short _Exchange, short _Comparand); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 199 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 200 | __int64 _InterlockedCompareExchange64(__int64 volatile *_Destination, |
| 201 | __int64 _Exchange, __int64 _Comparand); |
| 202 | __int64 _InterlockedcompareExchange64_HLEAcquire(__int64 volatile *, __int64, |
| 203 | __int64); |
| 204 | __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, |
| 205 | __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 206 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 207 | char _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange, |
| 208 | char _Comparand); |
| 209 | void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *, |
| 210 | void *); |
| 211 | void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *, |
| 212 | void *); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 213 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 214 | long __cdecl _InterlockedDecrement(long volatile *_Addend); |
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 | short _InterlockedDecrement16(short volatile *_Addend); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 217 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 218 | long __cdecl _InterlockedExchange(long volatile *_Target, long _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 219 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 220 | short _InterlockedExchange16(short volatile *_Target, short _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 221 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 222 | char _InterlockedExchange8(char volatile *_Target, char _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 223 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 224 | long __cdecl _InterlockedExchangeAdd(long volatile *_Addend, long _Value); |
| 225 | long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long); |
| 226 | long _InterlockedExchangeAdd_HLERelease(long volatile *, long); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 227 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 228 | short _InterlockedExchangeAdd16(short volatile *_Addend, short _Value); |
| 229 | __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64); |
| 230 | __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64); |
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 | char _InterlockedExchangeAdd8(char volatile *_Addend, char _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 | long __cdecl _InterlockedIncrement(long volatile *_Addend); |
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 | short _InterlockedIncrement16(short volatile *_Addend); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 237 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 238 | long _InterlockedOr(long volatile *_Value, long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 239 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 240 | short _InterlockedOr16(short volatile *_Value, short _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 241 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 242 | char _InterlockedOr8(char volatile *_Value, char _Mask); |
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 | long _InterlockedXor(long volatile *_Value, long _Mask); |
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 | short _InterlockedXor16(short volatile *_Value, short _Mask); |
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 | char _InterlockedXor8(char volatile *_Value, char _Mask); |
| 249 | void __cdecl _invpcid(unsigned int, void *); |
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 | unsigned long __cdecl _lrotl(unsigned long, int); |
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 | unsigned long __cdecl _lrotr(unsigned long, int); |
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 | unsigned int _lzcnt_u32(unsigned int); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 256 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 257 | void _ReadBarrier(void); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 258 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 259 | void _ReadWriteBarrier(void); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 260 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 261 | void *_ReturnAddress(void); |
| 262 | unsigned int _rorx_u32(unsigned int, const unsigned int); |
| 263 | int __cdecl _rdrand16_step(unsigned short *); |
| 264 | int __cdecl _rdrand32_step(unsigned int *); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 265 | static __inline__ |
Eric Christopher | fb4b433 | 2013-08-31 00:27:38 +0000 | [diff] [blame] | 266 | unsigned int __cdecl _rotl(unsigned int _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 267 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 268 | unsigned short _rotl16(unsigned short _Value, unsigned char _Shift); |
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 | unsigned __int64 __cdecl _rotl64(unsigned __int64 _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 271 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 272 | unsigned char _rotl8(unsigned char _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 273 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 274 | unsigned int __cdecl _rotr(unsigned int _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 275 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 276 | unsigned short _rotr16(unsigned short _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 277 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 278 | unsigned __int64 __cdecl _rotr64(unsigned __int64 _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 char _rotr8(unsigned char _Value, unsigned char _Shift); |
| 281 | int _sarx_i32(int, unsigned int); |
Reid Kleckner | 9b8dceb | 2014-01-27 19:14:09 +0000 | [diff] [blame] | 282 | int __cdecl _setjmp(jmp_buf); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 283 | unsigned int _shlx_u32(unsigned int, unsigned int); |
| 284 | unsigned int _shrx_u32(unsigned int, unsigned int); |
| 285 | void _Store_HLERelease(long volatile *, long); |
| 286 | void _Store64_HLERelease(__int64 volatile *, __int64); |
| 287 | void _StorePointer_HLERelease(void *volatile *, void *); |
| 288 | unsigned int _t1mskc_u32(unsigned int); |
| 289 | unsigned int _tzcnt_u32(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 290 | unsigned int _tzmsk_u32(unsigned int); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 291 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 292 | void _WriteBarrier(void); |
| 293 | void _xabort(const unsigned int imm); |
| 294 | unsigned __int32 xbegin(void); |
| 295 | void _xend(void); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 296 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 297 | unsigned __int64 __cdecl _xgetbv(unsigned int); |
| 298 | void __cdecl _xrstor(void const *, unsigned __int64); |
| 299 | void __cdecl _xsave(void *, unsigned __int64); |
| 300 | void __cdecl _xsaveopt(void *, unsigned __int64); |
| 301 | void __cdecl _xsetbv(unsigned int, unsigned __int64); |
| 302 | unsigned char _xtest(void); |
| 303 | |
| 304 | /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */ |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 305 | #ifdef __x86_64__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 306 | void __addgsbyte(unsigned long, unsigned char); |
| 307 | void __addgsdword(unsigned long, unsigned long); |
| 308 | void __addgsqword(unsigned long, unsigned __int64); |
| 309 | void __addgsword(unsigned long, unsigned short); |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame^] | 310 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 311 | void __faststorefence(void); |
| 312 | void __incgsbyte(unsigned long); |
| 313 | void __incgsdword(unsigned long); |
| 314 | void __incgsqword(unsigned long); |
| 315 | void __incgsword(unsigned long); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 316 | unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int); |
| 317 | void __lwpval64(unsigned __int64, unsigned int, unsigned int); |
| 318 | unsigned __int64 __lzcnt64(unsigned __int64); |
| 319 | void __movsq(unsigned long long *, unsigned long long const *, size_t); |
| 320 | __int64 __mulh(__int64, __int64); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 321 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 322 | unsigned __int64 __popcnt64(unsigned __int64); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 323 | unsigned char __readgsbyte(unsigned long); |
| 324 | unsigned long __readgsdword(unsigned long); |
| 325 | unsigned short __readgsword(unsigned long); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 326 | unsigned __int64 __shiftleft128(unsigned __int64 _LowPart, |
| 327 | unsigned __int64 _HighPart, |
| 328 | unsigned char _Shift); |
| 329 | unsigned __int64 __shiftright128(unsigned __int64 _LowPart, |
| 330 | unsigned __int64 _HighPart, |
| 331 | unsigned char _Shift); |
| 332 | void __stosq(unsigned __int64 *, unsigned __int64, size_t); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 333 | unsigned __int64 __umulh(unsigned __int64, unsigned __int64); |
| 334 | unsigned char __vmx_on(unsigned __int64 *); |
| 335 | unsigned char __vmx_vmclear(unsigned __int64 *); |
| 336 | unsigned char __vmx_vmlaunch(void); |
| 337 | unsigned char __vmx_vmptrld(unsigned __int64 *); |
| 338 | unsigned char __vmx_vmread(size_t, size_t *); |
| 339 | unsigned char __vmx_vmresume(void); |
| 340 | unsigned char __vmx_vmwrite(size_t, size_t); |
| 341 | void __writegsbyte(unsigned long, unsigned char); |
| 342 | void __writegsdword(unsigned long, unsigned long); |
| 343 | void __writegsqword(unsigned long, unsigned __int64); |
| 344 | void __writegsword(unsigned long, unsigned short); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 345 | unsigned __int64 _andn_u64(unsigned __int64, unsigned __int64); |
| 346 | unsigned __int64 _bextr_u64(unsigned __int64, unsigned int, unsigned int); |
| 347 | unsigned __int64 _bextri_u64(unsigned __int64, unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 348 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 349 | unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 350 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 351 | unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 352 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 353 | unsigned char _bittest64(__int64 const *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 354 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 355 | unsigned char _bittestandcomplement64(__int64 *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 356 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 357 | unsigned char _bittestandreset64(__int64 *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 358 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 359 | unsigned char _bittestandset64(__int64 *, __int64); |
| 360 | unsigned __int64 _blcfill_u64(unsigned __int64); |
| 361 | unsigned __int64 _blci_u64(unsigned __int64); |
| 362 | unsigned __int64 _blcic_u64(unsigned __int64); |
| 363 | unsigned __int64 _blcmsk_u64(unsigned __int64); |
| 364 | unsigned __int64 _blcs_u64(unsigned __int64); |
| 365 | unsigned __int64 _blsfill_u64(unsigned __int64); |
| 366 | unsigned __int64 _blsi_u64(unsigned __int64); |
| 367 | unsigned __int64 _blsic_u64(unsigned __int64); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 368 | unsigned __int64 _blsmsk_u64(unsigned __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 369 | unsigned __int64 _blsr_u64(unsigned __int64); |
| 370 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
| 371 | unsigned __int64 _bzhi_u64(unsigned __int64, unsigned int); |
| 372 | void __cdecl _fxrstor64(void const *); |
| 373 | void __cdecl _fxsave64(void *); |
| 374 | long _InterlockedAnd_np(long volatile *_Value, long _Mask); |
| 375 | short _InterlockedAnd16_np(short volatile *_Value, short _Mask); |
| 376 | __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask); |
| 377 | char _InterlockedAnd8_np(char volatile *_Value, char _Mask); |
| 378 | unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64); |
| 379 | unsigned char _interlockedbittestandset64(__int64 volatile *, __int64); |
| 380 | long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange, |
| 381 | long _Comparand); |
| 382 | unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination, |
| 383 | __int64 _ExchangeHigh, |
| 384 | __int64 _ExchangeLow, |
| 385 | __int64 *_CompareandResult); |
| 386 | unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination, |
| 387 | __int64 _ExchangeHigh, |
| 388 | __int64 _ExchangeLow, |
| 389 | __int64 *_ComparandResult); |
| 390 | short _InterlockedCompareExchange16_np(short volatile *_Destination, |
| 391 | short _Exchange, short _Comparand); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 392 | __int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64, |
| 393 | __int64); |
| 394 | __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, |
| 395 | __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 396 | __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination, |
| 397 | __int64 _Exchange, __int64 _Comparand); |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame^] | 398 | static __inline__ |
Eric Christopher | 58b4043 | 2014-01-25 01:38:30 +0000 | [diff] [blame] | 399 | void *_InterlockedCompareExchangePointer(void *volatile *_Destination, |
| 400 | void *_Exchange, void *_Comparand); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 401 | void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination, |
| 402 | void *_Exchange, void *_Comparand); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 403 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 404 | __int64 _InterlockedDecrement64(__int64 volatile *_Addend); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 405 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 406 | __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 407 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 408 | __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value); |
| 409 | void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 410 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 411 | __int64 _InterlockedIncrement64(__int64 volatile *_Addend); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 412 | long _InterlockedOr_np(long volatile *_Value, long _Mask); |
| 413 | short _InterlockedOr16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 414 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 415 | __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask); |
Warren Hunt | 41a993f | 2013-09-28 00:15:41 +0000 | [diff] [blame] | 416 | __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 417 | char _InterlockedOr8_np(char volatile *_Value, char _Mask); |
| 418 | long _InterlockedXor_np(long volatile *_Value, long _Mask); |
| 419 | short _InterlockedXor16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 420 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 421 | __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 422 | __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask); |
| 423 | char _InterlockedXor8_np(char volatile *_Value, char _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 424 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 425 | unsigned __int64 _lzcnt_u64(unsigned __int64); |
| 426 | __int64 _mul128(__int64 _Multiplier, __int64 _Multiplicand, |
| 427 | __int64 *_HighProduct); |
| 428 | unsigned int __cdecl _readfsbase_u32(void); |
| 429 | unsigned __int64 __cdecl _readfsbase_u64(void); |
| 430 | unsigned int __cdecl _readgsbase_u32(void); |
| 431 | unsigned __int64 __cdecl _readgsbase_u64(void); |
| 432 | unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 433 | __int64 _sarx_i64(__int64, unsigned int); |
| 434 | int __cdecl _setjmpex(jmp_buf); |
| 435 | unsigned __int64 _shlx_u64(unsigned __int64, unsigned int); |
| 436 | unsigned __int64 shrx_u64(unsigned __int64, unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 437 | unsigned __int64 _tzcnt_u64(unsigned __int64); |
| 438 | unsigned __int64 _tzmsk_u64(unsigned __int64); |
| 439 | unsigned __int64 _umul128(unsigned __int64 _Multiplier, |
| 440 | unsigned __int64 _Multiplicand, |
| 441 | unsigned __int64 *_HighProduct); |
| 442 | void __cdecl _writefsbase_u32(unsigned int); |
| 443 | void _cdecl _writefsbase_u64(unsigned __int64); |
| 444 | void __cdecl _writegsbase_u32(unsigned int); |
| 445 | void __cdecl _writegsbase_u64(unsigned __int64); |
| 446 | void __cdecl _xrstor64(void const *, unsigned __int64); |
| 447 | void __cdecl _xsave64(void *, unsigned __int64); |
| 448 | void __cdecl _xsaveopt64(void *, unsigned __int64); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 449 | |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 450 | #endif /* __x86_64__ */ |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 451 | |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 452 | /*----------------------------------------------------------------------------*\ |
| 453 | |* Bit Twiddling |
| 454 | \*----------------------------------------------------------------------------*/ |
| 455 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 456 | _rotl8(unsigned char _Value, unsigned char _Shift) { |
| 457 | _Shift &= 0x7; |
| 458 | return _Shift ? (_Value << _Shift) | (_Value >> (8 - _Shift)) : _Value; |
| 459 | } |
| 460 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 461 | _rotr8(unsigned char _Value, unsigned char _Shift) { |
| 462 | _Shift &= 0x7; |
| 463 | return _Shift ? (_Value >> _Shift) | (_Value << (8 - _Shift)) : _Value; |
| 464 | } |
| 465 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
| 466 | _rotl16(unsigned short _Value, unsigned char _Shift) { |
| 467 | _Shift &= 0xf; |
| 468 | return _Shift ? (_Value << _Shift) | (_Value >> (16 - _Shift)) : _Value; |
| 469 | } |
| 470 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
| 471 | _rotr16(unsigned short _Value, unsigned char _Shift) { |
| 472 | _Shift &= 0xf; |
| 473 | return _Shift ? (_Value >> _Shift) | (_Value << (16 - _Shift)) : _Value; |
| 474 | } |
| 475 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 476 | _rotl(unsigned int _Value, int _Shift) { |
| 477 | _Shift &= 0x1f; |
| 478 | return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; |
| 479 | } |
| 480 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 481 | _rotr(unsigned int _Value, int _Shift) { |
| 482 | _Shift &= 0x1f; |
| 483 | return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; |
| 484 | } |
| 485 | static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__)) |
| 486 | _lrotl(unsigned long _Value, int _Shift) { |
| 487 | _Shift &= 0x1f; |
| 488 | return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; |
| 489 | } |
| 490 | static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__)) |
| 491 | _lrotr(unsigned long _Value, int _Shift) { |
| 492 | _Shift &= 0x1f; |
| 493 | return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; |
| 494 | } |
| 495 | static |
| 496 | __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__)) |
| 497 | _rotl64(unsigned __int64 _Value, int _Shift) { |
| 498 | _Shift &= 0x3f; |
| 499 | return _Shift ? (_Value << _Shift) | (_Value >> (64 - _Shift)) : _Value; |
| 500 | } |
| 501 | static |
| 502 | __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__)) |
| 503 | _rotr64(unsigned __int64 _Value, int _Shift) { |
| 504 | _Shift &= 0x3f; |
| 505 | return _Shift ? (_Value >> _Shift) | (_Value << (64 - _Shift)) : _Value; |
| 506 | } |
| 507 | /*----------------------------------------------------------------------------*\ |
| 508 | |* Bit Counting and Testing |
| 509 | \*----------------------------------------------------------------------------*/ |
| 510 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 511 | _BitScanForward(unsigned long *_Index, unsigned long _Mask) { |
| 512 | if (!_Mask) |
| 513 | return 0; |
| 514 | *_Index = __builtin_ctzl(_Mask); |
| 515 | return 1; |
| 516 | } |
| 517 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 518 | _BitScanReverse(unsigned long *_Index, unsigned long _Mask) { |
| 519 | if (!_Mask) |
| 520 | return 0; |
| 521 | *_Index = 31 - __builtin_clzl(_Mask); |
| 522 | return 1; |
| 523 | } |
| 524 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 525 | _lzcnt_u32(unsigned int a) { |
| 526 | if (!a) |
| 527 | return 32; |
| 528 | return __builtin_clzl(a); |
| 529 | } |
| 530 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
| 531 | __popcnt16(unsigned short value) { |
| 532 | return __builtin_popcount((int)value); |
| 533 | } |
| 534 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 535 | __popcnt(unsigned int value) { |
| 536 | return __builtin_popcount(value); |
| 537 | } |
| 538 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 539 | _bittest(long const *a, long b) { |
| 540 | return (*a >> b) & 1; |
| 541 | } |
| 542 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 543 | _bittestandcomplement(long *a, long b) { |
| 544 | unsigned char x = (*a >> b) & 1; |
| 545 | *a = *a ^ (1 << b); |
| 546 | return x; |
| 547 | } |
| 548 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 549 | _bittestandreset(long *a, long b) { |
| 550 | unsigned char x = (*a >> b) & 1; |
| 551 | *a = *a & ~(1 << b); |
| 552 | return x; |
| 553 | } |
| 554 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 555 | _bittestandset(long *a, long b) { |
| 556 | unsigned char x = (*a >> b) & 1; |
Warren Hunt | 2731e3e | 2013-10-01 17:12:40 +0000 | [diff] [blame] | 557 | *a = *a | (1 << b); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 558 | return x; |
| 559 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 560 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 561 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 562 | _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 563 | if (!_Mask) |
| 564 | return 0; |
| 565 | *_Index = __builtin_ctzll(_Mask); |
| 566 | return 1; |
| 567 | } |
| 568 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 569 | _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 570 | if (!_Mask) |
| 571 | return 0; |
| 572 | *_Index = 63 - __builtin_clzll(_Mask); |
| 573 | return 1; |
| 574 | } |
| 575 | static |
| 576 | __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__)) |
| 577 | _lzcnt_u64(unsigned __int64 a) { |
| 578 | if (!a) |
| 579 | return 64; |
| 580 | return __builtin_clzll(a); |
| 581 | } |
| 582 | static __inline__ |
| 583 | unsigned __int64 __attribute__((__always_inline__, __nodebug__)) |
| 584 | __popcnt64(unsigned __int64 value) { |
| 585 | return __builtin_popcountll(value); |
| 586 | } |
| 587 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 588 | _bittest64(__int64 const *a, __int64 b) { |
| 589 | return (*a >> b) & 1; |
| 590 | } |
| 591 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 592 | _bittestandcomplement64(__int64 *a, __int64 b) { |
| 593 | unsigned char x = (*a >> b) & 1; |
| 594 | *a = *a ^ (1ll << b); |
| 595 | return x; |
| 596 | } |
| 597 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 598 | _bittestandreset64(__int64 *a, __int64 b) { |
| 599 | unsigned char x = (*a >> b) & 1; |
| 600 | *a = *a & ~(1ll << b); |
| 601 | return x; |
| 602 | } |
| 603 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 604 | _bittestandset64(__int64 *a, __int64 b) { |
| 605 | unsigned char x = (*a >> b) & 1; |
Warren Hunt | 2731e3e | 2013-10-01 17:12:40 +0000 | [diff] [blame] | 606 | *a = *a | (1ll << b); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 607 | return x; |
| 608 | } |
| 609 | #endif |
| 610 | /*----------------------------------------------------------------------------*\ |
| 611 | |* Interlocked Exchange Add |
| 612 | \*----------------------------------------------------------------------------*/ |
| 613 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 614 | _InterlockedExchangeAdd8(char volatile *_Addend, char _Value) { |
| 615 | return __atomic_add_fetch(_Addend, _Value, 0) - _Value; |
| 616 | } |
| 617 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 618 | _InterlockedExchangeAdd16(short volatile *_Addend, short _Value) { |
| 619 | return __atomic_add_fetch(_Addend, _Value, 0) - _Value; |
| 620 | } |
| 621 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 622 | _InterlockedExchangeAdd(long volatile *_Addend, long _Value) { |
| 623 | return __atomic_add_fetch(_Addend, _Value, 0) - _Value; |
| 624 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 625 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 626 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 627 | _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) { |
| 628 | return __atomic_add_fetch(_Addend, _Value, 0) - _Value; |
| 629 | } |
| 630 | #endif |
| 631 | /*----------------------------------------------------------------------------*\ |
| 632 | |* Interlocked Exchange Sub |
| 633 | \*----------------------------------------------------------------------------*/ |
| 634 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 635 | _InterlockedExchangeSub8(char volatile *_Subend, char _Value) { |
| 636 | return __atomic_sub_fetch(_Subend, _Value, 0) + _Value; |
| 637 | } |
| 638 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 639 | _InterlockedExchangeSub16(short volatile *_Subend, short _Value) { |
| 640 | return __atomic_sub_fetch(_Subend, _Value, 0) + _Value; |
| 641 | } |
| 642 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 643 | _InterlockedExchangeSub(long volatile *_Subend, long _Value) { |
| 644 | return __atomic_sub_fetch(_Subend, _Value, 0) + _Value; |
| 645 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 646 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 647 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 648 | _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) { |
| 649 | return __atomic_sub_fetch(_Subend, _Value, 0) + _Value; |
| 650 | } |
| 651 | #endif |
| 652 | /*----------------------------------------------------------------------------*\ |
| 653 | |* Interlocked Increment |
| 654 | \*----------------------------------------------------------------------------*/ |
Hans Wennborg | 2ed8880 | 2014-01-23 19:15:39 +0000 | [diff] [blame] | 655 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 656 | _InterlockedIncrement16(short volatile *_Value) { |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 657 | return __atomic_add_fetch(_Value, 1, 0); |
| 658 | } |
| 659 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 660 | _InterlockedIncrement(long volatile *_Value) { |
| 661 | return __atomic_add_fetch(_Value, 1, 0); |
| 662 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 663 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 664 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 665 | _InterlockedIncrement64(__int64 volatile *_Value) { |
| 666 | return __atomic_add_fetch(_Value, 1, 0); |
| 667 | } |
| 668 | #endif |
| 669 | /*----------------------------------------------------------------------------*\ |
| 670 | |* Interlocked Decrement |
| 671 | \*----------------------------------------------------------------------------*/ |
Hans Wennborg | 2ed8880 | 2014-01-23 19:15:39 +0000 | [diff] [blame] | 672 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 673 | _InterlockedDecrement16(short volatile *_Value) { |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 674 | return __atomic_sub_fetch(_Value, 1, 0); |
| 675 | } |
| 676 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 677 | _InterlockedDecrement(long volatile *_Value) { |
| 678 | return __atomic_sub_fetch(_Value, 1, 0); |
| 679 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 680 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 681 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 682 | _InterlockedDecrement64(__int64 volatile *_Value) { |
| 683 | return __atomic_sub_fetch(_Value, 1, 0); |
| 684 | } |
| 685 | #endif |
| 686 | /*----------------------------------------------------------------------------*\ |
| 687 | |* Interlocked And |
| 688 | \*----------------------------------------------------------------------------*/ |
| 689 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 690 | _InterlockedAnd8(char volatile *_Value, char _Mask) { |
| 691 | return __atomic_and_fetch(_Value, _Mask, 0); |
| 692 | } |
| 693 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 694 | _InterlockedAnd16(short volatile *_Value, short _Mask) { |
| 695 | return __atomic_and_fetch(_Value, _Mask, 0); |
| 696 | } |
| 697 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 698 | _InterlockedAnd(long volatile *_Value, long _Mask) { |
| 699 | return __atomic_and_fetch(_Value, _Mask, 0); |
| 700 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 701 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 702 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 703 | _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) { |
| 704 | return __atomic_and_fetch(_Value, _Mask, 0); |
| 705 | } |
| 706 | #endif |
| 707 | /*----------------------------------------------------------------------------*\ |
| 708 | |* Interlocked Or |
| 709 | \*----------------------------------------------------------------------------*/ |
| 710 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 711 | _InterlockedOr8(char volatile *_Value, char _Mask) { |
| 712 | return __atomic_or_fetch(_Value, _Mask, 0); |
| 713 | } |
| 714 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 715 | _InterlockedOr16(short volatile *_Value, short _Mask) { |
| 716 | return __atomic_or_fetch(_Value, _Mask, 0); |
| 717 | } |
| 718 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 719 | _InterlockedOr(long volatile *_Value, long _Mask) { |
| 720 | return __atomic_or_fetch(_Value, _Mask, 0); |
| 721 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 722 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 723 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 724 | _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) { |
| 725 | return __atomic_or_fetch(_Value, _Mask, 0); |
| 726 | } |
| 727 | #endif |
| 728 | /*----------------------------------------------------------------------------*\ |
| 729 | |* Interlocked Xor |
| 730 | \*----------------------------------------------------------------------------*/ |
| 731 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 732 | _InterlockedXor8(char volatile *_Value, char _Mask) { |
| 733 | return __atomic_xor_fetch(_Value, _Mask, 0); |
| 734 | } |
| 735 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 736 | _InterlockedXor16(short volatile *_Value, short _Mask) { |
| 737 | return __atomic_xor_fetch(_Value, _Mask, 0); |
| 738 | } |
| 739 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 740 | _InterlockedXor(long volatile *_Value, long _Mask) { |
| 741 | return __atomic_xor_fetch(_Value, _Mask, 0); |
| 742 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 743 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 744 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 745 | _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) { |
| 746 | return __atomic_xor_fetch(_Value, _Mask, 0); |
| 747 | } |
| 748 | #endif |
| 749 | /*----------------------------------------------------------------------------*\ |
| 750 | |* Interlocked Exchange |
| 751 | \*----------------------------------------------------------------------------*/ |
| 752 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 753 | _InterlockedExchange8(char volatile *_Target, char _Value) { |
| 754 | __atomic_exchange(_Target, &_Value, &_Value, 0); |
| 755 | return _Value; |
| 756 | } |
| 757 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 758 | _InterlockedExchange16(short volatile *_Target, short _Value) { |
| 759 | __atomic_exchange(_Target, &_Value, &_Value, 0); |
| 760 | return _Value; |
| 761 | } |
| 762 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 763 | _InterlockedExchange(long volatile *_Target, long _Value) { |
| 764 | __atomic_exchange(_Target, &_Value, &_Value, 0); |
| 765 | return _Value; |
| 766 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 767 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 768 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 769 | _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) { |
| 770 | __atomic_exchange(_Target, &_Value, &_Value, 0); |
| 771 | return _Value; |
| 772 | } |
| 773 | #endif |
| 774 | /*----------------------------------------------------------------------------*\ |
| 775 | |* Interlocked Compare Exchange |
| 776 | \*----------------------------------------------------------------------------*/ |
| 777 | static __inline__ char __attribute__((__always_inline__, __nodebug__)) |
| 778 | _InterlockedCompareExchange8(char volatile *_Destination, |
| 779 | char _Exchange, char _Comparand) { |
| 780 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, 0, 0); |
| 781 | return _Comparand; |
| 782 | } |
| 783 | static __inline__ short __attribute__((__always_inline__, __nodebug__)) |
| 784 | _InterlockedCompareExchange16(short volatile *_Destination, |
| 785 | short _Exchange, short _Comparand) { |
| 786 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, 0, 0); |
| 787 | return _Comparand; |
| 788 | } |
| 789 | static __inline__ long __attribute__((__always_inline__, __nodebug__)) |
| 790 | _InterlockedCompareExchange(long volatile *_Destination, |
| 791 | long _Exchange, long _Comparand) { |
| 792 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, 0, 0); |
| 793 | return _Comparand; |
| 794 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 795 | #ifdef __x86_64__ |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame^] | 796 | static __inline__ void *__attribute__((__always_inline__, __nodebug__)) |
| 797 | _InterlockedCompareExchangePointer(void *volatile *_Destination, |
| 798 | void *_Exchange, void *_Comparand) { |
| 799 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, 0, 0); |
| 800 | return _Comparand; |
| 801 | } |
| 802 | #endif |
| 803 | #ifdef __x86_64__ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 804 | static __inline__ __int64 __attribute__((__always_inline__, __nodebug__)) |
| 805 | _InterlockedCompareExchange64(__int64 volatile *_Destination, |
| 806 | __int64 _Exchange, __int64 _Comparand) { |
| 807 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, 0, 0); |
| 808 | return _Comparand; |
| 809 | } |
| 810 | #endif |
| 811 | /*----------------------------------------------------------------------------*\ |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 812 | |* Barriers |
| 813 | \*----------------------------------------------------------------------------*/ |
| 814 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 815 | __attribute__((deprecated("use other intrinsics or C++11 atomics instead"))) |
| 816 | _ReadWriteBarrier(void) { |
| 817 | __asm__ volatile ("" : : : "memory"); |
| 818 | } |
| 819 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 820 | __attribute__((deprecated("use other intrinsics or C++11 atomics instead"))) |
| 821 | _ReadBarrier(void) { |
| 822 | __asm__ volatile ("" : : : "memory"); |
| 823 | } |
| 824 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 825 | __attribute__((deprecated("use other intrinsics or C++11 atomics instead"))) |
| 826 | _WriteBarrier(void) { |
| 827 | __asm__ volatile ("" : : : "memory"); |
| 828 | } |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame^] | 829 | #ifdef __x86_64__ |
| 830 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 831 | __faststorefence(void) { |
| 832 | __asm__ volatile("lock orq $0, (%%rsp)" : : : "memory"); |
| 833 | } |
| 834 | #endif |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 835 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 836 | |* readfs |
| 837 | |* (Pointers in address space #257 are relative to the FS segment register.) |
| 838 | \*----------------------------------------------------------------------------*/ |
| 839 | #ifdef __i386__ |
| 840 | #define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \ |
| 841 | ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \ |
| 842 | (__offset)) |
| 843 | |
| 844 | static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__)) |
| 845 | __readfsbyte(unsigned long __offset) { |
| 846 | return *__ptr_to_addr_space(257, unsigned char, __offset); |
| 847 | } |
| 848 | static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__)) |
| 849 | __readfsdword(unsigned long __offset) { |
| 850 | return *__ptr_to_addr_space(257, unsigned long, __offset); |
| 851 | } |
| 852 | static __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__)) |
| 853 | __readfsqword(unsigned long __offset) { |
| 854 | return *__ptr_to_addr_space(257, unsigned __int64, __offset); |
| 855 | } |
| 856 | static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__)) |
| 857 | __readfsword(unsigned long __offset) { |
| 858 | return *__ptr_to_addr_space(257, unsigned short, __offset); |
| 859 | } |
| 860 | #undef __ptr_to_addr_space |
| 861 | #endif |
| 862 | /*----------------------------------------------------------------------------*\ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 863 | |* Misc |
| 864 | \*----------------------------------------------------------------------------*/ |
| 865 | static __inline__ void * __attribute__((__always_inline__, __nodebug__)) |
| 866 | _AddressOfReturnAddress(void) { |
| 867 | return (void*)((char*)__builtin_frame_address(0) + sizeof(void*)); |
| 868 | } |
| 869 | static __inline__ void * __attribute__((__always_inline__, __nodebug__)) |
| 870 | _ReturnAddress(void) { |
| 871 | return __builtin_return_address(0); |
| 872 | } |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 873 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 874 | __cpuid(int __info[4], int __level) { |
| 875 | #if __i386__ |
| 876 | __asm__ ("cpuid" |
| 877 | : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) |
| 878 | : "0"(__level)); |
| 879 | #else |
| 880 | __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) |
| 881 | : "0"(__level)); |
| 882 | #endif |
| 883 | } |
| 884 | static __inline__ unsigned __int64 __cdecl __attribute__((__always_inline__, __nodebug__)) |
| 885 | _xgetbv(unsigned int __xcr_no) { |
| 886 | unsigned int __eax, __edx; |
| 887 | __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no)); |
| 888 | return ((unsigned __int64)__edx << 32) | __eax; |
| 889 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 890 | |
Eric Christopher | cc87253 | 2013-09-18 22:40:18 +0000 | [diff] [blame] | 891 | #ifdef __cplusplus |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 892 | } |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 893 | #endif |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 894 | |
| 895 | #endif /* __INTRIN_H */ |
| 896 | #endif /* _MSC_VER */ |