1 /* ===-------- intrin.h ---------------------------------------------------===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===-----------------------------------------------------------------------===
10 /* Only include this if we're compiling for the windows platform. */
12 #include_next <intrin.h>
18 /* First include the standard intrinsics. */
19 #if defined(__i386__) || defined(__x86_64__)
20 #include <x86intrin.h>
27 #if defined(__aarch64__)
28 #include <arm64intr.h>
31 /* For the definition of jmp_buf. */
36 /* Define the default attributes for the functions in this file. */
37 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
44 /* And the random ones that aren't in those files. */
45 __m64 _m_from_float(float);
46 float _m_to_float(__m64);
49 /* Other assorted instruction intrinsics. */
50 void __addfsbyte(unsigned long, unsigned char);
51 void __addfsdword(unsigned long, unsigned long);
52 void __addfsword(unsigned long, unsigned short);
53 void __code_seg(const char *);
55 void __cpuid(int[4], int);
57 void __cpuidex(int[4], int, int);
59 __int64 __emul(int, int);
61 unsigned __int64 __emulu(unsigned int, unsigned int);
62 unsigned int __getcallerseflags(void);
65 unsigned char __inbyte(unsigned short);
66 void __inbytestring(unsigned short, unsigned char *, unsigned long);
67 void __incfsbyte(unsigned long);
68 void __incfsdword(unsigned long);
69 void __incfsword(unsigned long);
70 unsigned long __indword(unsigned short);
71 void __indwordstring(unsigned short, unsigned long *, unsigned long);
73 void __invlpg(void *);
74 unsigned short __inword(unsigned short);
75 void __inwordstring(unsigned short, unsigned short *, unsigned long);
77 unsigned __int64 __ll_lshift(unsigned __int64, int);
78 __int64 __ll_rshift(__int64, int);
80 void __movsb(unsigned char *, unsigned char const *, size_t);
82 void __movsd(unsigned long *, unsigned long const *, size_t);
84 void __movsw(unsigned short *, unsigned short const *, size_t);
87 void __nvreg_restore_fence(void);
88 void __nvreg_save_fence(void);
89 void __outbyte(unsigned short, unsigned char);
90 void __outbytestring(unsigned short, unsigned char *, unsigned long);
91 void __outdword(unsigned short, unsigned long);
92 void __outdwordstring(unsigned short, unsigned long *, unsigned long);
93 void __outword(unsigned short, unsigned short);
94 void __outwordstring(unsigned short, unsigned short *, unsigned long);
95 unsigned long __readcr0(void);
96 unsigned long __readcr2(void);
98 unsigned long __readcr3(void);
99 unsigned long __readcr4(void);
100 unsigned long __readcr8(void);
101 unsigned int __readdr(unsigned int);
104 unsigned char __readfsbyte(unsigned long);
106 unsigned __int64 __readfsqword(unsigned long);
108 unsigned short __readfsword(unsigned long);
111 unsigned __int64 __readmsr(unsigned long);
112 unsigned __int64 __readpmc(unsigned long);
113 unsigned long __segmentlimit(unsigned long);
116 void __stosb(unsigned char *, unsigned char, size_t);
118 void __stosd(unsigned long *, unsigned long, size_t);
120 void __stosw(unsigned short *, unsigned short, size_t);
121 void __svm_clgi(void);
122 void __svm_invlpga(void *, int);
123 void __svm_skinit(int);
124 void __svm_stgi(void);
125 void __svm_vmload(size_t);
126 void __svm_vmrun(size_t);
127 void __svm_vmsave(size_t);
129 unsigned __int64 __ull_rshift(unsigned __int64, int);
130 void __vmx_off(void);
131 void __vmx_vmptrst(unsigned __int64 *);
133 void __writecr0(unsigned int);
135 void __writecr3(unsigned int);
136 void __writecr4(unsigned int);
137 void __writecr8(unsigned int);
138 void __writedr(unsigned int, unsigned int);
139 void __writefsbyte(unsigned long, unsigned char);
140 void __writefsdword(unsigned long, unsigned long);
141 void __writefsqword(unsigned long, unsigned __int64);
142 void __writefsword(unsigned long, unsigned short);
143 void __writemsr(unsigned long, unsigned __int64);
145 void *_AddressOfReturnAddress(void);
147 unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
149 unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
150 unsigned char _bittest(long const *, long);
151 unsigned char _bittestandcomplement(long *, long);
152 unsigned char _bittestandreset(long *, long);
153 unsigned char _bittestandset(long *, long);
154 void __cdecl _disable(void);
155 void __cdecl _enable(void);
156 long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
157 unsigned char _interlockedbittestandreset(long volatile *, long);
158 unsigned char _interlockedbittestandset(long volatile *, long);
159 void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
161 void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
163 long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
164 long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
165 __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
166 __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
167 void __cdecl _invpcid(unsigned int, void *);
168 static __inline__ void
169 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
171 static __inline__ void
172 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
173 _ReadWriteBarrier(void);
174 unsigned int _rorx_u32(unsigned int, const unsigned int);
175 int _sarx_i32(int, unsigned int);
177 int __cdecl _setjmp(jmp_buf);
179 unsigned int _shlx_u32(unsigned int, unsigned int);
180 unsigned int _shrx_u32(unsigned int, unsigned int);
181 void _Store_HLERelease(long volatile *, long);
182 void _Store64_HLERelease(__int64 volatile *, __int64);
183 void _StorePointer_HLERelease(void *volatile *, void *);
184 static __inline__ void
185 __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
187 unsigned __int32 xbegin(void);
190 /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
192 void __addgsbyte(unsigned long, unsigned char);
193 void __addgsdword(unsigned long, unsigned long);
194 void __addgsqword(unsigned long, unsigned __int64);
195 void __addgsword(unsigned long, unsigned short);
197 void __faststorefence(void);
198 void __incgsbyte(unsigned long);
199 void __incgsdword(unsigned long);
200 void __incgsqword(unsigned long);
201 void __incgsword(unsigned long);
203 void __movsq(unsigned long long *, unsigned long long const *, size_t);
205 unsigned char __readgsbyte(unsigned long);
207 unsigned long __readgsdword(unsigned long);
209 unsigned __int64 __readgsqword(unsigned long);
210 unsigned short __readgsword(unsigned long);
211 unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
212 unsigned __int64 _HighPart,
213 unsigned char _Shift);
214 unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
215 unsigned __int64 _HighPart,
216 unsigned char _Shift);
218 void __stosq(unsigned __int64 *, unsigned __int64, size_t);
219 unsigned char __vmx_on(unsigned __int64 *);
220 unsigned char __vmx_vmclear(unsigned __int64 *);
221 unsigned char __vmx_vmlaunch(void);
222 unsigned char __vmx_vmptrld(unsigned __int64 *);
223 unsigned char __vmx_vmread(size_t, size_t *);
224 unsigned char __vmx_vmresume(void);
225 unsigned char __vmx_vmwrite(size_t, size_t);
226 void __writegsbyte(unsigned long, unsigned char);
227 void __writegsdword(unsigned long, unsigned long);
228 void __writegsqword(unsigned long, unsigned __int64);
229 void __writegsword(unsigned long, unsigned short);
230 unsigned char _bittest64(__int64 const *, __int64);
231 unsigned char _bittestandcomplement64(__int64 *, __int64);
232 unsigned char _bittestandreset64(__int64 *, __int64);
233 unsigned char _bittestandset64(__int64 *, __int64);
234 long _InterlockedAnd_np(long volatile *_Value, long _Mask);
235 short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
236 __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
237 char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
238 unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
239 unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
240 long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
242 unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
243 __int64 _ExchangeHigh,
244 __int64 _ExchangeLow,
245 __int64 *_CompareandResult);
246 unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
247 __int64 _ExchangeHigh,
248 __int64 _ExchangeLow,
249 __int64 *_ComparandResult);
250 short _InterlockedCompareExchange16_np(short volatile *_Destination,
251 short _Exchange, short _Comparand);
252 __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
253 __int64 _Exchange, __int64 _Comparand);
254 void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
255 void *_Exchange, void *_Comparand);
256 long _InterlockedOr_np(long volatile *_Value, long _Mask);
257 short _InterlockedOr16_np(short volatile *_Value, short _Mask);
258 __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
259 char _InterlockedOr8_np(char volatile *_Value, char _Mask);
260 long _InterlockedXor_np(long volatile *_Value, long _Mask);
261 short _InterlockedXor16_np(short volatile *_Value, short _Mask);
262 __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
263 char _InterlockedXor8_np(char volatile *_Value, char _Mask);
264 unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
265 __int64 _sarx_i64(__int64, unsigned int);
266 unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
267 unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
269 __int64 __mulh(__int64, __int64);
271 unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
273 __int64 _mul128(__int64, __int64, __int64*);
275 unsigned __int64 _umul128(unsigned __int64,
279 #endif /* __x86_64__ */
281 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
284 unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
286 unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
289 __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
291 __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
293 __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
295 __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
297 __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
299 __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
301 __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
303 __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
307 /*----------------------------------------------------------------------------*\
308 |* Interlocked Exchange Add
309 \*----------------------------------------------------------------------------*/
310 #if defined(__arm__) || defined(__aarch64__)
311 char _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value);
312 char _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value);
313 char _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value);
314 short _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value);
315 short _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value);
316 short _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value);
317 long _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value);
318 long _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value);
319 long _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value);
320 __int64 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value);
321 __int64 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value);
322 __int64 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value);
324 /*----------------------------------------------------------------------------*\
325 |* Interlocked Increment
326 \*----------------------------------------------------------------------------*/
327 #if defined(__arm__) || defined(__aarch64__)
328 short _InterlockedIncrement16_acq(short volatile *_Value);
329 short _InterlockedIncrement16_nf(short volatile *_Value);
330 short _InterlockedIncrement16_rel(short volatile *_Value);
331 long _InterlockedIncrement_acq(long volatile *_Value);
332 long _InterlockedIncrement_nf(long volatile *_Value);
333 long _InterlockedIncrement_rel(long volatile *_Value);
334 __int64 _InterlockedIncrement64_acq(__int64 volatile *_Value);
335 __int64 _InterlockedIncrement64_nf(__int64 volatile *_Value);
336 __int64 _InterlockedIncrement64_rel(__int64 volatile *_Value);
338 /*----------------------------------------------------------------------------*\
339 |* Interlocked Decrement
340 \*----------------------------------------------------------------------------*/
341 #if defined(__arm__) || defined(__aarch64__)
342 short _InterlockedDecrement16_acq(short volatile *_Value);
343 short _InterlockedDecrement16_nf(short volatile *_Value);
344 short _InterlockedDecrement16_rel(short volatile *_Value);
345 long _InterlockedDecrement_acq(long volatile *_Value);
346 long _InterlockedDecrement_nf(long volatile *_Value);
347 long _InterlockedDecrement_rel(long volatile *_Value);
348 __int64 _InterlockedDecrement64_acq(__int64 volatile *_Value);
349 __int64 _InterlockedDecrement64_nf(__int64 volatile *_Value);
350 __int64 _InterlockedDecrement64_rel(__int64 volatile *_Value);
352 /*----------------------------------------------------------------------------*\
354 \*----------------------------------------------------------------------------*/
355 #if defined(__arm__) || defined(__aarch64__)
356 char _InterlockedAnd8_acq(char volatile *_Value, char _Mask);
357 char _InterlockedAnd8_nf(char volatile *_Value, char _Mask);
358 char _InterlockedAnd8_rel(char volatile *_Value, char _Mask);
359 short _InterlockedAnd16_acq(short volatile *_Value, short _Mask);
360 short _InterlockedAnd16_nf(short volatile *_Value, short _Mask);
361 short _InterlockedAnd16_rel(short volatile *_Value, short _Mask);
362 long _InterlockedAnd_acq(long volatile *_Value, long _Mask);
363 long _InterlockedAnd_nf(long volatile *_Value, long _Mask);
364 long _InterlockedAnd_rel(long volatile *_Value, long _Mask);
365 __int64 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask);
366 __int64 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask);
367 __int64 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask);
369 /*----------------------------------------------------------------------------*\
370 |* Bit Counting and Testing
371 \*----------------------------------------------------------------------------*/
372 #if defined(__arm__) || defined(__aarch64__)
373 unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
375 unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
377 unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
379 unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
381 unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
383 unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
386 /*----------------------------------------------------------------------------*\
388 \*----------------------------------------------------------------------------*/
389 #if defined(__arm__) || defined(__aarch64__)
390 char _InterlockedOr8_acq(char volatile *_Value, char _Mask);
391 char _InterlockedOr8_nf(char volatile *_Value, char _Mask);
392 char _InterlockedOr8_rel(char volatile *_Value, char _Mask);
393 short _InterlockedOr16_acq(short volatile *_Value, short _Mask);
394 short _InterlockedOr16_nf(short volatile *_Value, short _Mask);
395 short _InterlockedOr16_rel(short volatile *_Value, short _Mask);
396 long _InterlockedOr_acq(long volatile *_Value, long _Mask);
397 long _InterlockedOr_nf(long volatile *_Value, long _Mask);
398 long _InterlockedOr_rel(long volatile *_Value, long _Mask);
399 __int64 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask);
400 __int64 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask);
401 __int64 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask);
403 /*----------------------------------------------------------------------------*\
405 \*----------------------------------------------------------------------------*/
406 #if defined(__arm__) || defined(__aarch64__)
407 char _InterlockedXor8_acq(char volatile *_Value, char _Mask);
408 char _InterlockedXor8_nf(char volatile *_Value, char _Mask);
409 char _InterlockedXor8_rel(char volatile *_Value, char _Mask);
410 short _InterlockedXor16_acq(short volatile *_Value, short _Mask);
411 short _InterlockedXor16_nf(short volatile *_Value, short _Mask);
412 short _InterlockedXor16_rel(short volatile *_Value, short _Mask);
413 long _InterlockedXor_acq(long volatile *_Value, long _Mask);
414 long _InterlockedXor_nf(long volatile *_Value, long _Mask);
415 long _InterlockedXor_rel(long volatile *_Value, long _Mask);
416 __int64 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask);
417 __int64 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask);
418 __int64 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask);
420 /*----------------------------------------------------------------------------*\
421 |* Interlocked Exchange
422 \*----------------------------------------------------------------------------*/
423 #if defined(__arm__) || defined(__aarch64__)
424 char _InterlockedExchange8_acq(char volatile *_Target, char _Value);
425 char _InterlockedExchange8_nf(char volatile *_Target, char _Value);
426 char _InterlockedExchange8_rel(char volatile *_Target, char _Value);
427 short _InterlockedExchange16_acq(short volatile *_Target, short _Value);
428 short _InterlockedExchange16_nf(short volatile *_Target, short _Value);
429 short _InterlockedExchange16_rel(short volatile *_Target, short _Value);
430 long _InterlockedExchange_acq(long volatile *_Target, long _Value);
431 long _InterlockedExchange_nf(long volatile *_Target, long _Value);
432 long _InterlockedExchange_rel(long volatile *_Target, long _Value);
433 __int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
434 __int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
435 __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
437 /*----------------------------------------------------------------------------*\
438 |* Interlocked Compare Exchange
439 \*----------------------------------------------------------------------------*/
440 #if defined(__arm__) || defined(__aarch64__)
441 char _InterlockedCompareExchange8_acq(char volatile *_Destination,
442 char _Exchange, char _Comparand);
443 char _InterlockedCompareExchange8_nf(char volatile *_Destination,
444 char _Exchange, char _Comparand);
445 char _InterlockedCompareExchange8_rel(char volatile *_Destination,
446 char _Exchange, char _Comparand);
447 short _InterlockedCompareExchange16_acq(short volatile *_Destination,
448 short _Exchange, short _Comparand);
449 short _InterlockedCompareExchange16_nf(short volatile *_Destination,
450 short _Exchange, short _Comparand);
451 short _InterlockedCompareExchange16_rel(short volatile *_Destination,
452 short _Exchange, short _Comparand);
453 long _InterlockedCompareExchange_acq(long volatile *_Destination,
454 long _Exchange, long _Comparand);
455 long _InterlockedCompareExchange_nf(long volatile *_Destination,
456 long _Exchange, long _Comparand);
457 long _InterlockedCompareExchange_rel(long volatile *_Destination,
458 long _Exchange, long _Comparand);
459 __int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
460 __int64 _Exchange, __int64 _Comparand);
461 __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
462 __int64 _Exchange, __int64 _Comparand);
463 __int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
464 __int64 _Exchange, __int64 _Comparand);
467 /*----------------------------------------------------------------------------*\
469 \*----------------------------------------------------------------------------*/
470 #if defined(__i386__) || defined(__x86_64__)
471 static __inline__ void __DEFAULT_FN_ATTRS
472 __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
473 __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
476 static __inline__ void __DEFAULT_FN_ATTRS
477 __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
478 __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
481 static __inline__ void __DEFAULT_FN_ATTRS
482 __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
483 __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
486 static __inline__ void __DEFAULT_FN_ATTRS
487 __stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
488 __asm__ __volatile__("rep stosl" : "+D"(__dst), "+c"(__n) : "a"(__x)
491 static __inline__ void __DEFAULT_FN_ATTRS
492 __stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
493 __asm__ __volatile__("rep stosw" : "+D"(__dst), "+c"(__n) : "a"(__x)
498 static __inline__ void __DEFAULT_FN_ATTRS
499 __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
500 __asm__ __volatile__("rep movsq" : "+D"(__dst), "+S"(__src), "+c"(__n)
503 static __inline__ void __DEFAULT_FN_ATTRS
504 __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
505 __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
510 /*----------------------------------------------------------------------------*\
512 \*----------------------------------------------------------------------------*/
513 #if defined(__i386__) || defined(__x86_64__)
514 static __inline__ void __DEFAULT_FN_ATTRS
515 __cpuid(int __info[4], int __level) {
516 __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
517 : "a"(__level), "c"(0));
519 static __inline__ void __DEFAULT_FN_ATTRS
520 __cpuidex(int __info[4], int __level, int __ecx) {
521 __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
522 : "a"(__level), "c"(__ecx));
524 static __inline__ void __DEFAULT_FN_ATTRS
526 __asm__ volatile ("hlt");
530 #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
531 static __inline__ void __DEFAULT_FN_ATTRS
533 __asm__ volatile ("nop");
537 /*----------------------------------------------------------------------------*\
538 |* MS AArch64 specific
539 \*----------------------------------------------------------------------------*/
540 #if defined(__aarch64__)
541 unsigned __int64 __getReg(int);
542 long _InterlockedAdd(long volatile *Addend, long Value);
543 __int64 _ReadStatusReg(int);
544 void _WriteStatusReg(int, __int64);
546 unsigned short __cdecl _byteswap_ushort(unsigned short val);
547 unsigned long __cdecl _byteswap_ulong (unsigned long val);
548 unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
551 /*----------------------------------------------------------------------------*\
552 |* Privileged intrinsics
553 \*----------------------------------------------------------------------------*/
554 #if defined(__i386__) || defined(__x86_64__)
555 static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
556 __readmsr(unsigned long __register) {
557 // Loads the contents of a 64-bit model specific register (MSR) specified in
558 // the ECX register into registers EDX:EAX. The EDX register is loaded with
559 // the high-order 32 bits of the MSR and the EAX register is loaded with the
560 // low-order 32 bits. If less than 64 bits are implemented in the MSR being
561 // read, the values returned to EDX:EAX in unimplemented bit locations are
565 __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
566 return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
569 static __inline__ unsigned long __DEFAULT_FN_ATTRS
571 unsigned long __cr3_val;
572 __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory");
576 static __inline__ void __DEFAULT_FN_ATTRS
577 __writecr3(unsigned int __cr3_val) {
578 __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory");
586 #undef __DEFAULT_FN_ATTRS
588 #endif /* __INTRIN_H */
589 #endif /* _MSC_VER */