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); |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 69 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 70 | __int64 __emul(int, int); |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 71 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 72 | unsigned __int64 __emulu(unsigned int, unsigned int); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 73 | void __cdecl __fastfail(unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 74 | unsigned int __getcallerseflags(void); |
Hans Wennborg | 740a4d6 | 2014-01-28 22:55:01 +0000 | [diff] [blame] | 75 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 76 | void __halt(void); |
| 77 | unsigned char __inbyte(unsigned short); |
| 78 | void __inbytestring(unsigned short, unsigned char *, unsigned long); |
| 79 | void __incfsbyte(unsigned long); |
| 80 | void __incfsdword(unsigned long); |
| 81 | void __incfsword(unsigned long); |
| 82 | unsigned long __indword(unsigned short); |
| 83 | void __indwordstring(unsigned short, unsigned long *, unsigned long); |
| 84 | void __int2c(void); |
| 85 | void __invlpg(void *); |
| 86 | unsigned short __inword(unsigned short); |
| 87 | void __inwordstring(unsigned short, unsigned short *, unsigned long); |
| 88 | void __lidt(void *); |
| 89 | unsigned __int64 __ll_lshift(unsigned __int64, int); |
| 90 | __int64 __ll_rshift(__int64, int); |
| 91 | void __llwpcb(void *); |
| 92 | unsigned char __lwpins32(unsigned int, unsigned int, unsigned int); |
| 93 | void __lwpval32(unsigned int, unsigned int, unsigned int); |
| 94 | unsigned int __lzcnt(unsigned int); |
| 95 | unsigned short __lzcnt16(unsigned short); |
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 __movsb(unsigned char *, unsigned char 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 __movsd(unsigned long *, unsigned long const *, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 100 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 101 | void __movsw(unsigned short *, unsigned short const *, size_t); |
Reid Kleckner | 5de2bcd | 2016-09-07 16:55:12 +0000 | [diff] [blame] | 102 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 103 | void __nop(void); |
| 104 | void __nvreg_restore_fence(void); |
| 105 | void __nvreg_save_fence(void); |
| 106 | void __outbyte(unsigned short, unsigned char); |
| 107 | void __outbytestring(unsigned short, unsigned char *, unsigned long); |
| 108 | void __outdword(unsigned short, unsigned long); |
| 109 | void __outdwordstring(unsigned short, unsigned long *, unsigned long); |
| 110 | void __outword(unsigned short, unsigned short); |
| 111 | void __outwordstring(unsigned short, unsigned short *, unsigned long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 112 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 113 | unsigned int __popcnt(unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 114 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 115 | unsigned short __popcnt16(unsigned short); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 116 | unsigned long __readcr0(void); |
| 117 | unsigned long __readcr2(void); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 118 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 119 | unsigned long __readcr3(void); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 120 | unsigned long __readcr4(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 121 | unsigned long __readcr8(void); |
| 122 | unsigned int __readdr(unsigned int); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 123 | #ifdef __i386__ |
| 124 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 125 | unsigned char __readfsbyte(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 126 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 127 | unsigned long __readfsdword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 128 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 129 | unsigned __int64 __readfsqword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 130 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 131 | unsigned short __readfsword(unsigned long); |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 132 | #endif |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 133 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 134 | unsigned __int64 __readmsr(unsigned long); |
| 135 | unsigned __int64 __readpmc(unsigned long); |
| 136 | unsigned long __segmentlimit(unsigned long); |
| 137 | void __sidt(void *); |
| 138 | void *__slwpcb(void); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 139 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 140 | void __stosb(unsigned char *, unsigned char, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 141 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 142 | void __stosd(unsigned long *, unsigned long, size_t); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 143 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 144 | void __stosw(unsigned short *, unsigned short, size_t); |
| 145 | void __svm_clgi(void); |
| 146 | void __svm_invlpga(void *, int); |
| 147 | void __svm_skinit(int); |
| 148 | void __svm_stgi(void); |
| 149 | void __svm_vmload(size_t); |
| 150 | void __svm_vmrun(size_t); |
| 151 | void __svm_vmsave(size_t); |
| 152 | void __ud2(void); |
| 153 | unsigned __int64 __ull_rshift(unsigned __int64, int); |
| 154 | void __vmx_off(void); |
| 155 | void __vmx_vmptrst(unsigned __int64 *); |
| 156 | void __wbinvd(void); |
| 157 | void __writecr0(unsigned int); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 158 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 159 | void __writecr3(unsigned int); |
| 160 | void __writecr4(unsigned int); |
| 161 | void __writecr8(unsigned int); |
| 162 | void __writedr(unsigned int, unsigned int); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 163 | void __writefsbyte(unsigned long, unsigned char); |
| 164 | void __writefsdword(unsigned long, unsigned long); |
| 165 | void __writefsqword(unsigned long, unsigned __int64); |
| 166 | void __writefsword(unsigned long, unsigned short); |
| 167 | void __writemsr(unsigned long, unsigned __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 168 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 169 | void *_AddressOfReturnAddress(void); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 170 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 171 | unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 172 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 173 | unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 174 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 175 | unsigned char _bittest(long const *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 176 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 177 | unsigned char _bittestandcomplement(long *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 178 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 179 | unsigned char _bittestandreset(long *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 180 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 181 | unsigned char _bittestandset(long *, long); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 182 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
| 183 | unsigned long __cdecl _byteswap_ulong(unsigned long); |
| 184 | unsigned short __cdecl _byteswap_ushort(unsigned short); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 185 | void __cdecl _disable(void); |
| 186 | void __cdecl _enable(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 187 | long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 188 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 189 | long _InterlockedAnd(long volatile *_Value, long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 190 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 191 | short _InterlockedAnd16(short volatile *_Value, short _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 192 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 193 | char _InterlockedAnd8(char volatile *_Value, char _Mask); |
| 194 | unsigned char _interlockedbittestandreset(long volatile *, long); |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 195 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 196 | unsigned char _interlockedbittestandset(long volatile *, long); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 197 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 198 | long __cdecl _InterlockedCompareExchange(long volatile *_Destination, |
| 199 | long _Exchange, long _Comparand); |
| 200 | long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long); |
| 201 | long _InterlockedCompareExchange_HLERelease(long volatile *, long, long); |
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 | short _InterlockedCompareExchange16(short volatile *_Destination, |
| 204 | short _Exchange, short _Comparand); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 205 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 206 | __int64 _InterlockedCompareExchange64(__int64 volatile *_Destination, |
| 207 | __int64 _Exchange, __int64 _Comparand); |
| 208 | __int64 _InterlockedcompareExchange64_HLEAcquire(__int64 volatile *, __int64, |
| 209 | __int64); |
| 210 | __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, |
| 211 | __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 212 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 213 | char _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange, |
| 214 | char _Comparand); |
| 215 | void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *, |
| 216 | void *); |
| 217 | void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *, |
| 218 | void *); |
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 _InterlockedDecrement(long volatile *_Addend); |
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 _InterlockedDecrement16(short volatile *_Addend); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 223 | long _InterlockedExchange(long volatile *_Target, long _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 224 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 225 | short _InterlockedExchange16(short volatile *_Target, short _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 226 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 227 | char _InterlockedExchange8(char volatile *_Target, char _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 228 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 229 | long __cdecl _InterlockedExchangeAdd(long volatile *_Addend, long _Value); |
| 230 | long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long); |
| 231 | long _InterlockedExchangeAdd_HLERelease(long volatile *, long); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 232 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 233 | short _InterlockedExchangeAdd16(short volatile *_Addend, short _Value); |
| 234 | __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64); |
| 235 | __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 236 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 237 | char _InterlockedExchangeAdd8(char volatile *_Addend, char _Value); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 238 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 239 | long __cdecl _InterlockedIncrement(long volatile *_Addend); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 240 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 241 | short _InterlockedIncrement16(short volatile *_Addend); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 242 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 243 | long _InterlockedOr(long volatile *_Value, long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 244 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 245 | short _InterlockedOr16(short volatile *_Value, short _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 246 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 247 | char _InterlockedOr8(char volatile *_Value, char _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 248 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 249 | long _InterlockedXor(long volatile *_Value, long _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 250 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 251 | short _InterlockedXor16(short volatile *_Value, short _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 252 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 253 | char _InterlockedXor8(char volatile *_Value, char _Mask); |
| 254 | void __cdecl _invpcid(unsigned int, void *); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 255 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 256 | unsigned long __cdecl _lrotl(unsigned long, int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 257 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 258 | unsigned long __cdecl _lrotr(unsigned long, int); |
Albert Gutowski | fcea61c | 2016-10-10 19:40:51 +0000 | [diff] [blame^] | 259 | static __inline__ void |
| 260 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
| 261 | _ReadBarrier(void); |
| 262 | static __inline__ void |
| 263 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
| 264 | _ReadWriteBarrier(void); |
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 | void *_ReturnAddress(void); |
| 267 | unsigned int _rorx_u32(unsigned int, const unsigned int); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 268 | static __inline__ |
Eric Christopher | fb4b433 | 2013-08-31 00:27:38 +0000 | [diff] [blame] | 269 | unsigned int __cdecl _rotl(unsigned int _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 270 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 271 | unsigned short _rotl16(unsigned short _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 272 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 273 | unsigned __int64 __cdecl _rotl64(unsigned __int64 _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 274 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 275 | unsigned char _rotl8(unsigned char _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 276 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 277 | unsigned int __cdecl _rotr(unsigned int _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 278 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 279 | unsigned short _rotr16(unsigned short _Value, unsigned char _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 280 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 281 | unsigned __int64 __cdecl _rotr64(unsigned __int64 _Value, int _Shift); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 282 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 283 | unsigned char _rotr8(unsigned char _Value, unsigned char _Shift); |
| 284 | int _sarx_i32(int, unsigned int); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 285 | #if __STDC_HOSTED__ |
Hans Wennborg | 1fd6dd3 | 2014-01-28 23:01:59 +0000 | [diff] [blame] | 286 | int __cdecl _setjmp(jmp_buf); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 287 | #endif |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 288 | unsigned int _shlx_u32(unsigned int, unsigned int); |
| 289 | unsigned int _shrx_u32(unsigned int, unsigned int); |
| 290 | void _Store_HLERelease(long volatile *, long); |
| 291 | void _Store64_HLERelease(__int64 volatile *, __int64); |
| 292 | void _StorePointer_HLERelease(void *volatile *, void *); |
Albert Gutowski | fcea61c | 2016-10-10 19:40:51 +0000 | [diff] [blame^] | 293 | static __inline__ void |
| 294 | __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) |
| 295 | _WriteBarrier(void); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 296 | unsigned __int32 xbegin(void); |
| 297 | void _xend(void); |
Reid Kleckner | 66e7717 | 2016-08-16 16:04:14 +0000 | [diff] [blame] | 298 | static __inline__ |
| 299 | #define _XCR_XFEATURE_ENABLED_MASK 0 |
| 300 | unsigned __int64 __cdecl _xgetbv(unsigned int); |
| 301 | void __cdecl _xsetbv(unsigned int, unsigned __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 302 | |
| 303 | /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */ |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 304 | #ifdef __x86_64__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 305 | void __addgsbyte(unsigned long, unsigned char); |
| 306 | void __addgsdword(unsigned long, unsigned long); |
| 307 | void __addgsqword(unsigned long, unsigned __int64); |
| 308 | void __addgsword(unsigned long, unsigned short); |
Reid Kleckner | f08d658 | 2014-01-27 19:16:35 +0000 | [diff] [blame] | 309 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 310 | void __faststorefence(void); |
| 311 | void __incgsbyte(unsigned long); |
| 312 | void __incgsdword(unsigned long); |
| 313 | void __incgsqword(unsigned long); |
| 314 | void __incgsword(unsigned long); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 315 | unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int); |
| 316 | void __lwpval64(unsigned __int64, unsigned int, unsigned int); |
| 317 | unsigned __int64 __lzcnt64(unsigned __int64); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 318 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 319 | void __movsq(unsigned long long *, unsigned long long const *, size_t); |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 320 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 321 | unsigned __int64 __popcnt64(unsigned __int64); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 322 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 323 | unsigned char __readgsbyte(unsigned long); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 324 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 325 | unsigned long __readgsdword(unsigned long); |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 326 | static __inline__ |
| 327 | unsigned __int64 __readgsqword(unsigned long); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 328 | unsigned short __readgsword(unsigned long); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 329 | unsigned __int64 __shiftleft128(unsigned __int64 _LowPart, |
| 330 | unsigned __int64 _HighPart, |
| 331 | unsigned char _Shift); |
| 332 | unsigned __int64 __shiftright128(unsigned __int64 _LowPart, |
| 333 | unsigned __int64 _HighPart, |
| 334 | unsigned char _Shift); |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 335 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 336 | void __stosq(unsigned __int64 *, unsigned __int64, size_t); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 337 | unsigned char __vmx_on(unsigned __int64 *); |
| 338 | unsigned char __vmx_vmclear(unsigned __int64 *); |
| 339 | unsigned char __vmx_vmlaunch(void); |
| 340 | unsigned char __vmx_vmptrld(unsigned __int64 *); |
| 341 | unsigned char __vmx_vmread(size_t, size_t *); |
| 342 | unsigned char __vmx_vmresume(void); |
| 343 | unsigned char __vmx_vmwrite(size_t, size_t); |
| 344 | void __writegsbyte(unsigned long, unsigned char); |
| 345 | void __writegsdword(unsigned long, unsigned long); |
| 346 | void __writegsqword(unsigned long, unsigned __int64); |
| 347 | void __writegsword(unsigned long, unsigned short); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 348 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 349 | unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 350 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 351 | unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 352 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 353 | unsigned char _bittest64(__int64 const *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 354 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 355 | unsigned char _bittestandcomplement64(__int64 *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 356 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 357 | unsigned char _bittestandreset64(__int64 *, __int64); |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 358 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 359 | unsigned char _bittestandset64(__int64 *, __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 360 | unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 361 | long _InterlockedAnd_np(long volatile *_Value, long _Mask); |
| 362 | short _InterlockedAnd16_np(short volatile *_Value, short _Mask); |
| 363 | __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask); |
| 364 | char _InterlockedAnd8_np(char volatile *_Value, char _Mask); |
| 365 | unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64); |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 366 | static __inline__ |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 367 | unsigned char _interlockedbittestandset64(__int64 volatile *, __int64); |
| 368 | long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange, |
| 369 | long _Comparand); |
| 370 | unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination, |
| 371 | __int64 _ExchangeHigh, |
| 372 | __int64 _ExchangeLow, |
| 373 | __int64 *_CompareandResult); |
| 374 | unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination, |
| 375 | __int64 _ExchangeHigh, |
| 376 | __int64 _ExchangeLow, |
| 377 | __int64 *_ComparandResult); |
| 378 | short _InterlockedCompareExchange16_np(short volatile *_Destination, |
| 379 | short _Exchange, short _Comparand); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 380 | __int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64, |
| 381 | __int64); |
| 382 | __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, |
| 383 | __int64); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 384 | __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination, |
| 385 | __int64 _Exchange, __int64 _Comparand); |
Eric Christopher | 58b4043 | 2014-01-25 01:38:30 +0000 | [diff] [blame] | 386 | void *_InterlockedCompareExchangePointer(void *volatile *_Destination, |
| 387 | void *_Exchange, void *_Comparand); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 388 | void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination, |
| 389 | void *_Exchange, void *_Comparand); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 390 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 391 | __int64 _InterlockedDecrement64(__int64 volatile *_Addend); |
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 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 394 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 395 | __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value); |
| 396 | void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 397 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 398 | __int64 _InterlockedIncrement64(__int64 volatile *_Addend); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 399 | long _InterlockedOr_np(long volatile *_Value, long _Mask); |
| 400 | short _InterlockedOr16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 401 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 402 | __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask); |
Warren Hunt | 41a993f | 2013-09-28 00:15:41 +0000 | [diff] [blame] | 403 | __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 404 | char _InterlockedOr8_np(char volatile *_Value, char _Mask); |
| 405 | long _InterlockedXor_np(long volatile *_Value, long _Mask); |
| 406 | short _InterlockedXor16_np(short volatile *_Value, short _Mask); |
Reid Kleckner | 924eb2a | 2014-01-27 18:48:02 +0000 | [diff] [blame] | 407 | static __inline__ |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 408 | __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 409 | __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask); |
| 410 | char _InterlockedXor8_np(char volatile *_Value, char _Mask); |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 411 | unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int); |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 412 | __int64 _sarx_i64(__int64, unsigned int); |
Nico Weber | a62cffa | 2014-07-08 18:34:46 +0000 | [diff] [blame] | 413 | #if __STDC_HOSTED__ |
| 414 | int __cdecl _setjmpex(jmp_buf); |
| 415 | #endif |
Eric Christopher | 439137e | 2014-01-24 12:13:47 +0000 | [diff] [blame] | 416 | unsigned __int64 _shlx_u64(unsigned __int64, unsigned int); |
David Majnemer | 5450763 | 2014-12-02 23:30:26 +0000 | [diff] [blame] | 417 | unsigned __int64 _shrx_u64(unsigned __int64, unsigned int); |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 418 | static __inline__ |
| 419 | __int64 __mulh(__int64, __int64); |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 420 | static __inline__ |
| 421 | unsigned __int64 __umulh(unsigned __int64, unsigned __int64); |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 422 | static __inline__ |
| 423 | __int64 _mul128(__int64, __int64, __int64*); |
| 424 | static __inline__ |
| 425 | unsigned __int64 _umul128(unsigned __int64, |
| 426 | unsigned __int64, |
| 427 | unsigned __int64*); |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 428 | |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 429 | #endif /* __x86_64__ */ |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 430 | |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 431 | /*----------------------------------------------------------------------------*\ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 432 | |* Bit Counting and Testing |
| 433 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 434 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 435 | _BitScanForward(unsigned long *_Index, unsigned long _Mask) { |
| 436 | if (!_Mask) |
| 437 | return 0; |
| 438 | *_Index = __builtin_ctzl(_Mask); |
| 439 | return 1; |
| 440 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 441 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 442 | _BitScanReverse(unsigned long *_Index, unsigned long _Mask) { |
| 443 | if (!_Mask) |
| 444 | return 0; |
| 445 | *_Index = 31 - __builtin_clzl(_Mask); |
| 446 | return 1; |
| 447 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 448 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 449 | _bittest(long const *_BitBase, long _BitPos) { |
| 450 | return (*_BitBase >> _BitPos) & 1; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 451 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 452 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 453 | _bittestandcomplement(long *_BitBase, long _BitPos) { |
| 454 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 455 | *_BitBase = *_BitBase ^ (1 << _BitPos); |
| 456 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 457 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 458 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 459 | _bittestandreset(long *_BitBase, long _BitPos) { |
| 460 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 461 | *_BitBase = *_BitBase & ~(1 << _BitPos); |
| 462 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 463 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 464 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 465 | _bittestandset(long *_BitBase, long _BitPos) { |
| 466 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 467 | *_BitBase = *_BitBase | (1 << _BitPos); |
| 468 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 469 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 470 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 471 | _interlockedbittestandset(long volatile *_BitBase, long _BitPos) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 472 | long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST); |
| 473 | return (_PrevVal >> _BitPos) & 1; |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 474 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 475 | #if defined(__arm__) || defined(__aarch64__) |
| 476 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
| 477 | _interlockedbittestandset_acq(long volatile *_BitBase, long _BitPos) { |
| 478 | long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_ACQUIRE); |
| 479 | return (_PrevVal >> _BitPos) & 1; |
| 480 | } |
| 481 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
| 482 | _interlockedbittestandset_nf(long volatile *_BitBase, long _BitPos) { |
| 483 | long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_RELAXED); |
| 484 | return (_PrevVal >> _BitPos) & 1; |
| 485 | } |
| 486 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
| 487 | _interlockedbittestandset_rel(long volatile *_BitBase, long _BitPos) { |
| 488 | long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_RELEASE); |
| 489 | return (_PrevVal >> _BitPos) & 1; |
| 490 | } |
| 491 | #endif |
Warren Hunt | 3f98794 | 2013-09-30 21:08:05 +0000 | [diff] [blame] | 492 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 493 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 494 | _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 495 | if (!_Mask) |
| 496 | return 0; |
| 497 | *_Index = __builtin_ctzll(_Mask); |
| 498 | return 1; |
| 499 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 500 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 501 | _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) { |
| 502 | if (!_Mask) |
| 503 | return 0; |
| 504 | *_Index = 63 - __builtin_clzll(_Mask); |
| 505 | return 1; |
| 506 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 507 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 508 | _bittest64(__int64 const *_BitBase, __int64 _BitPos) { |
| 509 | return (*_BitBase >> _BitPos) & 1; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 510 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 511 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 512 | _bittestandcomplement64(__int64 *_BitBase, __int64 _BitPos) { |
| 513 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 514 | *_BitBase = *_BitBase ^ (1ll << _BitPos); |
| 515 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 516 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 517 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 518 | _bittestandreset64(__int64 *_BitBase, __int64 _BitPos) { |
| 519 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 520 | *_BitBase = *_BitBase & ~(1ll << _BitPos); |
| 521 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 522 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 523 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 524 | _bittestandset64(__int64 *_BitBase, __int64 _BitPos) { |
| 525 | unsigned char _Res = (*_BitBase >> _BitPos) & 1; |
| 526 | *_BitBase = *_BitBase | (1ll << _BitPos); |
| 527 | return _Res; |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 528 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 529 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
David Majnemer | 56e4667 | 2015-07-13 23:38:56 +0000 | [diff] [blame] | 530 | _interlockedbittestandset64(__int64 volatile *_BitBase, __int64 _BitPos) { |
David Majnemer | e0b863f | 2015-07-13 23:39:37 +0000 | [diff] [blame] | 531 | long long _PrevVal = |
| 532 | __atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST); |
| 533 | return (_PrevVal >> _BitPos) & 1; |
Hans Wennborg | a316933 | 2014-03-13 17:05:09 +0000 | [diff] [blame] | 534 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 535 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 536 | /*----------------------------------------------------------------------------*\ |
| 537 | |* Interlocked Exchange Add |
| 538 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 539 | #if defined(__arm__) || defined(__aarch64__) |
| 540 | static __inline__ char __DEFAULT_FN_ATTRS |
| 541 | _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value) { |
| 542 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE); |
| 543 | } |
| 544 | static __inline__ char __DEFAULT_FN_ATTRS |
| 545 | _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value) { |
| 546 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED); |
| 547 | } |
| 548 | static __inline__ char __DEFAULT_FN_ATTRS |
| 549 | _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value) { |
| 550 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED); |
| 551 | } |
| 552 | static __inline__ short __DEFAULT_FN_ATTRS |
| 553 | _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value) { |
| 554 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE); |
| 555 | } |
| 556 | static __inline__ short __DEFAULT_FN_ATTRS |
| 557 | _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value) { |
| 558 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED); |
| 559 | } |
| 560 | static __inline__ short __DEFAULT_FN_ATTRS |
| 561 | _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value) { |
| 562 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE); |
| 563 | } |
| 564 | static __inline__ long __DEFAULT_FN_ATTRS |
| 565 | _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value) { |
| 566 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE); |
| 567 | } |
| 568 | static __inline__ long __DEFAULT_FN_ATTRS |
| 569 | _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value) { |
| 570 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED); |
| 571 | } |
| 572 | static __inline__ long __DEFAULT_FN_ATTRS |
| 573 | _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value) { |
| 574 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE); |
| 575 | } |
| 576 | #endif |
| 577 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 578 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 579 | _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 580 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 581 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 582 | #endif |
| 583 | #if defined(__arm__) || defined(__aarch64__) |
| 584 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 585 | _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value) { |
| 586 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE); |
| 587 | } |
| 588 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 589 | _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value) { |
| 590 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED); |
| 591 | } |
| 592 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 593 | _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value) { |
| 594 | return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE); |
| 595 | } |
| 596 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 597 | /*----------------------------------------------------------------------------*\ |
| 598 | |* Interlocked Exchange Sub |
| 599 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 600 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 601 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 602 | _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 603 | return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 604 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 605 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 606 | /*----------------------------------------------------------------------------*\ |
| 607 | |* Interlocked Increment |
| 608 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 609 | #if defined(__arm__) || defined(__aarch64__) |
| 610 | static __inline__ short __DEFAULT_FN_ATTRS |
| 611 | _InterlockedIncrement16_acq(short volatile *_Value) { |
| 612 | return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 613 | } |
| 614 | static __inline__ short __DEFAULT_FN_ATTRS |
| 615 | _InterlockedIncrement16_nf(short volatile *_Value) { |
| 616 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 617 | } |
| 618 | static __inline__ short __DEFAULT_FN_ATTRS |
| 619 | _InterlockedIncrement16_rel(short volatile *_Value) { |
| 620 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 621 | } |
| 622 | static __inline__ long __DEFAULT_FN_ATTRS |
| 623 | _InterlockedIncrement_acq(long volatile *_Value) { |
| 624 | return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 625 | } |
| 626 | static __inline__ long __DEFAULT_FN_ATTRS |
| 627 | _InterlockedIncrement_nf(long volatile *_Value) { |
| 628 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 629 | } |
| 630 | static __inline__ long __DEFAULT_FN_ATTRS |
| 631 | _InterlockedIncrement_rel(long volatile *_Value) { |
| 632 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 633 | } |
| 634 | #endif |
| 635 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 636 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 637 | _InterlockedIncrement64(__int64 volatile *_Value) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 638 | return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 639 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 640 | #endif |
| 641 | #if defined(__arm__) || defined(__aarch64__) |
| 642 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 643 | _InterlockedIncrement64_acq(__int64 volatile *_Value) { |
| 644 | return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 645 | } |
| 646 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 647 | _InterlockedIncrement64_nf(__int64 volatile *_Value) { |
| 648 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 649 | } |
| 650 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 651 | _InterlockedIncrement64_rel(__int64 volatile *_Value) { |
| 652 | return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 653 | } |
| 654 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 655 | /*----------------------------------------------------------------------------*\ |
| 656 | |* Interlocked Decrement |
| 657 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 658 | #if defined(__arm__) || defined(__aarch64__) |
| 659 | static __inline__ short __DEFAULT_FN_ATTRS |
| 660 | _InterlockedDecrement16_acq(short volatile *_Value) { |
| 661 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 662 | } |
| 663 | static __inline__ short __DEFAULT_FN_ATTRS |
| 664 | _InterlockedDecrement16_nf(short volatile *_Value) { |
| 665 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 666 | } |
| 667 | static __inline__ short __DEFAULT_FN_ATTRS |
| 668 | _InterlockedDecrement16_rel(short volatile *_Value) { |
| 669 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 670 | } |
| 671 | static __inline__ long __DEFAULT_FN_ATTRS |
| 672 | _InterlockedDecrement_acq(long volatile *_Value) { |
| 673 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 674 | } |
| 675 | static __inline__ long __DEFAULT_FN_ATTRS |
| 676 | _InterlockedDecrement_nf(long volatile *_Value) { |
| 677 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 678 | } |
| 679 | static __inline__ long __DEFAULT_FN_ATTRS |
| 680 | _InterlockedDecrement_rel(long volatile *_Value) { |
| 681 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 682 | } |
| 683 | #endif |
| 684 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 685 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 686 | _InterlockedDecrement64(__int64 volatile *_Value) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 687 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 688 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 689 | #endif |
| 690 | #if defined(__arm__) || defined(__aarch64__) |
| 691 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 692 | _InterlockedDecrement64_acq(__int64 volatile *_Value) { |
| 693 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE); |
| 694 | } |
| 695 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 696 | _InterlockedDecrement64_nf(__int64 volatile *_Value) { |
| 697 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED); |
| 698 | } |
| 699 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 700 | _InterlockedDecrement64_rel(__int64 volatile *_Value) { |
| 701 | return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE); |
| 702 | } |
| 703 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 704 | /*----------------------------------------------------------------------------*\ |
| 705 | |* Interlocked And |
| 706 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 707 | #if defined(__arm__) || defined(__aarch64__) |
| 708 | static __inline__ char __DEFAULT_FN_ATTRS |
| 709 | _InterlockedAnd8_acq(char volatile *_Value, char _Mask) { |
| 710 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 711 | } |
| 712 | static __inline__ char __DEFAULT_FN_ATTRS |
| 713 | _InterlockedAnd8_nf(char volatile *_Value, char _Mask) { |
| 714 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED); |
| 715 | } |
| 716 | static __inline__ char __DEFAULT_FN_ATTRS |
| 717 | _InterlockedAnd8_rel(char volatile *_Value, char _Mask) { |
| 718 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE); |
| 719 | } |
| 720 | static __inline__ short __DEFAULT_FN_ATTRS |
| 721 | _InterlockedAnd16_acq(short volatile *_Value, short _Mask) { |
| 722 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 723 | } |
| 724 | static __inline__ short __DEFAULT_FN_ATTRS |
| 725 | _InterlockedAnd16_nf(short volatile *_Value, short _Mask) { |
| 726 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED); |
| 727 | } |
| 728 | static __inline__ short __DEFAULT_FN_ATTRS |
| 729 | _InterlockedAnd16_rel(short volatile *_Value, short _Mask) { |
| 730 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE); |
| 731 | } |
| 732 | static __inline__ long __DEFAULT_FN_ATTRS |
| 733 | _InterlockedAnd_acq(long volatile *_Value, long _Mask) { |
| 734 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 735 | } |
| 736 | static __inline__ long __DEFAULT_FN_ATTRS |
| 737 | _InterlockedAnd_nf(long volatile *_Value, long _Mask) { |
| 738 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED); |
| 739 | } |
| 740 | static __inline__ long __DEFAULT_FN_ATTRS |
| 741 | _InterlockedAnd_rel(long volatile *_Value, long _Mask) { |
| 742 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE); |
| 743 | } |
| 744 | #endif |
| 745 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 746 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 747 | _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 748 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 749 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 750 | #endif |
| 751 | #if defined(__arm__) || defined(__aarch64__) |
| 752 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 753 | _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask) { |
| 754 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 755 | } |
| 756 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 757 | _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask) { |
| 758 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED); |
| 759 | } |
| 760 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 761 | _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask) { |
| 762 | return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE); |
| 763 | } |
| 764 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 765 | /*----------------------------------------------------------------------------*\ |
| 766 | |* Interlocked Or |
| 767 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 768 | #if defined(__arm__) || defined(__aarch64__) |
| 769 | static __inline__ char __DEFAULT_FN_ATTRS |
| 770 | _InterlockedOr8_acq(char volatile *_Value, char _Mask) { |
| 771 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 772 | } |
| 773 | static __inline__ char __DEFAULT_FN_ATTRS |
| 774 | _InterlockedOr8_nf(char volatile *_Value, char _Mask) { |
| 775 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED); |
| 776 | } |
| 777 | static __inline__ char __DEFAULT_FN_ATTRS |
| 778 | _InterlockedOr8_rel(char volatile *_Value, char _Mask) { |
| 779 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE); |
| 780 | } |
| 781 | static __inline__ short __DEFAULT_FN_ATTRS |
| 782 | _InterlockedOr16_acq(short volatile *_Value, short _Mask) { |
| 783 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 784 | } |
| 785 | static __inline__ short __DEFAULT_FN_ATTRS |
| 786 | _InterlockedOr16_nf(short volatile *_Value, short _Mask) { |
| 787 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED); |
| 788 | } |
| 789 | static __inline__ short __DEFAULT_FN_ATTRS |
| 790 | _InterlockedOr16_rel(short volatile *_Value, short _Mask) { |
| 791 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE); |
| 792 | } |
| 793 | static __inline__ long __DEFAULT_FN_ATTRS |
| 794 | _InterlockedOr_acq(long volatile *_Value, long _Mask) { |
| 795 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 796 | } |
| 797 | static __inline__ long __DEFAULT_FN_ATTRS |
| 798 | _InterlockedOr_nf(long volatile *_Value, long _Mask) { |
| 799 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED); |
| 800 | } |
| 801 | static __inline__ long __DEFAULT_FN_ATTRS |
| 802 | _InterlockedOr_rel(long volatile *_Value, long _Mask) { |
| 803 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE); |
| 804 | } |
| 805 | #endif |
| 806 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 807 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 808 | _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 809 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 810 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 811 | #endif |
| 812 | #if defined(__arm__) || defined(__aarch64__) |
| 813 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 814 | _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask) { |
| 815 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 816 | } |
| 817 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 818 | _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask) { |
| 819 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED); |
| 820 | } |
| 821 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 822 | _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask) { |
| 823 | return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE); |
| 824 | } |
| 825 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 826 | /*----------------------------------------------------------------------------*\ |
| 827 | |* Interlocked Xor |
| 828 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 829 | #if defined(__arm__) || defined(__aarch64__) |
| 830 | static __inline__ char __DEFAULT_FN_ATTRS |
| 831 | _InterlockedXor8_acq(char volatile *_Value, char _Mask) { |
| 832 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 833 | } |
| 834 | static __inline__ char __DEFAULT_FN_ATTRS |
| 835 | _InterlockedXor8_nf(char volatile *_Value, char _Mask) { |
| 836 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED); |
| 837 | } |
| 838 | static __inline__ char __DEFAULT_FN_ATTRS |
| 839 | _InterlockedXor8_rel(char volatile *_Value, char _Mask) { |
| 840 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE); |
| 841 | } |
| 842 | static __inline__ short __DEFAULT_FN_ATTRS |
| 843 | _InterlockedXor16_acq(short volatile *_Value, short _Mask) { |
| 844 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 845 | } |
| 846 | static __inline__ short __DEFAULT_FN_ATTRS |
| 847 | _InterlockedXor16_nf(short volatile *_Value, short _Mask) { |
| 848 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED); |
| 849 | } |
| 850 | static __inline__ short __DEFAULT_FN_ATTRS |
| 851 | _InterlockedXor16_rel(short volatile *_Value, short _Mask) { |
| 852 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE); |
| 853 | } |
| 854 | static __inline__ long __DEFAULT_FN_ATTRS |
| 855 | _InterlockedXor_acq(long volatile *_Value, long _Mask) { |
| 856 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 857 | } |
| 858 | static __inline__ long __DEFAULT_FN_ATTRS |
| 859 | _InterlockedXor_nf(long volatile *_Value, long _Mask) { |
| 860 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED); |
| 861 | } |
| 862 | static __inline__ long __DEFAULT_FN_ATTRS |
| 863 | _InterlockedXor_rel(long volatile *_Value, long _Mask) { |
| 864 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE); |
| 865 | } |
| 866 | #endif |
| 867 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 868 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 869 | _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 870 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_SEQ_CST); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 871 | } |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 872 | #endif |
| 873 | #if defined(__arm__) || defined(__aarch64__) |
| 874 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 875 | _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask) { |
| 876 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE); |
| 877 | } |
| 878 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 879 | _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask) { |
| 880 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED); |
| 881 | } |
| 882 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 883 | _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask) { |
| 884 | return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE); |
| 885 | } |
| 886 | #endif |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 887 | /*----------------------------------------------------------------------------*\ |
| 888 | |* Interlocked Exchange |
| 889 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 890 | #if defined(__arm__) || defined(__aarch64__) |
| 891 | static __inline__ char __DEFAULT_FN_ATTRS |
| 892 | _InterlockedExchange8_acq(char volatile *_Target, char _Value) { |
| 893 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE); |
| 894 | return _Value; |
| 895 | } |
| 896 | static __inline__ char __DEFAULT_FN_ATTRS |
| 897 | _InterlockedExchange8_nf(char volatile *_Target, char _Value) { |
| 898 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED); |
| 899 | return _Value; |
| 900 | } |
| 901 | static __inline__ char __DEFAULT_FN_ATTRS |
| 902 | _InterlockedExchange8_rel(char volatile *_Target, char _Value) { |
| 903 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE); |
| 904 | return _Value; |
| 905 | } |
| 906 | static __inline__ short __DEFAULT_FN_ATTRS |
| 907 | _InterlockedExchange16_acq(short volatile *_Target, short _Value) { |
| 908 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE); |
| 909 | return _Value; |
| 910 | } |
| 911 | static __inline__ short __DEFAULT_FN_ATTRS |
| 912 | _InterlockedExchange16_nf(short volatile *_Target, short _Value) { |
| 913 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED); |
| 914 | return _Value; |
| 915 | } |
| 916 | static __inline__ short __DEFAULT_FN_ATTRS |
| 917 | _InterlockedExchange16_rel(short volatile *_Target, short _Value) { |
| 918 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE); |
| 919 | return _Value; |
| 920 | } |
| 921 | static __inline__ long __DEFAULT_FN_ATTRS |
| 922 | _InterlockedExchange_acq(long volatile *_Target, long _Value) { |
| 923 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE); |
| 924 | return _Value; |
| 925 | } |
| 926 | static __inline__ long __DEFAULT_FN_ATTRS |
| 927 | _InterlockedExchange_nf(long volatile *_Target, long _Value) { |
| 928 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED); |
| 929 | return _Value; |
| 930 | } |
| 931 | static __inline__ long __DEFAULT_FN_ATTRS |
| 932 | _InterlockedExchange_rel(long volatile *_Target, long _Value) { |
| 933 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE); |
| 934 | return _Value; |
| 935 | } |
| 936 | #endif |
| 937 | #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 938 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 939 | _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) { |
Martin Storsjo | 963f75e | 2016-09-28 09:34:51 +0000 | [diff] [blame] | 940 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); |
| 941 | return _Value; |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 942 | } |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 943 | #endif |
Saleem Abdulrasool | eae64f8 | 2016-09-26 22:12:43 +0000 | [diff] [blame] | 944 | #if defined(__arm__) || defined(__aarch64__) |
| 945 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 946 | _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value) { |
| 947 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE); |
| 948 | return _Value; |
| 949 | } |
| 950 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 951 | _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value) { |
| 952 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED); |
| 953 | return _Value; |
| 954 | } |
| 955 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 956 | _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value) { |
| 957 | __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE); |
| 958 | return _Value; |
| 959 | } |
| 960 | #endif |
| 961 | /*----------------------------------------------------------------------------*\ |
| 962 | |* Interlocked Compare Exchange |
| 963 | \*----------------------------------------------------------------------------*/ |
| 964 | #if defined(__arm__) || defined(__aarch64__) |
| 965 | static __inline__ char __DEFAULT_FN_ATTRS |
| 966 | _InterlockedCompareExchange8_acq(char volatile *_Destination, |
| 967 | char _Exchange, char _Comparand) { |
| 968 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 969 | __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE); |
| 970 | return _Comparand; |
| 971 | } |
| 972 | static __inline__ char __DEFAULT_FN_ATTRS |
| 973 | _InterlockedCompareExchange8_nf(char volatile *_Destination, |
| 974 | char _Exchange, char _Comparand) { |
| 975 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 976 | __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); |
| 977 | return _Comparand; |
| 978 | } |
| 979 | static __inline__ char __DEFAULT_FN_ATTRS |
| 980 | _InterlockedCompareExchange8_rel(char volatile *_Destination, |
| 981 | char _Exchange, char _Comparand) { |
| 982 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 983 | __ATOMIC_SEQ_CST, __ATOMIC_RELEASE); |
| 984 | return _Comparand; |
| 985 | } |
| 986 | static __inline__ short __DEFAULT_FN_ATTRS |
| 987 | _InterlockedCompareExchange16_acq(short volatile *_Destination, |
| 988 | short _Exchange, short _Comparand) { |
| 989 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 990 | __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE); |
| 991 | return _Comparand; |
| 992 | } |
| 993 | static __inline__ short __DEFAULT_FN_ATTRS |
| 994 | _InterlockedCompareExchange16_nf(short volatile *_Destination, |
| 995 | short _Exchange, short _Comparand) { |
| 996 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 997 | __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); |
| 998 | return _Comparand; |
| 999 | } |
| 1000 | static __inline__ short __DEFAULT_FN_ATTRS |
| 1001 | _InterlockedCompareExchange16_rel(short volatile *_Destination, |
| 1002 | short _Exchange, short _Comparand) { |
| 1003 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1004 | __ATOMIC_SEQ_CST, __ATOMIC_RELEASE); |
| 1005 | return _Comparand; |
| 1006 | } |
| 1007 | static __inline__ long __DEFAULT_FN_ATTRS |
| 1008 | _InterlockedCompareExchange_acq(long volatile *_Destination, |
| 1009 | long _Exchange, long _Comparand) { |
| 1010 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1011 | __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE); |
| 1012 | return _Comparand; |
| 1013 | } |
| 1014 | static __inline__ long __DEFAULT_FN_ATTRS |
| 1015 | _InterlockedCompareExchange_nf(long volatile *_Destination, |
| 1016 | long _Exchange, long _Comparand) { |
| 1017 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1018 | __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); |
| 1019 | return _Comparand; |
| 1020 | } |
| 1021 | static __inline__ short __DEFAULT_FN_ATTRS |
| 1022 | _InterlockedCompareExchange_rel(long volatile *_Destination, |
| 1023 | long _Exchange, long _Comparand) { |
| 1024 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1025 | __ATOMIC_SEQ_CST, __ATOMIC_RELEASE); |
| 1026 | return _Comparand; |
| 1027 | } |
| 1028 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 1029 | _InterlockedCompareExchange64_acq(__int64 volatile *_Destination, |
| 1030 | __int64 _Exchange, __int64 _Comparand) { |
| 1031 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1032 | __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE); |
| 1033 | return _Comparand; |
| 1034 | } |
| 1035 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 1036 | _InterlockedCompareExchange64_nf(__int64 volatile *_Destination, |
| 1037 | __int64 _Exchange, __int64 _Comparand) { |
| 1038 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1039 | __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); |
| 1040 | return _Comparand; |
| 1041 | } |
| 1042 | static __inline__ __int64 __DEFAULT_FN_ATTRS |
| 1043 | _InterlockedCompareExchange64_rel(__int64 volatile *_Destination, |
| 1044 | __int64 _Exchange, __int64 _Comparand) { |
| 1045 | __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, |
| 1046 | __ATOMIC_SEQ_CST, __ATOMIC_RELEASE); |
| 1047 | return _Comparand; |
| 1048 | } |
| 1049 | #endif |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 1050 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1051 | |* readfs, readgs |
| 1052 | |* (Pointers in address space #256 and #257 are relative to the GS and FS |
| 1053 | |* segment registers, respectively.) |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1054 | \*----------------------------------------------------------------------------*/ |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1055 | #define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \ |
| 1056 | ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \ |
| 1057 | (__offset)) |
| 1058 | |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1059 | #ifdef __i386__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1060 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1061 | __readfsbyte(unsigned long __offset) { |
| 1062 | return *__ptr_to_addr_space(257, unsigned char, __offset); |
| 1063 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1064 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1065 | __readfsword(unsigned long __offset) { |
| 1066 | return *__ptr_to_addr_space(257, unsigned short, __offset); |
| 1067 | } |
David Majnemer | b2c5720 | 2016-05-27 02:06:14 +0000 | [diff] [blame] | 1068 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
| 1069 | __readfsqword(unsigned long __offset) { |
| 1070 | return *__ptr_to_addr_space(257, unsigned __int64, __offset); |
| 1071 | } |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1072 | #endif |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1073 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1074 | static __inline__ unsigned char __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1075 | __readgsbyte(unsigned long __offset) { |
| 1076 | return *__ptr_to_addr_space(256, unsigned char, __offset); |
| 1077 | } |
David Majnemer | b2c5720 | 2016-05-27 02:06:14 +0000 | [diff] [blame] | 1078 | static __inline__ unsigned short __DEFAULT_FN_ATTRS |
| 1079 | __readgsword(unsigned long __offset) { |
| 1080 | return *__ptr_to_addr_space(256, unsigned short, __offset); |
| 1081 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1082 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1083 | __readgsdword(unsigned long __offset) { |
| 1084 | return *__ptr_to_addr_space(256, unsigned long, __offset); |
| 1085 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1086 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1087 | __readgsqword(unsigned long __offset) { |
| 1088 | return *__ptr_to_addr_space(256, unsigned __int64, __offset); |
| 1089 | } |
Hans Wennborg | a4421e0 | 2014-03-12 21:09:05 +0000 | [diff] [blame] | 1090 | #endif |
| 1091 | #undef __ptr_to_addr_space |
Hans Wennborg | 74ca0c4 | 2014-01-24 00:52:39 +0000 | [diff] [blame] | 1092 | /*----------------------------------------------------------------------------*\ |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1093 | |* movs, stos |
| 1094 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1095 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1096 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1097 | __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) { |
| 1098 | __asm__("rep movsb" : : "D"(__dst), "S"(__src), "c"(__n) |
| 1099 | : "%edi", "%esi", "%ecx"); |
| 1100 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1101 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1102 | __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) { |
| 1103 | __asm__("rep movsl" : : "D"(__dst), "S"(__src), "c"(__n) |
| 1104 | : "%edi", "%esi", "%ecx"); |
| 1105 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1106 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1107 | __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) { |
Nico Weber | 1f22a34 | 2015-09-22 00:46:21 +0000 | [diff] [blame] | 1108 | __asm__("rep movsw" : : "D"(__dst), "S"(__src), "c"(__n) |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1109 | : "%edi", "%esi", "%ecx"); |
| 1110 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1111 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1112 | __stosb(unsigned char *__dst, unsigned char __x, size_t __n) { |
| 1113 | __asm__("rep stosb" : : "D"(__dst), "a"(__x), "c"(__n) |
| 1114 | : "%edi", "%ecx"); |
| 1115 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1116 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1117 | __stosd(unsigned long *__dst, unsigned long __x, size_t __n) { |
| 1118 | __asm__("rep stosl" : : "D"(__dst), "a"(__x), "c"(__n) |
| 1119 | : "%edi", "%ecx"); |
| 1120 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1121 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1122 | __stosw(unsigned short *__dst, unsigned short __x, size_t __n) { |
Nico Weber | 1f22a34 | 2015-09-22 00:46:21 +0000 | [diff] [blame] | 1123 | __asm__("rep stosw" : : "D"(__dst), "a"(__x), "c"(__n) |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1124 | : "%edi", "%ecx"); |
| 1125 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1126 | #endif |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1127 | #ifdef __x86_64__ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1128 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1129 | __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) { |
| 1130 | __asm__("rep movsq" : : "D"(__dst), "S"(__src), "c"(__n) |
| 1131 | : "%edi", "%esi", "%ecx"); |
| 1132 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1133 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | d9be72e | 2014-03-12 22:00:32 +0000 | [diff] [blame] | 1134 | __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) { |
| 1135 | __asm__("rep stosq" : : "D"(__dst), "a"(__x), "c"(__n) |
| 1136 | : "%edi", "%ecx"); |
| 1137 | } |
| 1138 | #endif |
| 1139 | |
| 1140 | /*----------------------------------------------------------------------------*\ |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 1141 | |* Misc |
| 1142 | \*----------------------------------------------------------------------------*/ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1143 | static __inline__ void * __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 1144 | _AddressOfReturnAddress(void) { |
| 1145 | return (void*)((char*)__builtin_frame_address(0) + sizeof(void*)); |
| 1146 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1147 | static __inline__ void * __DEFAULT_FN_ATTRS |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 1148 | _ReturnAddress(void) { |
| 1149 | return __builtin_return_address(0); |
| 1150 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1151 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1152 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 1153 | __cpuid(int __info[4], int __level) { |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 1154 | __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] | 1155 | : "a"(__level)); |
| 1156 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1157 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 12fb89e | 2014-01-31 19:44:55 +0000 | [diff] [blame] | 1158 | __cpuidex(int __info[4], int __level, int __ecx) { |
| 1159 | __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) |
| 1160 | : "a"(__level), "c"(__ecx)); |
Hans Wennborg | 854f7d3 | 2014-01-16 23:39:35 +0000 | [diff] [blame] | 1161 | } |
Reid Kleckner | 66e7717 | 2016-08-16 16:04:14 +0000 | [diff] [blame] | 1162 | static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS |
| 1163 | _xgetbv(unsigned int __xcr_no) { |
| 1164 | unsigned int __eax, __edx; |
| 1165 | __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no)); |
| 1166 | return ((unsigned __int64)__edx << 32) | __eax; |
| 1167 | } |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1168 | static __inline__ void __DEFAULT_FN_ATTRS |
Hans Wennborg | 740a4d6 | 2014-01-28 22:55:01 +0000 | [diff] [blame] | 1169 | __halt(void) { |
| 1170 | __asm__ volatile ("hlt"); |
| 1171 | } |
Reid Kleckner | 5de2bcd | 2016-09-07 16:55:12 +0000 | [diff] [blame] | 1172 | static __inline__ void __DEFAULT_FN_ATTRS |
| 1173 | __nop(void) { |
| 1174 | __asm__ volatile ("nop"); |
| 1175 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1176 | #endif |
Warren Hunt | d6ffae9 | 2013-09-27 23:57:26 +0000 | [diff] [blame] | 1177 | |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1178 | /*----------------------------------------------------------------------------*\ |
| 1179 | |* Privileged intrinsics |
| 1180 | \*----------------------------------------------------------------------------*/ |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1181 | #if defined(__i386__) || defined(__x86_64__) |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1182 | static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1183 | __readmsr(unsigned long __register) { |
| 1184 | // Loads the contents of a 64-bit model specific register (MSR) specified in |
| 1185 | // the ECX register into registers EDX:EAX. The EDX register is loaded with |
| 1186 | // the high-order 32 bits of the MSR and the EAX register is loaded with the |
| 1187 | // low-order 32 bits. If less than 64 bits are implemented in the MSR being |
| 1188 | // read, the values returned to EDX:EAX in unimplemented bit locations are |
| 1189 | // undefined. |
| 1190 | unsigned long __edx; |
| 1191 | unsigned long __eax; |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 1192 | __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register)); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1193 | return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax; |
| 1194 | } |
| 1195 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1196 | static __inline__ unsigned long __DEFAULT_FN_ATTRS |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1197 | __readcr3(void) { |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 1198 | unsigned long __cr3_val; |
| 1199 | __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory"); |
| 1200 | return __cr3_val; |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1203 | static __inline__ void __DEFAULT_FN_ATTRS |
Reid Kleckner | 6df5254 | 2014-04-08 17:49:16 +0000 | [diff] [blame] | 1204 | __writecr3(unsigned int __cr3_val) { |
| 1205 | __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory"); |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1206 | } |
Saleem Abdulrasool | 702eefe | 2014-06-25 16:48:40 +0000 | [diff] [blame] | 1207 | #endif |
Reid Kleckner | 592dc61 | 2014-04-08 00:28:22 +0000 | [diff] [blame] | 1208 | |
Eric Christopher | cc87253 | 2013-09-18 22:40:18 +0000 | [diff] [blame] | 1209 | #ifdef __cplusplus |
Eric Christopher | 0db88a7 | 2013-09-18 22:24:01 +0000 | [diff] [blame] | 1210 | } |
Eric Christopher | d1428bf | 2013-08-31 00:22:48 +0000 | [diff] [blame] | 1211 | #endif |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 1212 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 1213 | #undef __DEFAULT_FN_ATTRS |
Eric Christopher | 5a9bec1 | 2015-06-15 23:20:35 +0000 | [diff] [blame] | 1214 | |
Reid Kleckner | f0e2322 | 2013-09-19 00:19:53 +0000 | [diff] [blame] | 1215 | #endif /* __INTRIN_H */ |
| 1216 | #endif /* _MSC_VER */ |