1 /*===------------ larchintrin.h - LoongArch intrinsics ---------------------===
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 #ifndef _LOONGARCH_BASE_INTRIN_H
11 #define _LOONGARCH_BASE_INTRIN_H
17 typedef struct rdtime
{
22 #if __loongarch_grlen == 64
23 typedef struct drdtime
{
25 unsigned long dtimeid
;
28 extern __inline __drdtime_t
29 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
31 __drdtime_t __drdtime
;
33 "rdtime.d %[val], %[tid]\n\t"
34 : [val
] "=&r"(__drdtime
.dvalue
), [tid
] "=&r"(__drdtime
.dtimeid
));
39 extern __inline __rdtime_t
40 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
43 __asm__
volatile("rdtimeh.w %[val], %[tid]\n\t"
44 : [val
] "=&r"(__rdtime
.value
), [tid
] "=&r"(__rdtime
.timeid
));
48 extern __inline __rdtime_t
49 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
52 __asm__
volatile("rdtimel.w %[val], %[tid]\n\t"
53 : [val
] "=&r"(__rdtime
.value
), [tid
] "=&r"(__rdtime
.timeid
));
57 #if __loongarch_grlen == 64
59 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
60 __crc_w_b_w(char _1
, int _2
) {
61 return (int)__builtin_loongarch_crc_w_b_w((char)_1
, (int)_2
);
65 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
66 __crc_w_h_w(short _1
, int _2
) {
67 return (int)__builtin_loongarch_crc_w_h_w((short)_1
, (int)_2
);
71 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
72 __crc_w_w_w(int _1
, int _2
) {
73 return (int)__builtin_loongarch_crc_w_w_w((int)_1
, (int)_2
);
77 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
78 __crc_w_d_w(long int _1
, int _2
) {
79 return (int)__builtin_loongarch_crc_w_d_w((long int)_1
, (int)_2
);
83 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
84 __crcc_w_b_w(char _1
, int _2
) {
85 return (int)__builtin_loongarch_crcc_w_b_w((char)_1
, (int)_2
);
89 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
90 __crcc_w_h_w(short _1
, int _2
) {
91 return (int)__builtin_loongarch_crcc_w_h_w((short)_1
, (int)_2
);
95 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
96 __crcc_w_w_w(int _1
, int _2
) {
97 return (int)__builtin_loongarch_crcc_w_w_w((int)_1
, (int)_2
);
101 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
102 __crcc_w_d_w(long int _1
, int _2
) {
103 return (int)__builtin_loongarch_crcc_w_d_w((long int)_1
, (int)_2
);
107 #define __break(/*ui15*/ _1) __builtin_loongarch_break((_1))
109 #if __loongarch_grlen == 32
110 #define __cacop_w(/*uimm5*/ _1, /*unsigned int*/ _2, /*simm12*/ _3) \
111 ((void)__builtin_loongarch_cacop_w((_1), (unsigned int)(_2), (_3)))
114 #if __loongarch_grlen == 64
115 #define __cacop_d(/*uimm5*/ _1, /*unsigned long int*/ _2, /*simm12*/ _3) \
116 ((void)__builtin_loongarch_cacop_d((_1), (unsigned long int)(_2), (_3)))
119 #define __dbar(/*ui15*/ _1) __builtin_loongarch_dbar((_1))
121 #define __ibar(/*ui15*/ _1) __builtin_loongarch_ibar((_1))
123 #define __movfcsr2gr(/*ui5*/ _1) __builtin_loongarch_movfcsr2gr((_1));
125 #define __movgr2fcsr(/*ui5*/ _1, _2) \
126 __builtin_loongarch_movgr2fcsr((_1), (unsigned int)_2);
128 #define __syscall(/*ui15*/ _1) __builtin_loongarch_syscall((_1))
130 #define __csrrd_w(/*ui14*/ _1) ((unsigned int)__builtin_loongarch_csrrd_w((_1)))
132 #define __csrwr_w(/*unsigned int*/ _1, /*ui14*/ _2) \
133 ((unsigned int)__builtin_loongarch_csrwr_w((unsigned int)(_1), (_2)))
135 #define __csrxchg_w(/*unsigned int*/ _1, /*unsigned int*/ _2, /*ui14*/ _3) \
136 ((unsigned int)__builtin_loongarch_csrxchg_w((unsigned int)(_1), \
137 (unsigned int)(_2), (_3)))
139 #if __loongarch_grlen == 64
140 #define __csrrd_d(/*ui14*/ _1) \
141 ((unsigned long int)__builtin_loongarch_csrrd_d((_1)))
143 #define __csrwr_d(/*unsigned long int*/ _1, /*ui14*/ _2) \
144 ((unsigned long int)__builtin_loongarch_csrwr_d((unsigned long int)(_1), \
147 #define __csrxchg_d(/*unsigned long int*/ _1, /*unsigned long int*/ _2, \
149 ((unsigned long int)__builtin_loongarch_csrxchg_d( \
150 (unsigned long int)(_1), (unsigned long int)(_2), (_3)))
153 extern __inline
unsigned char
154 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
155 __iocsrrd_b(unsigned int _1
) {
156 return (unsigned char)__builtin_loongarch_iocsrrd_b((unsigned int)_1
);
159 extern __inline
unsigned short
160 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
161 __iocsrrd_h(unsigned int _1
) {
162 return (unsigned short)__builtin_loongarch_iocsrrd_h((unsigned int)_1
);
165 extern __inline
unsigned int
166 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
167 __iocsrrd_w(unsigned int _1
) {
168 return (unsigned int)__builtin_loongarch_iocsrrd_w((unsigned int)_1
);
171 #if __loongarch_grlen == 64
172 extern __inline
unsigned long int
173 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
174 __iocsrrd_d(unsigned int _1
) {
175 return (unsigned long int)__builtin_loongarch_iocsrrd_d((unsigned int)_1
);
180 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
181 __iocsrwr_b(unsigned char _1
, unsigned int _2
) {
182 __builtin_loongarch_iocsrwr_b((unsigned char)_1
, (unsigned int)_2
);
186 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
187 __iocsrwr_h(unsigned short _1
, unsigned int _2
) {
188 __builtin_loongarch_iocsrwr_h((unsigned short)_1
, (unsigned int)_2
);
192 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
193 __iocsrwr_w(unsigned int _1
, unsigned int _2
) {
194 __builtin_loongarch_iocsrwr_w((unsigned int)_1
, (unsigned int)_2
);
197 extern __inline
unsigned int
198 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
199 __cpucfg(unsigned int _1
) {
200 return (unsigned int)__builtin_loongarch_cpucfg((unsigned int)_1
);
203 #if __loongarch_grlen == 64
205 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
206 __iocsrwr_d(unsigned long int _1
, unsigned int _2
) {
207 __builtin_loongarch_iocsrwr_d((unsigned long int)_1
, (unsigned int)_2
);
211 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
212 __asrtgt_d(long int _1
, long int _2
) {
213 __builtin_loongarch_asrtgt_d((long int)_1
, (long int)_2
);
217 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
218 __asrtle_d(long int _1
, long int _2
) {
219 __builtin_loongarch_asrtle_d((long int)_1
, (long int)_2
);
223 #if __loongarch_grlen == 64
224 #define __lddir_d(/*long int*/ _1, /*ui5*/ _2) \
225 ((long int)__builtin_loongarch_lddir_d((long int)(_1), (_2)))
227 #define __ldpte_d(/*long int*/ _1, /*ui5*/ _2) \
228 ((void)__builtin_loongarch_ldpte_d((long int)(_1), (_2)))
231 #ifdef __loongarch_frecipe
232 extern __inline
float
233 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
234 __frecipe_s(float _1
) {
235 return __builtin_loongarch_frecipe_s(_1
);
238 extern __inline
double
239 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
240 __frecipe_d(double _1
) {
241 return __builtin_loongarch_frecipe_d(_1
);
244 extern __inline
float
245 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
246 __frsqrte_s(float _1
) {
247 return __builtin_loongarch_frsqrte_s(_1
);
250 extern __inline
double
251 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
252 __frsqrte_d(double _1
) {
253 return __builtin_loongarch_frsqrte_d(_1
);
260 #endif /* _LOONGARCH_BASE_INTRIN_H */