clang 19.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/* For the definition of jmp_buf. */
34#if __STDC_HOSTED__
35#include <setjmp.h>
36#endif
37
38/* Define the default attributes for the functions in this file. */
39#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
40
41#if __x86_64__
42#define __LPTRINT_TYPE__ __int64
43#else
44#define __LPTRINT_TYPE__ long
45#endif
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51#if defined(__MMX__)
52/* And the random ones that aren't in those files. */
53__m64 _m_from_float(float);
54float _m_to_float(__m64);
55#endif
56
57/* Other assorted instruction intrinsics. */
58void __addfsbyte(unsigned long, unsigned char);
59void __addfsdword(unsigned long, unsigned long);
60void __addfsword(unsigned long, unsigned short);
61void __code_seg(const char *);
62void __cpuid(int[4], int);
63void __cpuidex(int[4], int, int);
64__int64 __emul(int, int);
65unsigned __int64 __emulu(unsigned int, unsigned int);
66unsigned int __getcallerseflags(void);
67void __halt(void);
68unsigned char __inbyte(unsigned short);
69void __inbytestring(unsigned short, unsigned char *, unsigned long);
70void __incfsbyte(unsigned long);
71void __incfsdword(unsigned long);
72void __incfsword(unsigned long);
73unsigned long __indword(unsigned short);
74void __indwordstring(unsigned short, unsigned long *, unsigned long);
75void __int2c(void);
76void __invlpg(void *);
77unsigned short __inword(unsigned short);
78void __inwordstring(unsigned short, unsigned short *, unsigned long);
79void __lidt(void *);
80unsigned __int64 __ll_lshift(unsigned __int64, int);
81__int64 __ll_rshift(__int64, int);
82void __movsb(unsigned char *, unsigned char const *, size_t);
83void __movsd(unsigned long *, unsigned long const *, size_t);
84void __movsw(unsigned short *, unsigned short const *, size_t);
85void __nop(void);
86void __nvreg_restore_fence(void);
87void __nvreg_save_fence(void);
88void __outbyte(unsigned short, unsigned char);
89void __outbytestring(unsigned short, unsigned char *, unsigned long);
90void __outdword(unsigned short, unsigned long);
91void __outdwordstring(unsigned short, unsigned long *, unsigned long);
92void __outword(unsigned short, unsigned short);
93void __outwordstring(unsigned short, unsigned short *, unsigned long);
94unsigned long __readcr0(void);
95unsigned long __readcr2(void);
96unsigned __LPTRINT_TYPE__ __readcr3(void);
97unsigned long __readcr4(void);
98unsigned long __readcr8(void);
99unsigned int __readdr(unsigned int);
100#ifdef __i386__
101unsigned char __readfsbyte(unsigned long);
102unsigned short __readfsword(unsigned long);
103unsigned long __readfsdword(unsigned long);
104unsigned __int64 __readfsqword(unsigned long);
105#endif
106unsigned __int64 __readmsr(unsigned long);
107unsigned __int64 __readpmc(unsigned long);
108unsigned long __segmentlimit(unsigned long);
109void __sidt(void *);
110void __stosb(unsigned char *, unsigned char, size_t);
111void __stosd(unsigned long *, unsigned long, size_t);
112void __stosw(unsigned short *, unsigned short, size_t);
113void __svm_clgi(void);
114void __svm_invlpga(void *, int);
115void __svm_skinit(int);
116void __svm_stgi(void);
117void __svm_vmload(size_t);
118void __svm_vmrun(size_t);
119void __svm_vmsave(size_t);
120void __ud2(void);
121unsigned __int64 __ull_rshift(unsigned __int64, int);
122void __vmx_off(void);
123void __vmx_vmptrst(unsigned __int64 *);
124void __wbinvd(void);
125void __writecr0(unsigned int);
126void __writecr3(unsigned __INTPTR_TYPE__);
127void __writecr4(unsigned int);
128void __writecr8(unsigned int);
129void __writedr(unsigned int, unsigned int);
130void __writefsbyte(unsigned long, unsigned char);
131void __writefsdword(unsigned long, unsigned long);
132void __writefsqword(unsigned long, unsigned __int64);
133void __writefsword(unsigned long, unsigned short);
134void __writemsr(unsigned long, unsigned __int64);
135void *_AddressOfReturnAddress(void);
136unsigned char _bittest(long const *, long);
137unsigned char _bittestandcomplement(long *, long);
138unsigned char _bittestandreset(long *, long);
139unsigned char _bittestandset(long *, long);
140void __cdecl _disable(void);
141void __cdecl _enable(void);
142long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
143unsigned char _interlockedbittestandreset(long volatile *, long);
144unsigned char _interlockedbittestandset(long volatile *, long);
145void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
146 void *);
147void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
148 void *);
149long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
150long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
151__int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
152__int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
153void _ReadBarrier(void);
154unsigned int _rorx_u32(unsigned int, const unsigned int);
155int _sarx_i32(int, unsigned int);
156#if __STDC_HOSTED__
157int __cdecl _setjmp(jmp_buf);
158#endif
159unsigned int _shlx_u32(unsigned int, unsigned int);
160unsigned int _shrx_u32(unsigned int, unsigned int);
161void _Store_HLERelease(long volatile *, long);
162void _Store64_HLERelease(__int64 volatile *, __int64);
163void _StorePointer_HLERelease(void *volatile *, void *);
164void _WriteBarrier(void);
165unsigned __int32 xbegin(void);
166void _xend(void);
167
168/* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
169#if defined(__x86_64__) && !defined(__arm64ec__)
170void __addgsbyte(unsigned long, unsigned char);
171void __addgsdword(unsigned long, unsigned long);
172void __addgsqword(unsigned long, unsigned __int64);
173void __addgsword(unsigned long, unsigned short);
174void __faststorefence(void);
175void __incgsbyte(unsigned long);
176void __incgsdword(unsigned long);
177void __incgsqword(unsigned long);
178void __incgsword(unsigned long);
179void __movsq(unsigned long long *, unsigned long long const *, size_t);
180unsigned char __readgsbyte(unsigned long);
181unsigned long __readgsdword(unsigned long);
182unsigned __int64 __readgsqword(unsigned long);
183unsigned short __readgsword(unsigned long);
184void __stosq(unsigned __int64 *, unsigned __int64, size_t);
185unsigned char __vmx_on(unsigned __int64 *);
186unsigned char __vmx_vmclear(unsigned __int64 *);
187unsigned char __vmx_vmlaunch(void);
188unsigned char __vmx_vmptrld(unsigned __int64 *);
189unsigned char __vmx_vmread(size_t, size_t *);
190unsigned char __vmx_vmresume(void);
191unsigned char __vmx_vmwrite(size_t, size_t);
192void __writegsbyte(unsigned long, unsigned char);
193void __writegsdword(unsigned long, unsigned long);
194void __writegsqword(unsigned long, unsigned __int64);
195void __writegsword(unsigned long, unsigned short);
196unsigned char _bittest64(__int64 const *, __int64);
197unsigned char _bittestandcomplement64(__int64 *, __int64);
198unsigned char _bittestandreset64(__int64 *, __int64);
199unsigned char _bittestandset64(__int64 *, __int64);
200long _InterlockedAnd_np(long volatile *_Value, long _Mask);
201short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
202__int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
203char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
204unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
205unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
206long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
207 long _Comparand);
208unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
209 __int64 _ExchangeHigh,
210 __int64 _ExchangeLow,
211 __int64 *_ComparandResult);
212short _InterlockedCompareExchange16_np(short volatile *_Destination,
213 short _Exchange, short _Comparand);
214__int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
215 __int64 _Exchange, __int64 _Comparand);
216void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
217 void *_Exchange, void *_Comparand);
218long _InterlockedOr_np(long volatile *_Value, long _Mask);
219short _InterlockedOr16_np(short volatile *_Value, short _Mask);
220__int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
221char _InterlockedOr8_np(char volatile *_Value, char _Mask);
222long _InterlockedXor_np(long volatile *_Value, long _Mask);
223short _InterlockedXor16_np(short volatile *_Value, short _Mask);
224__int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
225char _InterlockedXor8_np(char volatile *_Value, char _Mask);
226unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
227__int64 _sarx_i64(__int64, unsigned int);
228unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
229unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
230__int64 __mulh(__int64, __int64);
231unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
232__int64 _mul128(__int64, __int64, __int64 *);
233
234#endif /* __x86_64__ */
235
236/*----------------------------------------------------------------------------*\
237|* movs, stos
238\*----------------------------------------------------------------------------*/
239
240#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
241static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
242 unsigned char const *__src,
243 size_t __n) {
244#if defined(__x86_64__)
245 __asm__ __volatile__("rep movsb"
246 : "+D"(__dst), "+S"(__src), "+c"(__n)
247 :
248 : "memory");
249#else
250 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
251 "rep movsb\n"
252 "xchg {%%esi, %1|%1, esi}"
253 : "+D"(__dst), "+r"(__src), "+c"(__n)
254 :
255 : "memory");
256#endif
257}
258static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
259 unsigned long const *__src,
260 size_t __n) {
261#if defined(__x86_64__)
262 __asm__ __volatile__("rep movs{l|d}"
263 : "+D"(__dst), "+S"(__src), "+c"(__n)
264 :
265 : "memory");
266#else
267 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
268 "rep movs{l|d}\n"
269 "xchg {%%esi, %1|%1, esi}"
270 : "+D"(__dst), "+r"(__src), "+c"(__n)
271 :
272 : "memory");
273#endif
274}
275static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
276 unsigned short const *__src,
277 size_t __n) {
278#if defined(__x86_64__)
279 __asm__ __volatile__("rep movsw"
280 : "+D"(__dst), "+S"(__src), "+c"(__n)
281 :
282 : "memory");
283#else
284 __asm__ __volatile__("xchg {%%esi, %1|%1, esi}\n"
285 "rep movsw\n"
286 "xchg {%%esi, %1|%1, esi}"
287 : "+D"(__dst), "+r"(__src), "+c"(__n)
288 :
289 : "memory");
290#endif
291}
292static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
293 unsigned long __x,
294 size_t __n) {
295 __asm__ __volatile__("rep stos{l|d}"
296 : "+D"(__dst), "+c"(__n)
297 : "a"(__x)
298 : "memory");
299}
300static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
301 unsigned short __x,
302 size_t __n) {
303 __asm__ __volatile__("rep stosw"
304 : "+D"(__dst), "+c"(__n)
305 : "a"(__x)
306 : "memory");
307}
308#endif
309#if defined(__x86_64__) && !defined(__arm64ec__)
310static __inline__ void __DEFAULT_FN_ATTRS __movsq(
311 unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
312 __asm__ __volatile__("rep movsq"
313 : "+D"(__dst), "+S"(__src), "+c"(__n)
314 :
315 : "memory");
316}
317static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
318 unsigned __int64 __x,
319 size_t __n) {
320 __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
321 : "memory");
322}
323#endif
324
325/*----------------------------------------------------------------------------*\
326|* Misc
327\*----------------------------------------------------------------------------*/
328#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
329static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
330 __asm__ volatile("hlt");
331}
332#endif
333
334#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
335static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
336 __asm__ volatile("nop");
337}
338#endif
339
340/*----------------------------------------------------------------------------*\
341|* MS AArch64 specific
342\*----------------------------------------------------------------------------*/
343#if defined(__aarch64__) || defined(__arm64ec__)
344unsigned __int64 __getReg(int);
345long _InterlockedAdd(long volatile *Addend, long Value);
346__int64 _InterlockedAdd64(__int64 volatile *Addend, __int64 Value);
347__int64 _ReadStatusReg(int);
348void _WriteStatusReg(int, __int64);
349
350unsigned short __cdecl _byteswap_ushort(unsigned short val);
351unsigned long __cdecl _byteswap_ulong (unsigned long val);
352unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 val);
353
354__int64 __mulh(__int64 __a, __int64 __b);
355unsigned __int64 __umulh(unsigned __int64 __a, unsigned __int64 __b);
356
357void __break(int);
358
359void __writex18byte(unsigned long offset, unsigned char data);
360void __writex18word(unsigned long offset, unsigned short data);
361void __writex18dword(unsigned long offset, unsigned long data);
362void __writex18qword(unsigned long offset, unsigned __int64 data);
363
364unsigned char __readx18byte(unsigned long offset);
365unsigned short __readx18word(unsigned long offset);
366unsigned long __readx18dword(unsigned long offset);
367unsigned __int64 __readx18qword(unsigned long offset);
368
369double _CopyDoubleFromInt64(__int64);
370float _CopyFloatFromInt32(__int32);
371__int32 _CopyInt32FromFloat(float);
372__int64 _CopyInt64FromDouble(double);
373
374unsigned int _CountLeadingOnes(unsigned long);
375unsigned int _CountLeadingOnes64(unsigned __int64);
376unsigned int _CountLeadingSigns(long);
377unsigned int _CountLeadingSigns64(__int64);
378unsigned int _CountOneBits(unsigned long);
379unsigned int _CountOneBits64(unsigned __int64);
380
381void __cdecl __prefetch(void *);
382#endif
383
384/*----------------------------------------------------------------------------*\
385|* Privileged intrinsics
386\*----------------------------------------------------------------------------*/
387#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
388static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
389__readmsr(unsigned long __register) {
390 // Loads the contents of a 64-bit model specific register (MSR) specified in
391 // the ECX register into registers EDX:EAX. The EDX register is loaded with
392 // the high-order 32 bits of the MSR and the EAX register is loaded with the
393 // low-order 32 bits. If less than 64 bits are implemented in the MSR being
394 // read, the values returned to EDX:EAX in unimplemented bit locations are
395 // undefined.
396 unsigned long __edx;
397 unsigned long __eax;
398 __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
399 return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
400}
401
402static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
403 unsigned __LPTRINT_TYPE__ __cr3_val;
404 __asm__ __volatile__(
405 "mov {%%cr3, %0|%0, cr3}"
406 : "=r"(__cr3_val)
407 :
408 : "memory");
409 return __cr3_val;
410}
411
412static __inline__ void __DEFAULT_FN_ATTRS
413__writecr3(unsigned __INTPTR_TYPE__ __cr3_val) {
414 __asm__ ("mov {%0, %%cr3|cr3, %0}" : : "r"(__cr3_val) : "memory");
415}
416#endif
417
418#ifdef __cplusplus
419}
420#endif
421
422#undef __LPTRINT_TYPE__
423
424#undef __DEFAULT_FN_ATTRS
425
426#endif /* __INTRIN_H */
427#endif /* _MSC_VER */
#define __DEFAULT_FN_ATTRS
static __inline__ vector float vector float __b
Definition: altivec.h:578
#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx)
Definition: cpuid.h:269
static __inline__ void int __a
Definition: emmintrin.h:4057
#define __break(_1)
Definition: larchintrin.h:107
static __inline__ void const void * __src
Definition: movdirintrin.h:45
static __inline__ void __DEFAULT_FN_ATTRS _xend(void)
Definition: rtmintrin.h:36