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