1 /* ===-------- intrin.h ---------------------------------------------------===
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  *
21  *===-----------------------------------------------------------------------===
22  */
23 
24 /* Only include this if we're compiling for the windows platform. */
25 #ifndef _MSC_VER
26 #include_next <intrin.h>
27 #else
28 
29 #ifndef __INTRIN_H
30 #define __INTRIN_H
31 
32 /* First include the standard intrinsics. */
33 #if defined(__i386__) || defined(__x86_64__)
34 #include <x86intrin.h>
35 #endif
36 
37 #if defined(__arm__)
38 #include <armintr.h>
39 #endif
40 
41 #if defined(__aarch64__)
42 #include <arm64intr.h>
43 #endif
44 
45 /* For the definition of jmp_buf. */
46 #if __STDC_HOSTED__
47 #include <setjmp.h>
48 #endif
49 
50 /* Define the default attributes for the functions in this file. */
51 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 #if defined(__MMX__)
58 /* And the random ones that aren't in those files. */
59 __m64 _m_from_float(float);
60 float _m_to_float(__m64);
61 #endif
62 
63 /* Other assorted instruction intrinsics. */
64 void __addfsbyte(unsigned long, unsigned char);
65 void __addfsdword(unsigned long, unsigned long);
66 void __addfsword(unsigned long, unsigned short);
67 void __code_seg(const char *);
68 static __inline__
69 void __cpuid(int[4], int);
70 static __inline__
71 void __cpuidex(int[4], int, int);
72 static __inline__
73 __int64 __emul(int, int);
74 static __inline__
75 unsigned __int64 __emulu(unsigned int, unsigned int);
76 unsigned int __getcallerseflags(void);
77 static __inline__
78 void __halt(void);
79 unsigned char __inbyte(unsigned short);
80 void __inbytestring(unsigned short, unsigned char *, unsigned long);
81 void __incfsbyte(unsigned long);
82 void __incfsdword(unsigned long);
83 void __incfsword(unsigned long);
84 unsigned long __indword(unsigned short);
85 void __indwordstring(unsigned short, unsigned long *, unsigned long);
86 void __int2c(void);
87 void __invlpg(void *);
88 unsigned short __inword(unsigned short);
89 void __inwordstring(unsigned short, unsigned short *, unsigned long);
90 void __lidt(void *);
91 unsigned __int64 __ll_lshift(unsigned __int64, int);
92 __int64 __ll_rshift(__int64, int);
93 unsigned int __lzcnt(unsigned int);
94 unsigned short __lzcnt16(unsigned short);
95 static __inline__
96 void __movsb(unsigned char *, unsigned char const *, size_t);
97 static __inline__
98 void __movsd(unsigned long *, unsigned long const *, size_t);
99 static __inline__
100 void __movsw(unsigned short *, unsigned short const *, size_t);
101 static __inline__
102 void __nop(void);
103 void __nvreg_restore_fence(void);
104 void __nvreg_save_fence(void);
105 void __outbyte(unsigned short, unsigned char);
106 void __outbytestring(unsigned short, unsigned char *, unsigned long);
107 void __outdword(unsigned short, unsigned long);
108 void __outdwordstring(unsigned short, unsigned long *, unsigned long);
109 void __outword(unsigned short, unsigned short);
110 void __outwordstring(unsigned short, unsigned short *, unsigned long);
111 unsigned long __readcr0(void);
112 unsigned long __readcr2(void);
113 static __inline__
114 unsigned long __readcr3(void);
115 unsigned long __readcr4(void);
116 unsigned long __readcr8(void);
117 unsigned int __readdr(unsigned int);
118 #ifdef __i386__
119 static __inline__
120 unsigned char __readfsbyte(unsigned long);
121 static __inline__
122 unsigned __int64 __readfsqword(unsigned long);
123 static __inline__
124 unsigned short __readfsword(unsigned long);
125 #endif
126 static __inline__
127 unsigned __int64 __readmsr(unsigned long);
128 unsigned __int64 __readpmc(unsigned long);
129 unsigned long __segmentlimit(unsigned long);
130 void __sidt(void *);
131 static __inline__
132 void __stosb(unsigned char *, unsigned char, size_t);
133 static __inline__
134 void __stosd(unsigned long *, unsigned long, size_t);
135 static __inline__
136 void __stosw(unsigned short *, unsigned short, size_t);
137 void __svm_clgi(void);
138 void __svm_invlpga(void *, int);
139 void __svm_skinit(int);
140 void __svm_stgi(void);
141 void __svm_vmload(size_t);
142 void __svm_vmrun(size_t);
143 void __svm_vmsave(size_t);
144 void __ud2(void);
145 unsigned __int64 __ull_rshift(unsigned __int64, int);
146 void __vmx_off(void);
147 void __vmx_vmptrst(unsigned __int64 *);
148 void __wbinvd(void);
149 void __writecr0(unsigned int);
150 static __inline__
151 void __writecr3(unsigned int);
152 void __writecr4(unsigned int);
153 void __writecr8(unsigned int);
154 void __writedr(unsigned int, unsigned int);
155 void __writefsbyte(unsigned long, unsigned char);
156 void __writefsdword(unsigned long, unsigned long);
157 void __writefsqword(unsigned long, unsigned __int64);
158 void __writefsword(unsigned long, unsigned short);
159 void __writemsr(unsigned long, unsigned __int64);
160 static __inline__
161 void *_AddressOfReturnAddress(void);
162 static __inline__
163 unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
164 static __inline__
165 unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
166 unsigned char _bittest(long const *, long);
167 unsigned char _bittestandcomplement(long *, long);
168 unsigned char _bittestandreset(long *, long);
169 unsigned char _bittestandset(long *, long);
170 void __cdecl _disable(void);
171 void __cdecl _enable(void);
172 long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
173 unsigned char _interlockedbittestandreset(long volatile *, long);
174 unsigned char _interlockedbittestandset(long volatile *, long);
175 void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
176                                                     void *);
177 void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
178                                                     void *);
179 long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
180 long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
181 __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
182 __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
183 void __cdecl _invpcid(unsigned int, void *);
184 static __inline__ void
185 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
186 _ReadBarrier(void);
187 static __inline__ void
188 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
189 _ReadWriteBarrier(void);
190 unsigned int _rorx_u32(unsigned int, const unsigned int);
191 int _sarx_i32(int, unsigned int);
192 #if __STDC_HOSTED__
193 int __cdecl _setjmp(jmp_buf);
194 #endif
195 unsigned int _shlx_u32(unsigned int, unsigned int);
196 unsigned int _shrx_u32(unsigned int, unsigned int);
197 void _Store_HLERelease(long volatile *, long);
198 void _Store64_HLERelease(__int64 volatile *, __int64);
199 void _StorePointer_HLERelease(void *volatile *, void *);
200 static __inline__ void
201 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
202 _WriteBarrier(void);
203 unsigned __int32 xbegin(void);
204 void _xend(void);
205 static __inline__
206 #define _XCR_XFEATURE_ENABLED_MASK 0
207 unsigned __int64 __cdecl _xgetbv(unsigned int);
208 void __cdecl _xsetbv(unsigned int, unsigned __int64);
209 
210 /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
211 #ifdef __x86_64__
212 void __addgsbyte(unsigned long, unsigned char);
213 void __addgsdword(unsigned long, unsigned long);
214 void __addgsqword(unsigned long, unsigned __int64);
215 void __addgsword(unsigned long, unsigned short);
216 static __inline__
217 void __faststorefence(void);
218 void __incgsbyte(unsigned long);
219 void __incgsdword(unsigned long);
220 void __incgsqword(unsigned long);
221 void __incgsword(unsigned long);
222 unsigned __int64 __lzcnt64(unsigned __int64);
223 static __inline__
224 void __movsq(unsigned long long *, unsigned long long const *, size_t);
225 static __inline__
226 unsigned char __readgsbyte(unsigned long);
227 static __inline__
228 unsigned long __readgsdword(unsigned long);
229 static __inline__
230 unsigned __int64 __readgsqword(unsigned long);
231 unsigned short __readgsword(unsigned long);
232 unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
233                                 unsigned __int64 _HighPart,
234                                 unsigned char _Shift);
235 unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
236                                  unsigned __int64 _HighPart,
237                                  unsigned char _Shift);
238 static __inline__
239 void __stosq(unsigned __int64 *, unsigned __int64, size_t);
240 unsigned char __vmx_on(unsigned __int64 *);
241 unsigned char __vmx_vmclear(unsigned __int64 *);
242 unsigned char __vmx_vmlaunch(void);
243 unsigned char __vmx_vmptrld(unsigned __int64 *);
244 unsigned char __vmx_vmread(size_t, size_t *);
245 unsigned char __vmx_vmresume(void);
246 unsigned char __vmx_vmwrite(size_t, size_t);
247 void __writegsbyte(unsigned long, unsigned char);
248 void __writegsdword(unsigned long, unsigned long);
249 void __writegsqword(unsigned long, unsigned __int64);
250 void __writegsword(unsigned long, unsigned short);
251 unsigned char _bittest64(__int64 const *, __int64);
252 unsigned char _bittestandcomplement64(__int64 *, __int64);
253 unsigned char _bittestandreset64(__int64 *, __int64);
254 unsigned char _bittestandset64(__int64 *, __int64);
255 long _InterlockedAnd_np(long volatile *_Value, long _Mask);
256 short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
257 __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
258 char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
259 unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
260 unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
261 long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
262                                     long _Comparand);
263 unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
264                                              __int64 _ExchangeHigh,
265                                              __int64 _ExchangeLow,
266                                              __int64 *_CompareandResult);
267 unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
268                                                 __int64 _ExchangeHigh,
269                                                 __int64 _ExchangeLow,
270                                                 __int64 *_ComparandResult);
271 short _InterlockedCompareExchange16_np(short volatile *_Destination,
272                                        short _Exchange, short _Comparand);
273 __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
274                                          __int64 _Exchange, __int64 _Comparand);
275 void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
276                                             void *_Exchange, void *_Comparand);
277 long _InterlockedOr_np(long volatile *_Value, long _Mask);
278 short _InterlockedOr16_np(short volatile *_Value, short _Mask);
279 __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
280 char _InterlockedOr8_np(char volatile *_Value, char _Mask);
281 long _InterlockedXor_np(long volatile *_Value, long _Mask);
282 short _InterlockedXor16_np(short volatile *_Value, short _Mask);
283 __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
284 char _InterlockedXor8_np(char volatile *_Value, char _Mask);
285 unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
286 __int64 _sarx_i64(__int64, unsigned int);
287 unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
288 unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
289 static __inline__
290 __int64 __mulh(__int64, __int64);
291 static __inline__
292 unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
293 static __inline__
294 __int64 _mul128(__int64, __int64, __int64*);
295 static __inline__
296 unsigned __int64 _umul128(unsigned __int64,
297                           unsigned __int64,
298                           unsigned __int64*);
299 
300 #endif /* __x86_64__ */
301 
302 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
303 
304 static __inline__
305 unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
306 static __inline__
307 unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
308 
309 static __inline__
310 __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
311 static __inline__
312 __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
313 static __inline__
314 __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
315 static __inline__
316 __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
317 static __inline__
318 __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
319 static __inline__
320 __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
321 static __inline__
322 __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
323 static __inline__
324 __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
325 
326 #endif
327 
328 /*----------------------------------------------------------------------------*\
329 |* Interlocked Exchange Add
330 \*----------------------------------------------------------------------------*/
331 #if defined(__arm__) || defined(__aarch64__)
332 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd8_acq(char volatile * _Addend,char _Value)333 _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value) {
334   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
335 }
336 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd8_nf(char volatile * _Addend,char _Value)337 _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value) {
338   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
339 }
340 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd8_rel(char volatile * _Addend,char _Value)341 _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value) {
342   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
343 }
344 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd16_acq(short volatile * _Addend,short _Value)345 _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value) {
346   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
347 }
348 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd16_nf(short volatile * _Addend,short _Value)349 _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value) {
350   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
351 }
352 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd16_rel(short volatile * _Addend,short _Value)353 _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value) {
354   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE);
355 }
356 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd_acq(long volatile * _Addend,long _Value)357 _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value) {
358   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
359 }
360 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd_nf(long volatile * _Addend,long _Value)361 _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value) {
362   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
363 }
364 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd_rel(long volatile * _Addend,long _Value)365 _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value) {
366   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE);
367 }
368 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd64_acq(__int64 volatile * _Addend,__int64 _Value)369 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value) {
370   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
371 }
372 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd64_nf(__int64 volatile * _Addend,__int64 _Value)373 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value) {
374   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
375 }
376 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchangeAdd64_rel(__int64 volatile * _Addend,__int64 _Value)377 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value) {
378   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE);
379 }
380 #endif
381 /*----------------------------------------------------------------------------*\
382 |* Interlocked Increment
383 \*----------------------------------------------------------------------------*/
384 #if defined(__arm__) || defined(__aarch64__)
385 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedIncrement16_acq(short volatile * _Value)386 _InterlockedIncrement16_acq(short volatile *_Value) {
387   return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE);
388 }
389 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedIncrement16_nf(short volatile * _Value)390 _InterlockedIncrement16_nf(short volatile *_Value) {
391   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED);
392 }
393 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedIncrement16_rel(short volatile * _Value)394 _InterlockedIncrement16_rel(short volatile *_Value) {
395   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE);
396 }
397 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedIncrement_acq(long volatile * _Value)398 _InterlockedIncrement_acq(long volatile *_Value) {
399   return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE);
400 }
401 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedIncrement_nf(long volatile * _Value)402 _InterlockedIncrement_nf(long volatile *_Value) {
403   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED);
404 }
405 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedIncrement_rel(long volatile * _Value)406 _InterlockedIncrement_rel(long volatile *_Value) {
407   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE);
408 }
409 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedIncrement64_acq(__int64 volatile * _Value)410 _InterlockedIncrement64_acq(__int64 volatile *_Value) {
411   return __atomic_add_fetch(_Value, 1, __ATOMIC_ACQUIRE);
412 }
413 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedIncrement64_nf(__int64 volatile * _Value)414 _InterlockedIncrement64_nf(__int64 volatile *_Value) {
415   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELAXED);
416 }
417 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedIncrement64_rel(__int64 volatile * _Value)418 _InterlockedIncrement64_rel(__int64 volatile *_Value) {
419   return __atomic_add_fetch(_Value, 1, __ATOMIC_RELEASE);
420 }
421 #endif
422 /*----------------------------------------------------------------------------*\
423 |* Interlocked Decrement
424 \*----------------------------------------------------------------------------*/
425 #if defined(__arm__) || defined(__aarch64__)
426 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedDecrement16_acq(short volatile * _Value)427 _InterlockedDecrement16_acq(short volatile *_Value) {
428   return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE);
429 }
430 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedDecrement16_nf(short volatile * _Value)431 _InterlockedDecrement16_nf(short volatile *_Value) {
432   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED);
433 }
434 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedDecrement16_rel(short volatile * _Value)435 _InterlockedDecrement16_rel(short volatile *_Value) {
436   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE);
437 }
438 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedDecrement_acq(long volatile * _Value)439 _InterlockedDecrement_acq(long volatile *_Value) {
440   return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE);
441 }
442 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedDecrement_nf(long volatile * _Value)443 _InterlockedDecrement_nf(long volatile *_Value) {
444   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED);
445 }
446 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedDecrement_rel(long volatile * _Value)447 _InterlockedDecrement_rel(long volatile *_Value) {
448   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE);
449 }
450 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedDecrement64_acq(__int64 volatile * _Value)451 _InterlockedDecrement64_acq(__int64 volatile *_Value) {
452   return __atomic_sub_fetch(_Value, 1, __ATOMIC_ACQUIRE);
453 }
454 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedDecrement64_nf(__int64 volatile * _Value)455 _InterlockedDecrement64_nf(__int64 volatile *_Value) {
456   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELAXED);
457 }
458 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedDecrement64_rel(__int64 volatile * _Value)459 _InterlockedDecrement64_rel(__int64 volatile *_Value) {
460   return __atomic_sub_fetch(_Value, 1, __ATOMIC_RELEASE);
461 }
462 #endif
463 /*----------------------------------------------------------------------------*\
464 |* Interlocked And
465 \*----------------------------------------------------------------------------*/
466 #if defined(__arm__) || defined(__aarch64__)
467 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedAnd8_acq(char volatile * _Value,char _Mask)468 _InterlockedAnd8_acq(char volatile *_Value, char _Mask) {
469   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE);
470 }
471 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedAnd8_nf(char volatile * _Value,char _Mask)472 _InterlockedAnd8_nf(char volatile *_Value, char _Mask) {
473   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED);
474 }
475 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedAnd8_rel(char volatile * _Value,char _Mask)476 _InterlockedAnd8_rel(char volatile *_Value, char _Mask) {
477   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE);
478 }
479 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedAnd16_acq(short volatile * _Value,short _Mask)480 _InterlockedAnd16_acq(short volatile *_Value, short _Mask) {
481   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE);
482 }
483 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedAnd16_nf(short volatile * _Value,short _Mask)484 _InterlockedAnd16_nf(short volatile *_Value, short _Mask) {
485   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED);
486 }
487 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedAnd16_rel(short volatile * _Value,short _Mask)488 _InterlockedAnd16_rel(short volatile *_Value, short _Mask) {
489   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE);
490 }
491 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedAnd_acq(long volatile * _Value,long _Mask)492 _InterlockedAnd_acq(long volatile *_Value, long _Mask) {
493   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE);
494 }
495 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedAnd_nf(long volatile * _Value,long _Mask)496 _InterlockedAnd_nf(long volatile *_Value, long _Mask) {
497   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED);
498 }
499 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedAnd_rel(long volatile * _Value,long _Mask)500 _InterlockedAnd_rel(long volatile *_Value, long _Mask) {
501   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE);
502 }
503 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedAnd64_acq(__int64 volatile * _Value,__int64 _Mask)504 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask) {
505   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_ACQUIRE);
506 }
507 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedAnd64_nf(__int64 volatile * _Value,__int64 _Mask)508 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask) {
509   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELAXED);
510 }
511 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedAnd64_rel(__int64 volatile * _Value,__int64 _Mask)512 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask) {
513   return __atomic_fetch_and(_Value, _Mask, __ATOMIC_RELEASE);
514 }
515 #endif
516 /*----------------------------------------------------------------------------*\
517 |* Bit Counting and Testing
518 \*----------------------------------------------------------------------------*/
519 #if defined(__arm__) || defined(__aarch64__)
520 unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
521                                             long _BitPos);
522 unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
523                                            long _BitPos);
524 unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
525                                             long _BitPos);
526 unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
527                                               long _BitPos);
528 unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
529                                              long _BitPos);
530 unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
531                                               long _BitPos);
532 #endif
533 /*----------------------------------------------------------------------------*\
534 |* Interlocked Or
535 \*----------------------------------------------------------------------------*/
536 #if defined(__arm__) || defined(__aarch64__)
537 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedOr8_acq(char volatile * _Value,char _Mask)538 _InterlockedOr8_acq(char volatile *_Value, char _Mask) {
539   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE);
540 }
541 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedOr8_nf(char volatile * _Value,char _Mask)542 _InterlockedOr8_nf(char volatile *_Value, char _Mask) {
543   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED);
544 }
545 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedOr8_rel(char volatile * _Value,char _Mask)546 _InterlockedOr8_rel(char volatile *_Value, char _Mask) {
547   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE);
548 }
549 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedOr16_acq(short volatile * _Value,short _Mask)550 _InterlockedOr16_acq(short volatile *_Value, short _Mask) {
551   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE);
552 }
553 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedOr16_nf(short volatile * _Value,short _Mask)554 _InterlockedOr16_nf(short volatile *_Value, short _Mask) {
555   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED);
556 }
557 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedOr16_rel(short volatile * _Value,short _Mask)558 _InterlockedOr16_rel(short volatile *_Value, short _Mask) {
559   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE);
560 }
561 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedOr_acq(long volatile * _Value,long _Mask)562 _InterlockedOr_acq(long volatile *_Value, long _Mask) {
563   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE);
564 }
565 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedOr_nf(long volatile * _Value,long _Mask)566 _InterlockedOr_nf(long volatile *_Value, long _Mask) {
567   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED);
568 }
569 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedOr_rel(long volatile * _Value,long _Mask)570 _InterlockedOr_rel(long volatile *_Value, long _Mask) {
571   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE);
572 }
573 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedOr64_acq(__int64 volatile * _Value,__int64 _Mask)574 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask) {
575   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_ACQUIRE);
576 }
577 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedOr64_nf(__int64 volatile * _Value,__int64 _Mask)578 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask) {
579   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELAXED);
580 }
581 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedOr64_rel(__int64 volatile * _Value,__int64 _Mask)582 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask) {
583   return __atomic_fetch_or(_Value, _Mask, __ATOMIC_RELEASE);
584 }
585 #endif
586 /*----------------------------------------------------------------------------*\
587 |* Interlocked Xor
588 \*----------------------------------------------------------------------------*/
589 #if defined(__arm__) || defined(__aarch64__)
590 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedXor8_acq(char volatile * _Value,char _Mask)591 _InterlockedXor8_acq(char volatile *_Value, char _Mask) {
592   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE);
593 }
594 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedXor8_nf(char volatile * _Value,char _Mask)595 _InterlockedXor8_nf(char volatile *_Value, char _Mask) {
596   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED);
597 }
598 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedXor8_rel(char volatile * _Value,char _Mask)599 _InterlockedXor8_rel(char volatile *_Value, char _Mask) {
600   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE);
601 }
602 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedXor16_acq(short volatile * _Value,short _Mask)603 _InterlockedXor16_acq(short volatile *_Value, short _Mask) {
604   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE);
605 }
606 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedXor16_nf(short volatile * _Value,short _Mask)607 _InterlockedXor16_nf(short volatile *_Value, short _Mask) {
608   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED);
609 }
610 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedXor16_rel(short volatile * _Value,short _Mask)611 _InterlockedXor16_rel(short volatile *_Value, short _Mask) {
612   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE);
613 }
614 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedXor_acq(long volatile * _Value,long _Mask)615 _InterlockedXor_acq(long volatile *_Value, long _Mask) {
616   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE);
617 }
618 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedXor_nf(long volatile * _Value,long _Mask)619 _InterlockedXor_nf(long volatile *_Value, long _Mask) {
620   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED);
621 }
622 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedXor_rel(long volatile * _Value,long _Mask)623 _InterlockedXor_rel(long volatile *_Value, long _Mask) {
624   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE);
625 }
626 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedXor64_acq(__int64 volatile * _Value,__int64 _Mask)627 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask) {
628   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_ACQUIRE);
629 }
630 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedXor64_nf(__int64 volatile * _Value,__int64 _Mask)631 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask) {
632   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELAXED);
633 }
634 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedXor64_rel(__int64 volatile * _Value,__int64 _Mask)635 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask) {
636   return __atomic_fetch_xor(_Value, _Mask, __ATOMIC_RELEASE);
637 }
638 #endif
639 /*----------------------------------------------------------------------------*\
640 |* Interlocked Exchange
641 \*----------------------------------------------------------------------------*/
642 #if defined(__arm__) || defined(__aarch64__)
643 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchange8_acq(char volatile * _Target,char _Value)644 _InterlockedExchange8_acq(char volatile *_Target, char _Value) {
645   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE);
646   return _Value;
647 }
648 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchange8_nf(char volatile * _Target,char _Value)649 _InterlockedExchange8_nf(char volatile *_Target, char _Value) {
650   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED);
651   return _Value;
652 }
653 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedExchange8_rel(char volatile * _Target,char _Value)654 _InterlockedExchange8_rel(char volatile *_Target, char _Value) {
655   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE);
656   return _Value;
657 }
658 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchange16_acq(short volatile * _Target,short _Value)659 _InterlockedExchange16_acq(short volatile *_Target, short _Value) {
660   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE);
661   return _Value;
662 }
663 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchange16_nf(short volatile * _Target,short _Value)664 _InterlockedExchange16_nf(short volatile *_Target, short _Value) {
665   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED);
666   return _Value;
667 }
668 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedExchange16_rel(short volatile * _Target,short _Value)669 _InterlockedExchange16_rel(short volatile *_Target, short _Value) {
670   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE);
671   return _Value;
672 }
673 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchange_acq(long volatile * _Target,long _Value)674 _InterlockedExchange_acq(long volatile *_Target, long _Value) {
675   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE);
676   return _Value;
677 }
678 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchange_nf(long volatile * _Target,long _Value)679 _InterlockedExchange_nf(long volatile *_Target, long _Value) {
680   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED);
681   return _Value;
682 }
683 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedExchange_rel(long volatile * _Target,long _Value)684 _InterlockedExchange_rel(long volatile *_Target, long _Value) {
685   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE);
686   return _Value;
687 }
688 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchange64_acq(__int64 volatile * _Target,__int64 _Value)689 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value) {
690   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_ACQUIRE);
691   return _Value;
692 }
693 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchange64_nf(__int64 volatile * _Target,__int64 _Value)694 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value) {
695   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELAXED);
696   return _Value;
697 }
698 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedExchange64_rel(__int64 volatile * _Target,__int64 _Value)699 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value) {
700   __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_RELEASE);
701   return _Value;
702 }
703 #endif
704 /*----------------------------------------------------------------------------*\
705 |* Interlocked Compare Exchange
706 \*----------------------------------------------------------------------------*/
707 #if defined(__arm__) || defined(__aarch64__)
708 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedCompareExchange8_acq(char volatile * _Destination,char _Exchange,char _Comparand)709 _InterlockedCompareExchange8_acq(char volatile *_Destination,
710                              char _Exchange, char _Comparand) {
711   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
712                             __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
713   return _Comparand;
714 }
715 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedCompareExchange8_nf(char volatile * _Destination,char _Exchange,char _Comparand)716 _InterlockedCompareExchange8_nf(char volatile *_Destination,
717                              char _Exchange, char _Comparand) {
718   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
719                             __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
720   return _Comparand;
721 }
722 static __inline__ char __DEFAULT_FN_ATTRS
_InterlockedCompareExchange8_rel(char volatile * _Destination,char _Exchange,char _Comparand)723 _InterlockedCompareExchange8_rel(char volatile *_Destination,
724                              char _Exchange, char _Comparand) {
725   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
726                             __ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
727   return _Comparand;
728 }
729 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedCompareExchange16_acq(short volatile * _Destination,short _Exchange,short _Comparand)730 _InterlockedCompareExchange16_acq(short volatile *_Destination,
731                               short _Exchange, short _Comparand) {
732   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
733                             __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
734   return _Comparand;
735 }
736 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedCompareExchange16_nf(short volatile * _Destination,short _Exchange,short _Comparand)737 _InterlockedCompareExchange16_nf(short volatile *_Destination,
738                               short _Exchange, short _Comparand) {
739   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
740                             __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
741   return _Comparand;
742 }
743 static __inline__ short __DEFAULT_FN_ATTRS
_InterlockedCompareExchange16_rel(short volatile * _Destination,short _Exchange,short _Comparand)744 _InterlockedCompareExchange16_rel(short volatile *_Destination,
745                               short _Exchange, short _Comparand) {
746   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
747                             __ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
748   return _Comparand;
749 }
750 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedCompareExchange_acq(long volatile * _Destination,long _Exchange,long _Comparand)751 _InterlockedCompareExchange_acq(long volatile *_Destination,
752                               long _Exchange, long _Comparand) {
753   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
754                             __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
755   return _Comparand;
756 }
757 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedCompareExchange_nf(long volatile * _Destination,long _Exchange,long _Comparand)758 _InterlockedCompareExchange_nf(long volatile *_Destination,
759                               long _Exchange, long _Comparand) {
760   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
761                             __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
762   return _Comparand;
763 }
764 static __inline__ long __DEFAULT_FN_ATTRS
_InterlockedCompareExchange_rel(long volatile * _Destination,long _Exchange,long _Comparand)765 _InterlockedCompareExchange_rel(long volatile *_Destination,
766                               long _Exchange, long _Comparand) {
767   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
768                             __ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
769   return _Comparand;
770 }
771 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedCompareExchange64_acq(__int64 volatile * _Destination,__int64 _Exchange,__int64 _Comparand)772 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
773                               __int64 _Exchange, __int64 _Comparand) {
774   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
775                             __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
776   return _Comparand;
777 }
778 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedCompareExchange64_nf(__int64 volatile * _Destination,__int64 _Exchange,__int64 _Comparand)779 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
780                               __int64 _Exchange, __int64 _Comparand) {
781   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
782                             __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
783   return _Comparand;
784 }
785 static __inline__ __int64 __DEFAULT_FN_ATTRS
_InterlockedCompareExchange64_rel(__int64 volatile * _Destination,__int64 _Exchange,__int64 _Comparand)786 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
787                               __int64 _Exchange, __int64 _Comparand) {
788   __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
789                             __ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
790   return _Comparand;
791 }
792 #endif
793 
794 /*----------------------------------------------------------------------------*\
795 |* movs, stos
796 \*----------------------------------------------------------------------------*/
797 #if defined(__i386__) || defined(__x86_64__)
798 static __inline__ void __DEFAULT_FN_ATTRS
__movsb(unsigned char * __dst,unsigned char const * __src,size_t __n)799 __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
800   __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
801                        : : "memory");
802 }
803 static __inline__ void __DEFAULT_FN_ATTRS
__movsd(unsigned long * __dst,unsigned long const * __src,size_t __n)804 __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
805   __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
806                        : : "memory");
807 }
808 static __inline__ void __DEFAULT_FN_ATTRS
__movsw(unsigned short * __dst,unsigned short const * __src,size_t __n)809 __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
810   __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
811                        : : "memory");
812 }
813 static __inline__ void __DEFAULT_FN_ATTRS
__stosd(unsigned long * __dst,unsigned long __x,size_t __n)814 __stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
815   __asm__ __volatile__("rep stosl" : "+D"(__dst), "+c"(__n) : "a"(__x)
816                        : "memory");
817 }
818 static __inline__ void __DEFAULT_FN_ATTRS
__stosw(unsigned short * __dst,unsigned short __x,size_t __n)819 __stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
820   __asm__ __volatile__("rep stosw" : "+D"(__dst), "+c"(__n) : "a"(__x)
821                        : "memory");
822 }
823 #endif
824 #ifdef __x86_64__
825 static __inline__ void __DEFAULT_FN_ATTRS
__movsq(unsigned long long * __dst,unsigned long long const * __src,size_t __n)826 __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
827   __asm__ __volatile__("rep movsq" : "+D"(__dst), "+S"(__src), "+c"(__n)
828                        : : "memory");
829 }
830 static __inline__ void __DEFAULT_FN_ATTRS
__stosq(unsigned __int64 * __dst,unsigned __int64 __x,size_t __n)831 __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
832   __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
833                        : "memory");
834 }
835 #endif
836 
837 /*----------------------------------------------------------------------------*\
838 |* Misc
839 \*----------------------------------------------------------------------------*/
840 #if defined(__i386__) || defined(__x86_64__)
841 static __inline__ void __DEFAULT_FN_ATTRS
__cpuid(int __info[4],int __level)842 __cpuid(int __info[4], int __level) {
843   __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
844                    : "a"(__level));
845 }
846 static __inline__ void __DEFAULT_FN_ATTRS
__cpuidex(int __info[4],int __level,int __ecx)847 __cpuidex(int __info[4], int __level, int __ecx) {
848   __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
849                    : "a"(__level), "c"(__ecx));
850 }
851 static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS
_xgetbv(unsigned int __xcr_no)852 _xgetbv(unsigned int __xcr_no) {
853   unsigned int __eax, __edx;
854   __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
855   return ((unsigned __int64)__edx << 32) | __eax;
856 }
857 static __inline__ void __DEFAULT_FN_ATTRS
__halt(void)858 __halt(void) {
859   __asm__ volatile ("hlt");
860 }
861 static __inline__ void __DEFAULT_FN_ATTRS
__nop(void)862 __nop(void) {
863   __asm__ volatile ("nop");
864 }
865 #endif
866 
867 /*----------------------------------------------------------------------------*\
868 |* Privileged intrinsics
869 \*----------------------------------------------------------------------------*/
870 #if defined(__i386__) || defined(__x86_64__)
871 static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
__readmsr(unsigned long __register)872 __readmsr(unsigned long __register) {
873   // Loads the contents of a 64-bit model specific register (MSR) specified in
874   // the ECX register into registers EDX:EAX. The EDX register is loaded with
875   // the high-order 32 bits of the MSR and the EAX register is loaded with the
876   // low-order 32 bits. If less than 64 bits are implemented in the MSR being
877   // read, the values returned to EDX:EAX in unimplemented bit locations are
878   // undefined.
879   unsigned long __edx;
880   unsigned long __eax;
881   __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
882   return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
883 }
884 
885 static __inline__ unsigned long __DEFAULT_FN_ATTRS
__readcr3(void)886 __readcr3(void) {
887   unsigned long __cr3_val;
888   __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory");
889   return __cr3_val;
890 }
891 
892 static __inline__ void __DEFAULT_FN_ATTRS
__writecr3(unsigned int __cr3_val)893 __writecr3(unsigned int __cr3_val) {
894   __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory");
895 }
896 #endif
897 
898 #ifdef __cplusplus
899 }
900 #endif
901 
902 #undef __DEFAULT_FN_ATTRS
903 
904 #endif /* __INTRIN_H */
905 #endif /* _MSC_VER */
906