clang 23.0.0git
intrin.h
Go to the documentation of this file.
1/* ===-------- intrin.h ---------------------------------------------------===
2 *
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
6 *
7 *===-----------------------------------------------------------------------===
8 */
9
10/* Only include this if we're compiling for the windows platform. */
11#ifndef _MSC_VER
12#include_next <intrin.h>
13#else
14
15#ifndef __INTRIN_H
16#define __INTRIN_H
17
18#include <intrin0.h>
19
20/* First include the standard intrinsics. */
21#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
22#include <x86intrin.h>
23#endif
24
25#if defined(__arm__)
26#include <armintr.h>
27#endif
28
29#if defined(__aarch64__) || defined(__arm64ec__)
30#include <arm64intr.h>
31#endif
32
33#if defined(__ARM_ACLE)
34#include <arm_acle.h>
35#endif
36
37/* For the definition of jmp_buf. */
38#if __STDC_HOSTED__
39#include <setjmp.h>
40#endif
41
42/* Define the default attributes for the functions in this file. */
43#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
44
45#if __x86_64__
46#define __LPTRINT_TYPE__ __int64
47#define __IPTRINT_TYPE__ __int64
48#else
49#define __LPTRINT_TYPE__ long
50#define __IPTRINT_TYPE__ int
51#endif
52
53#ifdef __cplusplus
54extern "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);
60float _m_to_float(__m64);
61#endif
62
63/* Other assorted instruction intrinsics. */
64void __addfsbyte(unsigned long, unsigned char);
65void __addfsdword(unsigned long, unsigned long);
66void __addfsword(unsigned long, unsigned short);
67void __code_seg(const char *);
68void __cpuid(int[4], int);
69void __cpuidex(int[4], int, int);
70__int64 __emul(int, int);
71unsigned __int64 __emulu(unsigned int, unsigned int);
72unsigned int __getcallerseflags(void);
73void __halt(void);
74unsigned char __inbyte(unsigned short);
75void __inbytestring(unsigned short, unsigned char *, unsigned long);
76void __incfsbyte(unsigned long);
77void __incfsdword(unsigned long);
78void __incfsword(unsigned long);
79unsigned long __indword(unsigned short);
80void __indwordstring(unsigned short, unsigned long *, unsigned long);
81void __int2c(void);
82void __invlpg(void *);
83unsigned short __inword(unsigned short);
84void __inwordstring(unsigned short, unsigned short *, unsigned long);
85void __lidt(void *);
86unsigned __int64 __ll_lshift(unsigned __int64, int);
87__int64 __ll_rshift(__int64, int);
88void __movsb(unsigned char *, unsigned char const *, size_t);
89void __movsd(unsigned long *, unsigned long const *, size_t);
90void __movsw(unsigned short *, unsigned short const *, size_t);
91void __nop(void);
92void __nvreg_restore_fence(void);
93void __nvreg_save_fence(void);
94void __outbyte(unsigned short, unsigned char);
95void __outbytestring(unsigned short, unsigned char *, unsigned long);
96void __outdword(unsigned short, unsigned long);
97void __outdwordstring(unsigned short, unsigned long *, unsigned long);
98void __outword(unsigned short, unsigned short);
99void __outwordstring(unsigned short, unsigned short *, unsigned long);
100unsigned __LPTRINT_TYPE__ __readcr0(void);
101unsigned __LPTRINT_TYPE__ __readcr2(void);
102unsigned __LPTRINT_TYPE__ __readcr3(void);
103unsigned __LPTRINT_TYPE__ __readcr4(void);
104unsigned __LPTRINT_TYPE__ __readcr8(void);
105unsigned __IPTRINT_TYPE__ __readdr(unsigned int);
106#ifdef __i386__
107unsigned char __readfsbyte(unsigned long);
108unsigned short __readfsword(unsigned long);
109unsigned long __readfsdword(unsigned long);
110unsigned __int64 __readfsqword(unsigned long);
111#endif
112unsigned __int64 __readmsr(unsigned long);
113unsigned __int64 __readpmc(unsigned long);
114unsigned long __segmentlimit(unsigned long);
115void __sidt(void *);
116void __stosb(unsigned char *, unsigned char, size_t);
117void __stosd(unsigned long *, unsigned long, size_t);
118void __stosw(unsigned short *, unsigned short, size_t);
119void __svm_clgi(void);
120void __svm_invlpga(void *, int);
121void __svm_skinit(int);
122void __svm_stgi(void);
123void __svm_vmload(size_t);
124void __svm_vmrun(size_t);
125void __svm_vmsave(size_t);
126void __ud2(void);
127unsigned __int64 __ull_rshift(unsigned __int64, int);
128void __vmx_off(void);
129void __vmx_vmptrst(unsigned __int64 *);
130void __wbinvd(void);
131void __writecr0(unsigned __IPTRINT_TYPE__);
132void __writecr2(unsigned __IPTRINT_TYPE__);
133void __writecr3(unsigned __IPTRINT_TYPE__);
134void __writecr4(unsigned __IPTRINT_TYPE__);
135void __writecr8(unsigned __IPTRINT_TYPE__);
136void __writedr(unsigned int, unsigned __IPTRINT_TYPE__);
137void __writefsbyte(unsigned long, unsigned char);
138void __writefsdword(unsigned long, unsigned long);
139void __writefsqword(unsigned long, unsigned __int64);
140void __writefsword(unsigned long, unsigned short);
141void __writemsr(unsigned long, unsigned __int64);
142void *_AddressOfReturnAddress(void);
143unsigned char _bittest(long const *, long);
144unsigned char _bittestandcomplement(long *, long);
145unsigned char _bittestandreset(long *, long);
146unsigned char _bittestandset(long *, long);
147void __cdecl _disable(void);
148void __cdecl _enable(void);
149long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
150unsigned char _interlockedbittestandreset(long volatile *, long);
151unsigned char _interlockedbittestandset(long volatile *, long);
152void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
153 void *);
154void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
155 void *);
156long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
157long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
158__int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
159__int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
160void _ReadBarrier(void);
161unsigned int _rorx_u32(unsigned int, const unsigned int);
162int _sarx_i32(int, unsigned int);
163#if __STDC_HOSTED__
164int __cdecl _setjmp(jmp_buf);
165#endif
166unsigned int _shlx_u32(unsigned int, unsigned int);
167unsigned int _shrx_u32(unsigned int, unsigned int);
168void _Store_HLERelease(long volatile *, long);
169void _Store64_HLERelease(__int64 volatile *, __int64);
170void _StorePointer_HLERelease(void *volatile *, void *);
171void _WriteBarrier(void);
172
173/* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
174#if defined(__x86_64__) && !defined(__arm64ec__)
175void __addgsbyte(unsigned long, unsigned char);
176void __addgsdword(unsigned long, unsigned long);
177void __addgsqword(unsigned long, unsigned __int64);
178void __addgsword(unsigned long, unsigned short);
179void __faststorefence(void);
180void __incgsbyte(unsigned long);
181void __incgsdword(unsigned long);
182void __incgsqword(unsigned long);
183void __incgsword(unsigned long);
184void __movsq(unsigned long long *, unsigned long long const *, size_t);
185unsigned char __readgsbyte(unsigned long);
186unsigned long __readgsdword(unsigned long);
187unsigned __int64 __readgsqword(unsigned long);
188unsigned short __readgsword(unsigned long);
189void __stosq(unsigned __int64 *, unsigned __int64, size_t);
190unsigned char __vmx_on(unsigned __int64 *);
191unsigned char __vmx_vmclear(unsigned __int64 *);
192unsigned char __vmx_vmlaunch(void);
193unsigned char __vmx_vmptrld(unsigned __int64 *);
194unsigned char __vmx_vmread(size_t, size_t *);
195unsigned char __vmx_vmresume(void);
196unsigned char __vmx_vmwrite(size_t, size_t);
197void __writegsbyte(unsigned long, unsigned char);
198void __writegsdword(unsigned long, unsigned long);
199void __writegsqword(unsigned long, unsigned __int64);
200void __writegsword(unsigned long, unsigned short);
201unsigned char _bittest64(__int64 const *, __int64);
202unsigned char _bittestandcomplement64(__int64 *, __int64);
203unsigned char _bittestandreset64(__int64 *, __int64);
204unsigned char _bittestandset64(__int64 *, __int64);
205long _InterlockedAnd_np(long volatile *_Value, long _Mask);
206short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
207__int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
208char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
209unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
210unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
211long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
212 long _Comparand);
213unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
214 __int64 _ExchangeHigh,
215 __int64 _ExchangeLow,
216 __int64 *_ComparandResult);
217short _InterlockedCompareExchange16_np(short volatile *_Destination,
218 short _Exchange, short _Comparand);
219__int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
220 __int64 _Exchange, __int64 _Comparand);
221void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
222 void *_Exchange, void *_Comparand);
223long _InterlockedOr_np(long volatile *_Value, long _Mask);
224short _InterlockedOr16_np(short volatile *_Value, short _Mask);
225__int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
226char _InterlockedOr8_np(char volatile *_Value, char _Mask);
227long _InterlockedXor_np(long volatile *_Value, long _Mask);
228short _InterlockedXor16_np(short volatile *_Value, short _Mask);
229__int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
230char _InterlockedXor8_np(char volatile *_Value, char _Mask);
231unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
232__int64 _sarx_i64(__int64, unsigned int);
233unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
234unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
235__int64 __mulh(__int64, __int64);
236unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
237__int64 _mul128(__int64, __int64, __int64 *);
238
239#endif /* __x86_64__ */
240
241/*----------------------------------------------------------------------------*\
242|* movs, stos
243\*----------------------------------------------------------------------------*/
244
245#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
246static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
247 unsigned char const *__src,
248 size_t __n) {
249#if defined(__x86_64__)
250 __asm__ __volatile__("rep movsb"
251 : "+D"(__dst), "+S"(__src), "+c"(__n)
252 :
253 : "memory");
254#else
255 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
256 "rep movsb\n"
257 "xchg {%%esi, %1|%1, esi}"
258 : "+D"(__dst), "+r"(__src), "+c"(__n)
259 :
260 : "memory");
261#endif
262}
263static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
264 unsigned long const *__src,
265 size_t __n) {
266#if defined(__x86_64__)
267 __asm__ __volatile__("rep movs{l|d}"
268 : "+D"(__dst), "+S"(__src), "+c"(__n)
269 :
270 : "memory");
271#else
272 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
273 "rep movs{l|d}\n"
274 "xchg {%%esi, %1|%1, esi}"
275 : "+D"(__dst), "+r"(__src), "+c"(__n)
276 :
277 : "memory");
278#endif
279}
280static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
281 unsigned short const *__src,
282 size_t __n) {
283#if defined(__x86_64__)
284 __asm__ __volatile__("rep movsw"
285 : "+D"(__dst), "+S"(__src), "+c"(__n)
286 :
287 : "memory");
288#else
289 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
290 "rep movsw\n"
291 "xchg {%%esi, %1|%1, esi}"
292 : "+D"(__dst), "+r"(__src), "+c"(__n)
293 :
294 : "memory");
295#endif
296}
297static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
298 unsigned long __x,
299 size_t __n) {
300 __asm__ __volatile__("rep stos{l|d}"
301 : "+D"(__dst), "+c"(__n)
302 : "a"(__x)
303 : "memory");
304}
305static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
306 unsigned short __x,
307 size_t __n) {
308 __asm__ __volatile__("rep stosw"
309 : "+D"(__dst), "+c"(__n)
310 : "a"(__x)
311 : "memory");
312}
313#endif
314#if defined(__x86_64__) && !defined(__arm64ec__)
315static __inline__ void __DEFAULT_FN_ATTRS __movsq(
316 unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
317 __asm__ __volatile__("rep movsq"
318 : "+D"(__dst), "+S"(__src), "+c"(__n)
319 :
320 : "memory");
321}
322static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
323 unsigned __int64 __x,
324 size_t __n) {
325 __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
326 : "memory");
327}
328#endif
329
330/*----------------------------------------------------------------------------*\
331|* Misc
332\*----------------------------------------------------------------------------*/
333#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
334static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
335 __asm__ volatile("hlt");
336}
337
338static __inline__ unsigned char __inbyte(unsigned short port) {
339 unsigned char ret;
340 __asm__ __volatile__("inb %w1, %b0" : "=a"(ret) : "Nd"(port));
341 return ret;
342}
343
344static __inline__ unsigned short __inword(unsigned short port) {
345 unsigned short ret;
346 __asm__ __volatile__("inw %w1, %w0" : "=a"(ret) : "Nd"(port));
347 return ret;
348}
349
350static __inline__ unsigned long __indword(unsigned short port) {
351 unsigned long ret;
352 __asm__ __volatile__("inl %w1, %k0" : "=a"(ret) : "Nd"(port));
353 return ret;
354}
355
356static __inline__ void __outbyte(unsigned short port, unsigned char data) {
357 __asm__ __volatile__("outb %b0, %w1" : : "a"(data), "Nd"(port));
358}
359
360static __inline__ void __outword(unsigned short port, unsigned short data) {
361 __asm__ __volatile__("outw %w0, %w1" : : "a"(data), "Nd"(port));
362}
363
364static __inline__ void __outdword(unsigned short port, unsigned long data) {
365 __asm__ __volatile__("outl %k0, %w1" : : "a"(data), "Nd"(port));
366}
367#endif
368
369#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
370static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
371 __asm__ volatile("nop");
372}
373#endif
374
375/*----------------------------------------------------------------------------*\
376|* MS AArch64 specific
377\*----------------------------------------------------------------------------*/
378#if defined(__aarch64__) || defined(__arm64ec__)
379unsigned __int64 __getReg(int);
380unsigned char _interlockedbittestandreset_acq(long volatile *, long);
381unsigned char _interlockedbittestandreset_nf(long volatile *, long);
382unsigned char _interlockedbittestandreset_rel(long volatile *, long);
383unsigned char _interlockedbittestandreset64_acq(__int64 volatile *, __int64);
384unsigned char _interlockedbittestandreset64_nf(__int64 volatile *, __int64);
385unsigned char _interlockedbittestandreset64_rel(__int64 volatile *, __int64);
386unsigned char _interlockedbittestandset_acq(long volatile *, long);
387unsigned char _interlockedbittestandset_nf(long volatile *, long);
388unsigned char _interlockedbittestandset_rel(long volatile *, long);
389unsigned char _interlockedbittestandset64_acq(__int64 volatile *, __int64);
390unsigned char _interlockedbittestandset64_nf(__int64 volatile *, __int64);
391unsigned char _interlockedbittestandset64_rel(__int64 volatile *, __int64);
392long _InterlockedAdd(long volatile *, long);
393long _InterlockedAdd_acq(long volatile *, long);
394long _InterlockedAdd_nf(long volatile *, long);
395long _InterlockedAdd_rel(long volatile *, long);
396__int64 _InterlockedAdd64(__int64 volatile *, __int64);
397__int64 _InterlockedAdd64_acq(__int64 volatile *, __int64);
398__int64 _InterlockedAdd64_nf(__int64 volatile *, __int64);
399__int64 _InterlockedAdd64_rel(__int64 volatile *, __int64);
400__int64 _ReadStatusReg(int);
401void _WriteStatusReg(int, __int64);
402unsigned int __sys(int, __int64);
403
404unsigned short __cdecl _byteswap_ushort(unsigned short val);
405unsigned long __cdecl _byteswap_ulong (unsigned long val);
406unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
407
408__int64 __mulh(__int64 __a, __int64 __b);
409unsigned __int64 __umulh(unsigned __int64 __a, unsigned __int64 __b);
410
411void __break(int);
412
413void __writex18byte(unsigned long offset, unsigned char data);
414void __writex18word(unsigned long offset, unsigned short data);
415void __writex18dword(unsigned long offset, unsigned long data);
416void __writex18qword(unsigned long offset, unsigned __int64 data);
417
418unsigned char __readx18byte(unsigned long offset);
419unsigned short __readx18word(unsigned long offset);
420unsigned long __readx18dword(unsigned long offset);
421unsigned __int64 __readx18qword(unsigned long offset);
422
423void __addx18byte(unsigned long offset, unsigned char data);
424void __addx18word(unsigned long offset, unsigned short data);
425void __addx18dword(unsigned long offset, unsigned long data);
426void __addx18qword(unsigned long offset, unsigned __int64 data);
427
428void __incx18byte(unsigned long offset);
429void __incx18word(unsigned long offset);
430void __incx18dword(unsigned long offset);
431void __incx18qword(unsigned long offset);
432
433double _CopyDoubleFromInt64(__int64);
434float _CopyFloatFromInt32(__int32);
435__int32 _CopyInt32FromFloat(float);
436__int64 _CopyInt64FromDouble(double);
437
438unsigned int _CountLeadingOnes(unsigned long);
439unsigned int _CountLeadingOnes64(unsigned __int64);
440unsigned int _CountLeadingSigns(long);
441unsigned int _CountLeadingSigns64(__int64);
442unsigned int _CountOneBits(unsigned long);
443unsigned int _CountOneBits64(unsigned __int64);
444
445unsigned int __hlt(unsigned int, ...);
446
447void __cdecl __prefetch(const void *);
448
449#endif
450
451/*----------------------------------------------------------------------------*\
452|* Privileged intrinsics
453\*----------------------------------------------------------------------------*/
454#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
455static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
456__readmsr(unsigned long __register) {
457 // Loads the contents of a 64-bit model specific register (MSR) specified in
458 // the ECX register into registers EDX:EAX. The EDX register is loaded with
459 // the high-order 32 bits of the MSR and the EAX register is loaded with the
460 // low-order 32 bits. If less than 64 bits are implemented in the MSR being
461 // read, the values returned to EDX:EAX in unimplemented bit locations are
462 // undefined.
463 unsigned long __edx;
464 unsigned long __eax;
465 __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
466 return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
467}
468
469static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
470 unsigned __LPTRINT_TYPE__ __cr3_val;
471 __asm__ __volatile__(
472 "mov {%%cr3, %0|%0, cr3}"
473 : "=r"(__cr3_val)
474 :
475 : "memory");
476 return __cr3_val;
477}
478
479static __inline__ void __DEFAULT_FN_ATTRS
480__writecr3(unsigned __IPTRINT_TYPE__ __cr3_val) {
481 __asm__ ("mov {%0, %%cr3|cr3, %0}" : : "r"(__cr3_val) : "memory");
482}
483#endif
484
485#ifdef __cplusplus
486}
487#endif
488
489#undef __LPTRINT_TYPE__
490#undef __IPTRINT_TYPE__
491
492#undef __DEFAULT_FN_ATTRS
493
494#endif /* __INTRIN_H */
495#endif /* _MSC_VER */
#define __DEFAULT_FN_ATTRS
static __inline__ vector float vector float __b
Definition altivec.h:578
__asm__("swp %0, %1, [%2]" :"=r"(__v) :"r"(__x), "r"(__p) :"memory")
#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx)
Definition cpuid.h:266
static __inline void __cpuidex(int __cpu_info[4], int __leaf, int __subleaf)
Executes the CPUID instruction with the specified leaf and subleaf values, and returns the results fr...
Definition cpuid.h:444
static __inline__ void int __a
Definition emmintrin.h:4077
#define __break(_1)
static __inline__ void const void * __src