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