Hans Wennborg | f8b91f8 | 2016-06-14 20:14:24 +0000 | [diff] [blame] | 1 | /* ===-------- intrin.h ---------------------------------------------------=== |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 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 |
Hans Wennborg | f8b91f8 | 2016-06-14 20:14:24 +0000 | [diff] [blame] | 26 | #include_next <intrin.h> |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 27 | #else |
| 28 | |
| 29 | #ifndef __INTRIN_H |
| 30 | #define __INTRIN_H |
| 31 | |
| 32 | /* First include the standard intrinsics. */ |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 33 | #if defined(__i386__) || defined(__x86_64__) |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 34 | #include <x86intrin.h> |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 35 | #endif |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 36 | |
Saleem Abdulrasool | afdef20 | 2016-08-06 17:58:24 +0000 | [diff] [blame^] | 37 | #if defined(__arm__) |
| 38 | #include <armintr.h> |
| 39 | #endif |
| 40 | |
Hans Wennborg | 1fd6dd3 | 2014-01-28 23:01:59 +0000 | [diff] [blame] | 41 | /* For the definition of jmp_buf. */ |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 42 | #if __STDC_HOSTED__ |
Hans Wennborg | 1fd6dd3 | 2014-01-28 23:01:59 +0000 | [diff] [blame] | 43 | #include <setjmp.h> |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 44 | #endif |
Hans Wennborg | 1fd6dd3 | 2014-01-28 23:01:59 +0000 | [diff] [blame] | 45 | |
Eric Christopher | 5a9bec1 | 2015-06-15 23:20:35 +0000 | [diff] [blame] | 46 | /* Define the default attributes for the functions in this file. */ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 47 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) |
Eric Christopher | 5a9bec1 | 2015-06-15 23:20:35 +0000 | [diff] [blame] | 48 | |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
Saleem Abdulrasool | c4ebb12 | 2014-07-08 05:46:04 +0000 | [diff] [blame] | 53 | #if defined(__MMX__) |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 54 | /* And the random ones that aren't in those files. */ |
| 55 | __m64 _m_from_float(float); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 56 | float _m_to_float(__m64); |
Saleem Abdulrasool | c4ebb12 | 2014-07-08 05:46:04 +0000 | [diff] [blame] | 57 | #endif |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 58 | |
| 59 | /* Other assorted instruction intrinsics. */ |
| 60 | void __addfsbyte(unsigned long, unsigned char); |
| 61 | void __addfsdword(unsigned long, unsigned long); |
| 62 | void __addfsword(unsigned long, unsigned short); |
| 63 | void __code_seg(const char *); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 64 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 65 | void __cpuid(int[4], int); |
Hans Wennborg | 12fb89e | 2014-01-31 19:44:55 +0000 | [diff] [blame] | 66 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 67 | void __cpuidex(int[4], int, int); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 68 | void __debugbreak(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 69 | __int64 __emul(int, int); |
| 70 | unsigned __int64 __emulu(unsigned int, unsigned int); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 71 | void __cdecl __fastfail(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 72 | unsigned int __getcallerseflags(void); |
Hans Wennborg | 740a4d6 | 2014-01-28 22:55:01 +0000 | [diff] [blame] | 73 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 74 | void __halt(void); |
| 75 | unsigned char __inbyte(unsigned short); |
| 76 | void __inbytestring(unsigned short, unsigned char *, unsigned long); |
| 77 | void __incfsbyte(unsigned long); |
| 78 | void __incfsdword(unsigned long); |
| 79 | void __incfsword(unsigned long); |
| 80 | unsigned long __indword(unsigned short); |
| 81 | void __indwordstring(unsigned short, unsigned long *, unsigned long); |
| 82 | void __int2c(void); |
| 83 | void __invlpg(void *); |
| 84 | unsigned short __inword(unsigned short); |
| 85 | void __inwordstring(unsigned short, unsigned short *, unsigned long); |
| 86 | void __lidt(void *); |
| 87 | unsigned __int64 __ll_lshift(unsigned __int64, int); |
| 88 | __int64 __ll_rshift(__int64, int); |
| 89 | void __llwpcb(void *); |
| 90 | unsigned char __lwpins32(unsigned int, unsigned int, unsigned int); |
| 91 | void __lwpval32(unsigned int, unsigned int, unsigned int); |
| 92 | unsigned int __lzcnt(unsigned int); |
| 93 | unsigned short __lzcnt16(unsigned short); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 94 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 95 | void __movsb(unsigned char *, unsigned char const *, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 96 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 97 | void __movsd(unsigned long *, unsigned long const *, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 98 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 99 | void __movsw(unsigned short *, unsigned short const *, size_t); |
| 100 | void __nop(void); |
| 101 | void __nvreg_restore_fence(void); |
| 102 | void __nvreg_save_fence(void); |
| 103 | void __outbyte(unsigned short, unsigned char); |
| 104 | void __outbytestring(unsigned short, unsigned char *, unsigned long); |
| 105 | void __outdword(unsigned short, unsigned long); |
| 106 | void __outdwordstring(unsigned short, unsigned long *, unsigned long); |
| 107 | void __outword(unsigned short, unsigned short); |
| 108 | void __outwordstring(unsigned short, unsigned short *, unsigned long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 109 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 110 | unsigned int __popcnt(unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 111 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 112 | unsigned short __popcnt16(unsigned short); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 113 | unsigned long __readcr0(void); |
| 114 | unsigned long __readcr2(void); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 115 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 116 | unsigned long __readcr3(void); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 117 | unsigned long __readcr4(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 118 | unsigned long __readcr8(void); |
| 119 | unsigned int __readdr(unsigned int); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 120 | #ifdef __i386__ |
| 121 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 122 | unsigned char __readfsbyte(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 123 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 124 | unsigned long __readfsdword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 125 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 126 | unsigned __int64 __readfsqword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 127 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 128 | unsigned short __readfsword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 129 | #endif |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 130 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 131 | unsigned __int64 __readmsr(unsigned long); |
| 132 | unsigned __int64 __readpmc(unsigned long); |
| 133 | unsigned long __segmentlimit(unsigned long); |
| 134 | void __sidt(void *); |
| 135 | void *__slwpcb(void); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 136 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 137 | void __stosb(unsigned char *, unsigned char, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 138 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 139 | void __stosd(unsigned long *, unsigned long, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 140 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 141 | void __stosw(unsigned short *, unsigned short, size_t); |
| 142 | void __svm_clgi(void); |
| 143 | void __svm_invlpga(void *, int); |
| 144 | void __svm_skinit(int); |
| 145 | void __svm_stgi(void); |
| 146 | void __svm_vmload(size_t); |
| 147 | void __svm_vmrun(size_t); |
| 148 | void __svm_vmsave(size_t); |
| 149 | void __ud2(void); |
| 150 | unsigned __int64 __ull_rshift(unsigned __int64, int); |
| 151 | void __vmx_off(void); |
| 152 | void __vmx_vmptrst(unsigned __int64 *); |
| 153 | void __wbinvd(void); |
| 154 | void __writecr0(unsigned int); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 155 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 156 | void __writecr3(unsigned int); |
| 157 | void __writecr4(unsigned int); |
| 158 | void __writecr8(unsigned int); |
| 159 | void __writedr(unsigned int, unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 160 | void __writefsbyte(unsigned long, unsigned char); |
| 161 | void __writefsdword(unsigned long, unsigned long); |
| 162 | void __writefsqword(unsigned long, unsigned __int64); |
| 163 | void __writefsword(unsigned long, unsigned short); |
| 164 | void __writemsr(unsigned long, unsigned __int64); |
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 | void *_AddressOfReturnAddress(void); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 167 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 168 | unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 169 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 170 | unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 171 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 172 | unsigned char _bittest(long const *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 173 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 174 | unsigned char _bittestandcomplement(long *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 175 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 176 | unsigned char _bittestandreset(long *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 177 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 178 | unsigned char _bittestandset(long *, long); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 179 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
| 180 | unsigned long __cdecl _byteswap_ulong(unsigned long); |
| 181 | unsigned short __cdecl _byteswap_ushort(unsigned short); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 182 | void __cdecl _disable(void); |
| 183 | void __cdecl _enable(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 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); |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 192 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 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); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 220 | long _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 | void _ReadBarrier(void); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 258 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 259 | void _ReadWriteBarrier(void); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 260 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 261 | void *_ReturnAddress(void); |
| 262 | unsigned int _rorx_u32(unsigned int, const unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 263 | static __inline__ |
Eric Christopher | fb4b433 | 2013-08-31 00:27:38 +0000 | [diff] [blame] | 264 | unsigned int __cdecl _rotl(unsigned int _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 265 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 266 | unsigned short _rotl16(unsigned short _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 267 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 268 | unsigned __int64 __cdecl _rotl64(unsigned __int64 _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 char _rotl8(unsigned char _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 int __cdecl _rotr(unsigned int _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 short _rotr16(unsigned short _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 __int64 __cdecl _rotr64(unsigned __int64 _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 char _rotr8(unsigned char _Value, unsigned char _Shift); |
| 279 | int _sarx_i32(int, unsigned int); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 280 | #if __STDC_HOSTED__ |
Hans Wennborg | 1fd6dd3 | 2014-01-28 23:01:59 +0000 | [diff] [blame] | 281 | int __cdecl _setjmp(jmp_buf); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 282 | #endif |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 283 | unsigned int _shlx_u32(unsigned int, unsigned int); |
| 284 | unsigned int _shrx_u32(unsigned int, unsigned int); |
| 285 | void _Store_HLERelease(long volatile *, long); |
| 286 | void _Store64_HLERelease(__int64 volatile *, __int64); |
| 287 | void _StorePointer_HLERelease(void *volatile *, void *); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 288 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 289 | void _WriteBarrier(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 290 | unsigned __int32 xbegin(void); |
| 291 | void _xend(void); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 292 | static __inline__ |
Hans Wennborg | 2e56d95 | 2015-01-27 23:34:35 +0000 | [diff] [blame] | 293 | #define _XCR_XFEATURE_ENABLED_MASK 0 |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 294 | unsigned __int64 __cdecl _xgetbv(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 295 | void __cdecl _xsetbv(unsigned int, unsigned __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 296 | |
| 297 | /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */ |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 298 | #ifdef __x86_64__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 299 | void __addgsbyte(unsigned long, unsigned char); |
| 300 | void __addgsdword(unsigned long, unsigned long); |
| 301 | void __addgsqword(unsigned long, unsigned __int64); |
| 302 | void __addgsword(unsigned long, unsigned short); |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame] | 303 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 304 | void __faststorefence(void); |
| 305 | void __incgsbyte(unsigned long); |
| 306 | void __incgsdword(unsigned long); |
| 307 | void __incgsqword(unsigned long); |
| 308 | void __incgsword(unsigned long); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 309 | unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int); |
| 310 | void __lwpval64(unsigned __int64, unsigned int, unsigned int); |
| 311 | unsigned __int64 __lzcnt64(unsigned __int64); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 312 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 313 | void __movsq(unsigned long long *, unsigned long long const *, size_t); |
| 314 | __int64 __mulh(__int64, __int64); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 315 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 316 | unsigned __int64 __popcnt64(unsigned __int64); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 317 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 318 | unsigned char __readgsbyte(unsigned long); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 319 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 320 | unsigned long __readgsdword(unsigned long); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 321 | static __inline__ |
| 322 | unsigned __int64 __readgsqword(unsigned long); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 323 | unsigned short __readgsword(unsigned long); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 324 | unsigned __int64 __shiftleft128(unsigned __int64 _LowPart, |
| 325 | unsigned __int64 _HighPart, |
| 326 | unsigned char _Shift); |
| 327 | unsigned __int64 __shiftright128(unsigned __int64 _LowPart, |
| 328 | unsigned __int64 _HighPart, |
| 329 | unsigned char _Shift); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 330 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 331 | void __stosq(unsigned __int64 *, unsigned __int64, size_t); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 332 | unsigned char __vmx_on(unsigned __int64 *); |
| 333 | unsigned char __vmx_vmclear(unsigned __int64 *); |
| 334 | unsigned char __vmx_vmlaunch(void); |
| 335 | unsigned char __vmx_vmptrld(unsigned __int64 *); |
| 336 | unsigned char __vmx_vmread(size_t, size_t *); |
| 337 | unsigned char __vmx_vmresume(void); |
| 338 | unsigned char __vmx_vmwrite(size_t, size_t); |
| 339 | void __writegsbyte(unsigned long, unsigned char); |
| 340 | void __writegsdword(unsigned long, unsigned long); |
| 341 | void __writegsqword(unsigned long, unsigned __int64); |
| 342 | void __writegsword(unsigned long, unsigned short); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 343 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 344 | unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 345 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 346 | unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 347 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 348 | unsigned char _bittest64(__int64 const *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 349 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 350 | unsigned char _bittestandcomplement64(__int64 *, __int64); |
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 _bittestandreset64(__int64 *, __int64); |
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 _bittestandset64(__int64 *, __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 355 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 356 | long _InterlockedAnd_np(long volatile *_Value, long _Mask); |
| 357 | short _InterlockedAnd16_np(short volatile *_Value, short _Mask); |
| 358 | __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask); |
| 359 | char _InterlockedAnd8_np(char volatile *_Value, char _Mask); |
| 360 | unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64); |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 361 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 362 | unsigned char _interlockedbittestandset64(__int64 volatile *, __int64); |
| 363 | long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange, |
| 364 | long _Comparand); |
| 365 | unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination, |
| 366 | __int64 _ExchangeHigh, |
| 367 | __int64 _ExchangeLow, |
| 368 | __int64 *_CompareandResult); |
| 369 | unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination, |
| 370 | __int64 _ExchangeHigh, |
| 371 | __int64 _ExchangeLow, |
| 372 | __int64 *_ComparandResult); |
| 373 | short _InterlockedCompareExchange16_np(short volatile *_Destination, |
| 374 | short _Exchange, short _Comparand); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 375 | __int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64, |
| 376 | __int64); |
| 377 | __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, |
| 378 | __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 379 | __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination, |
| 380 | __int64 _Exchange, __int64 _Comparand); |
Eric Christopher | 58b4043 | 2014-01-25 01:38:30 +0000 | [diff] [blame] | 381 | void *_InterlockedCompareExchangePointer(void *volatile *_Destination, |
| 382 | void *_Exchange, void *_Comparand); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 383 | void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination, |
| 384 | void *_Exchange, void *_Comparand); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 385 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 386 | __int64 _InterlockedDecrement64(__int64 volatile *_Addend); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 387 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 388 | __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 389 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 390 | __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value); |
| 391 | void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 392 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 393 | __int64 _InterlockedIncrement64(__int64 volatile *_Addend); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 394 | long _InterlockedOr_np(long volatile *_Value, long _Mask); |
| 395 | short _InterlockedOr16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 396 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 397 | __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask); |
Warren Hunt | 41a993f | 2013-09-28 00:15:41 +0000 | [diff] [blame] | 398 | __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 399 | char _InterlockedOr8_np(char volatile *_Value, char _Mask); |
| 400 | long _InterlockedXor_np(long volatile *_Value, long _Mask); |
| 401 | short _InterlockedXor16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 402 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 403 | __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 404 | __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask); |
| 405 | char _InterlockedXor8_np(char volatile *_Value, char _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 406 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 407 | __int64 _mul128(__int64 _Multiplier, __int64 _Multiplicand, |
| 408 | __int64 *_HighProduct); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 409 | unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 410 | __int64 _sarx_i64(__int64, unsigned int); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 411 | #if __STDC_HOSTED__ |
| 412 | int __cdecl _setjmpex(jmp_buf); |
| 413 | #endif |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 414 | unsigned __int64 _shlx_u64(unsigned __int64, unsigned int); |
David Majnemer | 5450763 | 2014-12-02 23:30:26 +0000 | [diff] [blame] | 415 | unsigned __int64 _shrx_u64(unsigned __int64, unsigned int); |
David Majnemer | 5f9afc5 | 2014-12-02 23:30:24 +0000 | [diff] [blame] | 416 | /* |
| 417 | * Multiply two 64-bit integers and obtain a 64-bit result. |
| 418 | * The low-half is returned directly and the high half is in an out parameter. |
| 419 | */ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 420 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
David Majnemer | 5f9afc5 | 2014-12-02 23:30:24 +0000 | [diff] [blame] | 421 | _umul128(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand, |
| 422 | unsigned __int64 *_HighProduct) { |
| 423 | unsigned __int128 _FullProduct = |
| 424 | (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand; |
David Majnemer | 00973ce | 2014-12-02 23:44:40 +0000 | [diff] [blame] | 425 | *_HighProduct = _FullProduct >> 64; |
| 426 | return _FullProduct; |
David Majnemer | 5f9afc5 | 2014-12-02 23:30:24 +0000 | [diff] [blame] | 427 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 428 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Reid Kleckner | baf7709 | 2014-12-03 23:36:14 +0000 | [diff] [blame] | 429 | __umulh(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand) { |
| 430 | unsigned __int128 _FullProduct = |
| 431 | (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand; |
| 432 | return _FullProduct >> 64; |
| 433 | } |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 434 | |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 435 | #endif /* __x86_64__ */ |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 436 | |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 437 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | 4ca00af | 2015-10-14 16:24:28 +0000 | [diff] [blame] | 438 | |* Multiplication |
| 439 | \*----------------------------------------------------------------------------*/ |
| 440 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 441 | __emul(int __in1, int __in2) { |
| 442 | return (__int64)__in1 * (__int64)__in2; |
| 443 | } |
| 444 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
| 445 | __emulu(unsigned int __in1, unsigned int __in2) { |
| 446 | return (unsigned __int64)__in1 * (unsigned __int64)__in2; |
| 447 | } |
| 448 | /*----------------------------------------------------------------------------*\ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 449 | |* Bit Twiddling |
| 450 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 451 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 452 | _rotl8(unsigned char _Value, unsigned char _Shift) { |
| 453 | _Shift &= 0x7; |
| 454 | return _Shift ? (_Value << _Shift) | (_Value >> (8 - _Shift)) : _Value; |
| 455 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 456 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 457 | _rotr8(unsigned char _Value, unsigned char _Shift) { |
| 458 | _Shift &= 0x7; |
| 459 | return _Shift ? (_Value >> _Shift) | (_Value << (8 - _Shift)) : _Value; |
| 460 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 461 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 462 | _rotl16(unsigned short _Value, unsigned char _Shift) { |
| 463 | _Shift &= 0xf; |
| 464 | return _Shift ? (_Value << _Shift) | (_Value >> (16 - _Shift)) : _Value; |
| 465 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 466 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 467 | _rotr16(unsigned short _Value, unsigned char _Shift) { |
| 468 | _Shift &= 0xf; |
| 469 | return _Shift ? (_Value >> _Shift) | (_Value << (16 - _Shift)) : _Value; |
| 470 | } |
Michael Kuperstein | b62c5bc | 2015-08-25 11:42:31 +0000 | [diff] [blame] | 471 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| 472 | _rotl(unsigned int _Value, int _Shift) { |
| 473 | _Shift &= 0x1f; |
| 474 | return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; |
| 475 | } |
| 476 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| 477 | _rotr(unsigned int _Value, int _Shift) { |
| 478 | _Shift &= 0x1f; |
| 479 | return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; |
| 480 | } |
| 481 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
| 482 | _lrotl(unsigned long _Value, int _Shift) { |
| 483 | _Shift &= 0x1f; |
| 484 | return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; |
| 485 | } |
| 486 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
| 487 | _lrotr(unsigned long _Value, int _Shift) { |
| 488 | _Shift &= 0x1f; |
| 489 | return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; |
| 490 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 491 | static |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 492 | __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 493 | _rotl64(unsigned __int64 _Value, int _Shift) { |
| 494 | _Shift &= 0x3f; |
| 495 | return _Shift ? (_Value << _Shift) | (_Value >> (64 - _Shift)) : _Value; |
| 496 | } |
| 497 | static |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 498 | __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 499 | _rotr64(unsigned __int64 _Value, int _Shift) { |
| 500 | _Shift &= 0x3f; |
| 501 | return _Shift ? (_Value >> _Shift) | (_Value << (64 - _Shift)) : _Value; |
| 502 | } |
| 503 | /*----------------------------------------------------------------------------*\ |
| 504 | |* Bit Counting and Testing |
| 505 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 506 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 507 | _BitScanForward(unsigned long *_Index, unsigned long _Mask) { |
| 508 | if (!_Mask) |
| 509 | return 0; |
| 510 | *_Index = __builtin_ctzl(_Mask); |
| 511 | return 1; |
| 512 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 513 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 514 | _BitScanReverse(unsigned long *_Index, unsigned long _Mask) { |
| 515 | if (!_Mask) |
| 516 | return 0; |
| 517 | *_Index = 31 - __builtin_clzl(_Mask); |
| 518 | return 1; |
| 519 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 520 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
David Majnemer | 8dadce7 | 2015-07-13 02:53:23 +0000 | [diff] [blame] | 521 | __popcnt16(unsigned short _Value) { |
| 522 | return __builtin_popcount((int)_Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 523 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 524 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
David Majnemer | 8dadce7 | 2015-07-13 02:53:23 +0000 | [diff] [blame] | 525 | __popcnt(unsigned int _Value) { |
| 526 | return __builtin_popcount(_Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 527 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 528 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 529 | _bittest(long const *_BitBase, long _BitPos) { |
| 530 | return (*_BitBase >> _BitPos) & 1; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 531 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 532 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 533 | _bittestandcomplement(long *_BitBase, long _BitPos) { |
| 534 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 535 | *_BitBase = *_BitBase ^ (1 << _BitPos); |
| 536 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 537 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 538 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 539 | _bittestandreset(long *_BitBase, long _BitPos) { |
| 540 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 541 | *_BitBase = *_BitBase & ~(1 << _BitPos); |
| 542 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 543 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 544 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 545 | _bittestandset(long *_BitBase, long _BitPos) { |
| 546 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 547 | *_BitBase = *_BitBase | (1 << _BitPos); |
| 548 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 549 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 550 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 551 | _interlockedbittestandset(long volatile *_BitBase, long _BitPos) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 552 | long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST); |
| 553 | return (_PrevVal >> _BitPos) & 1; |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 554 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 555 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 556 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 557 | _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 558 | if (!_Mask) |
| 559 | return 0; |
| 560 | *_Index = __builtin_ctzll(_Mask); |
| 561 | return 1; |
| 562 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 563 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 564 | _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 565 | if (!_Mask) |
| 566 | return 0; |
| 567 | *_Index = 63 - __builtin_clzll(_Mask); |
| 568 | return 1; |
| 569 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 570 | static __inline__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 571 | unsigned __int64 __DEFAULT_FN_ATTRS |
David Majnemer | 8dadce7 | 2015-07-13 02:53:23 +0000 | [diff] [blame] | 572 | __popcnt64(unsigned __int64 _Value) { |
| 573 | return __builtin_popcountll(_Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 574 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 575 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 576 | _bittest64(__int64 const *_BitBase, __int64 _BitPos) { |
| 577 | return (*_BitBase >> _BitPos) & 1; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 578 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 579 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 580 | _bittestandcomplement64(__int64 *_BitBase, __int64 _BitPos) { |
| 581 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 582 | *_BitBase = *_BitBase ^ (1ll << _BitPos); |
| 583 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 584 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 585 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 586 | _bittestandreset64(__int64 *_BitBase, __int64 _BitPos) { |
| 587 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 588 | *_BitBase = *_BitBase & ~(1ll << _BitPos); |
| 589 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 590 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 591 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 592 | _bittestandset64(__int64 *_BitBase, __int64 _BitPos) { |
| 593 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 594 | *_BitBase = *_BitBase | (1ll << _BitPos); |
| 595 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 596 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 597 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 598 | _interlockedbittestandset64(__int64 volatile *_BitBase, __int64 _BitPos) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 599 | long long _PrevVal = |
| 600 | __atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST); |
| 601 | return (_PrevVal >> _BitPos) & 1; |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 602 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 603 | #endif |
| 604 | /*----------------------------------------------------------------------------*\ |
| 605 | |* Interlocked Exchange Add |
| 606 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 607 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 608 | _InterlockedExchangeAdd8(char volatile *_Addend, char _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 609 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 610 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 611 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 612 | _InterlockedExchangeAdd16(short volatile *_Addend, short _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 613 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 614 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 615 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 616 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 617 | _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 618 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 619 | } |
| 620 | #endif |
| 621 | /*----------------------------------------------------------------------------*\ |
| 622 | |* Interlocked Exchange Sub |
| 623 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 624 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 625 | _InterlockedExchangeSub8(char volatile *_Subend, char _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 626 | return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 627 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 628 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 629 | _InterlockedExchangeSub16(short volatile *_Subend, short _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 630 | return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 631 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 632 | static __inline__ long __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 633 | _InterlockedExchangeSub(long volatile *_Subend, long _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 634 | return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 635 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 636 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 637 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 638 | _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 639 | return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 640 | } |
| 641 | #endif |
| 642 | /*----------------------------------------------------------------------------*\ |
| 643 | |* Interlocked Increment |
| 644 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 645 | static __inline__ short __DEFAULT_FN_ATTRS |
Hans Wennborg | 2ed8880 | 2014-01-23 19:15:39 +0000 | [diff] [blame] | 646 | _InterlockedIncrement16(short volatile *_Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 647 | return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 648 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 649 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 650 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 651 | _InterlockedIncrement64(__int64 volatile *_Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 652 | return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 653 | } |
| 654 | #endif |
| 655 | /*----------------------------------------------------------------------------*\ |
| 656 | |* Interlocked Decrement |
| 657 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 658 | static __inline__ short __DEFAULT_FN_ATTRS |
Hans Wennborg | 2ed8880 | 2014-01-23 19:15:39 +0000 | [diff] [blame] | 659 | _InterlockedDecrement16(short volatile *_Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 660 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 661 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 662 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 663 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 664 | _InterlockedDecrement64(__int64 volatile *_Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 665 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 666 | } |
| 667 | #endif |
| 668 | /*----------------------------------------------------------------------------*\ |
| 669 | |* Interlocked And |
| 670 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 671 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 672 | _InterlockedAnd8(char volatile *_Value, char _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 673 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 674 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 675 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 676 | _InterlockedAnd16(short volatile *_Value, short _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 677 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 678 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 679 | static __inline__ long __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 680 | _InterlockedAnd(long volatile *_Value, long _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 681 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 682 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 683 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 684 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 685 | _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 686 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 687 | } |
| 688 | #endif |
| 689 | /*----------------------------------------------------------------------------*\ |
| 690 | |* Interlocked Or |
| 691 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 692 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 693 | _InterlockedOr8(char volatile *_Value, char _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 694 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 695 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 696 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 697 | _InterlockedOr16(short volatile *_Value, short _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 698 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 699 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 700 | static __inline__ long __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 701 | _InterlockedOr(long volatile *_Value, long _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 702 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 703 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 704 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 705 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 706 | _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 707 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 708 | } |
| 709 | #endif |
| 710 | /*----------------------------------------------------------------------------*\ |
| 711 | |* Interlocked Xor |
| 712 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 713 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 714 | _InterlockedXor8(char volatile *_Value, char _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 715 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 716 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 717 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 718 | _InterlockedXor16(short volatile *_Value, short _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 719 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 720 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 721 | static __inline__ long __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 722 | _InterlockedXor(long volatile *_Value, long _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 723 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 724 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 725 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 726 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 727 | _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) { |
David Majnemer | 2916a61 | 2016-06-28 02:54:43 +0000 | [diff] [blame] | 728 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 729 | } |
| 730 | #endif |
| 731 | /*----------------------------------------------------------------------------*\ |
| 732 | |* Interlocked Exchange |
| 733 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 734 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 735 | _InterlockedExchange8(char volatile *_Target, char _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 736 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 737 | return _Value; |
| 738 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 739 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 740 | _InterlockedExchange16(short volatile *_Target, short _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 741 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 742 | return _Value; |
| 743 | } |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 744 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 745 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 746 | _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 747 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 748 | return _Value; |
| 749 | } |
| 750 | #endif |
| 751 | /*----------------------------------------------------------------------------*\ |
| 752 | |* Interlocked Compare Exchange |
| 753 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 754 | static __inline__ char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 755 | _InterlockedCompareExchange8(char volatile *_Destination, |
| 756 | char _Exchange, char _Comparand) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 757 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 758 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 759 | return _Comparand; |
| 760 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 761 | static __inline__ short __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 762 | _InterlockedCompareExchange16(short volatile *_Destination, |
| 763 | short _Exchange, short _Comparand) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 764 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 765 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 766 | return _Comparand; |
| 767 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 768 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 769 | _InterlockedCompareExchange64(__int64 volatile *_Destination, |
| 770 | __int64 _Exchange, __int64 _Comparand) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 771 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 772 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 773 | return _Comparand; |
| 774 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 775 | /*----------------------------------------------------------------------------*\ |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 776 | |* Barriers |
| 777 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 778 | static __inline__ void __DEFAULT_FN_ATTRS |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 779 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 780 | _ReadWriteBarrier(void) { |
David Majnemer | 6b8e297 | 2015-07-16 03:13:02 +0000 | [diff] [blame] | 781 | __atomic_signal_fence(__ATOMIC_SEQ_CST); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 782 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 783 | static __inline__ void __DEFAULT_FN_ATTRS |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 784 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 785 | _ReadBarrier(void) { |
David Majnemer | 6b8e297 | 2015-07-16 03:13:02 +0000 | [diff] [blame] | 786 | __atomic_signal_fence(__ATOMIC_SEQ_CST); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 787 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 788 | static __inline__ void __DEFAULT_FN_ATTRS |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 789 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 790 | _WriteBarrier(void) { |
David Majnemer | 6b8e297 | 2015-07-16 03:13:02 +0000 | [diff] [blame] | 791 | __atomic_signal_fence(__ATOMIC_SEQ_CST); |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 792 | } |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame] | 793 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 794 | static __inline__ void __DEFAULT_FN_ATTRS |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame] | 795 | __faststorefence(void) { |
David Majnemer | 6b8e297 | 2015-07-16 03:13:02 +0000 | [diff] [blame] | 796 | __atomic_thread_fence(__ATOMIC_SEQ_CST); |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame] | 797 | } |
| 798 | #endif |
Reid Kleckner | 00d33a5 | 2013-10-17 01:29:48 +0000 | [diff] [blame] | 799 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 800 | |* readfs, readgs |
| 801 | |* (Pointers in address space #256 and #257 are relative to the GS and FS |
| 802 | |* segment registers, respectively.) |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 803 | \*----------------------------------------------------------------------------*/ |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 804 | #define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \ |
| 805 | ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \ |
| 806 | (__offset)) |
| 807 | |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 808 | #ifdef __i386__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 809 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 810 | __readfsbyte(unsigned long __offset) { |
| 811 | return *__ptr_to_addr_space(257, unsigned char, __offset); |
| 812 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 813 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 814 | __readfsword(unsigned long __offset) { |
| 815 | return *__ptr_to_addr_space(257, unsigned short, __offset); |
| 816 | } |
David Majnemer | b2c5720 | 2016-05-27 02:06:14 +0000 | [diff] [blame] | 817 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
| 818 | __readfsqword(unsigned long __offset) { |
| 819 | return *__ptr_to_addr_space(257, unsigned __int64, __offset); |
| 820 | } |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 821 | #endif |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 822 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 823 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 824 | __readgsbyte(unsigned long __offset) { |
| 825 | return *__ptr_to_addr_space(256, unsigned char, __offset); |
| 826 | } |
David Majnemer | b2c5720 | 2016-05-27 02:06:14 +0000 | [diff] [blame] | 827 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
| 828 | __readgsword(unsigned long __offset) { |
| 829 | return *__ptr_to_addr_space(256, unsigned short, __offset); |
| 830 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 831 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 832 | __readgsdword(unsigned long __offset) { |
| 833 | return *__ptr_to_addr_space(256, unsigned long, __offset); |
| 834 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 835 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 836 | __readgsqword(unsigned long __offset) { |
| 837 | return *__ptr_to_addr_space(256, unsigned __int64, __offset); |
| 838 | } |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 839 | #endif |
| 840 | #undef __ptr_to_addr_space |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 841 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 842 | |* movs, stos |
| 843 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 844 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 845 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 846 | __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) { |
| 847 | __asm__("rep movsb" : : "D"(__dst), "S"(__src), "c"(__n) |
| 848 | : "%edi", "%esi", "%ecx"); |
| 849 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 850 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 851 | __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) { |
| 852 | __asm__("rep movsl" : : "D"(__dst), "S"(__src), "c"(__n) |
| 853 | : "%edi", "%esi", "%ecx"); |
| 854 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 855 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 856 | __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) { |
Nico Weber | 1f22a34 | 2015-09-22 00:46:21 +0000 | [diff] [blame] | 857 | __asm__("rep movsw" : : "D"(__dst), "S"(__src), "c"(__n) |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 858 | : "%edi", "%esi", "%ecx"); |
| 859 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 860 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 861 | __stosb(unsigned char *__dst, unsigned char __x, size_t __n) { |
| 862 | __asm__("rep stosb" : : "D"(__dst), "a"(__x), "c"(__n) |
| 863 | : "%edi", "%ecx"); |
| 864 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 865 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 866 | __stosd(unsigned long *__dst, unsigned long __x, size_t __n) { |
| 867 | __asm__("rep stosl" : : "D"(__dst), "a"(__x), "c"(__n) |
| 868 | : "%edi", "%ecx"); |
| 869 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 870 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 871 | __stosw(unsigned short *__dst, unsigned short __x, size_t __n) { |
Nico Weber | 1f22a34 | 2015-09-22 00:46:21 +0000 | [diff] [blame] | 872 | __asm__("rep stosw" : : "D"(__dst), "a"(__x), "c"(__n) |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 873 | : "%edi", "%ecx"); |
| 874 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 875 | #endif |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 876 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 877 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 878 | __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) { |
| 879 | __asm__("rep movsq" : : "D"(__dst), "S"(__src), "c"(__n) |
| 880 | : "%edi", "%esi", "%ecx"); |
| 881 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 882 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 883 | __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) { |
| 884 | __asm__("rep stosq" : : "D"(__dst), "a"(__x), "c"(__n) |
| 885 | : "%edi", "%ecx"); |
| 886 | } |
| 887 | #endif |
| 888 | |
| 889 | /*----------------------------------------------------------------------------*\ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 890 | |* Misc |
| 891 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 892 | static __inline__ void * __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 893 | _AddressOfReturnAddress(void) { |
| 894 | return (void*)((char*)__builtin_frame_address(0) + sizeof(void*)); |
| 895 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 896 | static __inline__ void * __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 897 | _ReturnAddress(void) { |
| 898 | return __builtin_return_address(0); |
| 899 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 900 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 901 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 902 | __cpuid(int __info[4], int __level) { |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 903 | __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] | 904 | : "a"(__level)); |
| 905 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 906 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 12fb89e | 2014-01-31 19:44:55 +0000 | [diff] [blame] | 907 | __cpuidex(int __info[4], int __level, int __ecx) { |
| 908 | __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) |
| 909 | : "a"(__level), "c"(__ecx)); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 910 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 911 | static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 912 | _xgetbv(unsigned int __xcr_no) { |
| 913 | unsigned int __eax, __edx; |
| 914 | __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no)); |
| 915 | return ((unsigned __int64)__edx << 32) | __eax; |
| 916 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 917 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 740a4d6 | 2014-01-28 22:55:01 +0000 | [diff] [blame] | 918 | __halt(void) { |
| 919 | __asm__ volatile ("hlt"); |
| 920 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 921 | #endif |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 922 | |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 923 | /*----------------------------------------------------------------------------*\ |
| 924 | |* Privileged intrinsics |
| 925 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 926 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 927 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 928 | __readmsr(unsigned long __register) { |
| 929 | // Loads the contents of a 64-bit model specific register (MSR) specified in |
| 930 | // the ECX register into registers EDX:EAX. The EDX register is loaded with |
| 931 | // the high-order 32 bits of the MSR and the EAX register is loaded with the |
| 932 | // low-order 32 bits. If less than 64 bits are implemented in the MSR being |
| 933 | // read, the values returned to EDX:EAX in unimplemented bit locations are |
| 934 | // undefined. |
| 935 | unsigned long __edx; |
| 936 | unsigned long __eax; |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 937 | __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register)); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 938 | return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax; |
| 939 | } |
| 940 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 941 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 942 | __readcr3(void) { |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 943 | unsigned long __cr3_val; |
| 944 | __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory"); |
| 945 | return __cr3_val; |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 948 | static __inline__ void __DEFAULT_FN_ATTRS |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 949 | __writecr3(unsigned int __cr3_val) { |
| 950 | __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory"); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 951 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 952 | #endif |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 953 | |
Eric Christopher | cc87253 | 2013-09-18 22:40:18 +0000 | [diff] [blame] | 954 | #ifdef __cplusplus |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 955 | } |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 956 | #endif |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 957 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 958 | #undef __DEFAULT_FN_ATTRS |
Eric Christopher | 5a9bec1 | 2015-06-15 23:20:35 +0000 | [diff] [blame] | 959 | |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 960 | #endif /* __INTRIN_H */ |
| 961 | #endif /* _MSC_VER */ |