1 /* Intrinsics for LoongArch BASE operations.
2 Copyright (C) 2021-2025 Free Software Foundation, Inc.
3 Contributed by Loongson Ltd.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef _GCC_LOONGARCH_BASE_INTRIN_H
27 #define _GCC_LOONGARCH_BASE_INTRIN_H
33 typedef struct drdtime
36 unsigned long dtimeid
;
46 extern __inline __drdtime_t
47 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
50 __drdtime_t __drdtime
;
52 "rdtime.d\t%[val],%[tid]\n\t"
53 : [val
]"=&r"(__drdtime
.dvalue
),[tid
]"=&r"(__drdtime
.dtimeid
)
59 extern __inline __rdtime_t
60 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
65 "rdtimeh.w\t%[val],%[tid]\n\t"
66 : [val
]"=&r"(__rdtime
.value
),[tid
]"=&r"(__rdtime
.timeid
)
71 extern __inline __rdtime_t
72 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
77 "rdtimel.w\t%[val],%[tid]\n\t"
78 : [val
]"=&r"(__rdtime
.value
),[tid
]"=&r"(__rdtime
.timeid
)
83 /* Assembly instruction format: rj, fcsr. */
84 /* Data types in instruction templates: USI, UQI. */
85 #define __movfcsr2gr(/*ui5*/ _1) __builtin_loongarch_movfcsr2gr ((_1));
87 /* Assembly instruction format: fcsr, rj. */
88 /* Data types in instruction templates: VOID, UQI, USI. */
89 #define __movgr2fcsr(/*ui5*/ _1, _2) \
90 __builtin_loongarch_movgr2fcsr ((_1), _2);
92 #if defined __loongarch64
93 /* Assembly instruction format: ui5, rj, si12. */
94 /* Data types in instruction templates: VOID, USI, UDI, SI. */
95 #define __cacop_d(/*ui5*/ _1, /*unsigned long int*/ _2, /*si12*/ _3) \
96 __builtin_loongarch_cacop_d ((_1), (_2), (_3))
98 #error "Unsupported ABI."
101 /* Assembly instruction format: rd, rj. */
102 /* Data types in instruction templates: USI, USI. */
103 extern __inline
unsigned int
104 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
105 __cpucfg (unsigned int _1
)
107 return __builtin_loongarch_cpucfg (_1
);
111 /* Assembly instruction format: rj, rk. */
112 /* Data types in instruction templates: DI, DI. */
114 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
115 __asrtle_d (long int _1
, long int _2
)
117 __builtin_loongarch_asrtle_d (_1
, _2
);
120 /* Assembly instruction format: rj, rk. */
121 /* Data types in instruction templates: DI, DI. */
123 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
124 __asrtgt_d (long int _1
, long int _2
)
126 __builtin_loongarch_asrtgt_d (_1
, _2
);
130 #if defined __loongarch64
131 /* Assembly instruction format: rd, rj, ui5. */
132 /* Data types in instruction templates: DI, DI, UQI. */
133 #define __lddir_d(/*long int*/ _1, /*ui5*/ _2) \
134 __builtin_loongarch_lddir_d ((_1), (_2))
136 #error "Unsupported ABI."
139 #if defined __loongarch64
140 /* Assembly instruction format: rj, ui5. */
141 /* Data types in instruction templates: VOID, DI, UQI. */
142 #define __ldpte_d(/*long int*/ _1, /*ui5*/ _2) \
143 __builtin_loongarch_ldpte_d ((_1), (_2))
145 #error "Unsupported ABI."
148 /* Assembly instruction format: rd, rj, rk. */
149 /* Data types in instruction templates: SI, QI, SI. */
151 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
152 __crc_w_b_w (char _1
, int _2
)
154 return __builtin_loongarch_crc_w_b_w (_1
, _2
);
157 /* Assembly instruction format: rd, rj, rk. */
158 /* Data types in instruction templates: SI, HI, SI. */
160 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
161 __crc_w_h_w (short _1
, int _2
)
163 return __builtin_loongarch_crc_w_h_w (_1
, _2
);
166 /* Assembly instruction format: rd, rj, rk. */
167 /* Data types in instruction templates: SI, SI, SI. */
169 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
170 __crc_w_w_w (int _1
, int _2
)
172 return __builtin_loongarch_crc_w_w_w (_1
, _2
);
176 /* Assembly instruction format: rd, rj, rk. */
177 /* Data types in instruction templates: SI, DI, SI. */
179 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
180 __crc_w_d_w (long int _1
, int _2
)
182 return __builtin_loongarch_crc_w_d_w (_1
, _2
);
186 /* Assembly instruction format: rd, rj, rk. */
187 /* Data types in instruction templates: SI, QI, SI. */
189 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
190 __crcc_w_b_w (char _1
, int _2
)
192 return __builtin_loongarch_crcc_w_b_w (_1
, _2
);
195 /* Assembly instruction format: rd, rj, rk. */
196 /* Data types in instruction templates: SI, HI, SI. */
198 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
199 __crcc_w_h_w (short _1
, int _2
)
201 return __builtin_loongarch_crcc_w_h_w (_1
, _2
);
204 /* Assembly instruction format: rd, rj, rk. */
205 /* Data types in instruction templates: SI, SI, SI. */
207 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
208 __crcc_w_w_w (int _1
, int _2
)
210 return __builtin_loongarch_crcc_w_w_w (_1
, _2
);
214 /* Assembly instruction format: rd, rj, rk. */
215 /* Data types in instruction templates: SI, DI, SI. */
217 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
218 __crcc_w_d_w (long int _1
, int _2
)
220 return __builtin_loongarch_crcc_w_d_w (_1
, _2
);
224 /* Assembly instruction format: rd, ui14. */
225 /* Data types in instruction templates: USI, USI. */
226 #define __csrrd_w(/*ui14*/ _1) \
227 __builtin_loongarch_csrrd_w ((_1))
229 /* Assembly instruction format: rd, ui14. */
230 /* Data types in instruction templates: USI, USI, USI. */
231 #define __csrwr_w(/*unsigned int*/ _1, /*ui14*/ _2) \
232 __builtin_loongarch_csrwr_w ((_1), (_2))
234 /* Assembly instruction format: rd, rj, ui14. */
235 /* Data types in instruction templates: USI, USI, USI, USI. */
236 #define __csrxchg_w(/*unsigned int*/ _1, /*unsigned int*/ _2, /*ui14*/ _3) \
237 __builtin_loongarch_csrxchg_w ((_1), (_2), (_3))
240 /* Assembly instruction format: rd, ui14. */
241 /* Data types in instruction templates: UDI, USI. */
242 #define __csrrd_d(/*ui14*/ _1) \
243 __builtin_loongarch_csrrd_d ((_1))
245 /* Assembly instruction format: rd, ui14. */
246 /* Data types in instruction templates: UDI, UDI, USI. */
247 #define __csrwr_d(/*unsigned long int*/ _1, /*ui14*/ _2) \
248 __builtin_loongarch_csrwr_d ((_1), (_2))
250 /* Assembly instruction format: rd, rj, ui14. */
251 /* Data types in instruction templates: UDI, UDI, UDI, USI. */
252 #define __csrxchg_d(/*unsigned long int*/ _1, /*unsigned long int*/ _2, \
254 __builtin_loongarch_csrxchg_d ((_1), (_2), (_3))
257 /* Assembly instruction format: rd, rj. */
258 /* Data types in instruction templates: UQI, USI. */
259 extern __inline
unsigned char
260 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
261 __iocsrrd_b (unsigned int _1
)
263 return __builtin_loongarch_iocsrrd_b (_1
);
266 /* Assembly instruction format: rd, rj. */
267 /* Data types in instruction templates: UHI, USI. */
268 extern __inline
unsigned short
269 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
270 __iocsrrd_h (unsigned int _1
)
272 return __builtin_loongarch_iocsrrd_h (_1
);
275 /* Assembly instruction format: rd, rj. */
276 /* Data types in instruction templates: USI, USI. */
277 extern __inline
unsigned int
278 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
279 __iocsrrd_w (unsigned int _1
)
281 return __builtin_loongarch_iocsrrd_w (_1
);
285 /* Assembly instruction format: rd, rj. */
286 /* Data types in instruction templates: UDI, USI. */
287 extern __inline
unsigned long int
288 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
289 __iocsrrd_d (unsigned int _1
)
291 return __builtin_loongarch_iocsrrd_d (_1
);
295 /* Assembly instruction format: rd, rj. */
296 /* Data types in instruction templates: VOID, UQI, USI. */
298 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
299 __iocsrwr_b (unsigned char _1
, unsigned int _2
)
301 __builtin_loongarch_iocsrwr_b (_1
, _2
);
304 /* Assembly instruction format: rd, rj. */
305 /* Data types in instruction templates: VOID, UHI, USI. */
307 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
308 __iocsrwr_h (unsigned short _1
, unsigned int _2
)
310 __builtin_loongarch_iocsrwr_h (_1
, _2
);
313 /* Assembly instruction format: rd, rj. */
314 /* Data types in instruction templates: VOID, USI, USI. */
316 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
317 __iocsrwr_w (unsigned int _1
, unsigned int _2
)
319 __builtin_loongarch_iocsrwr_w (_1
, _2
);
323 /* Assembly instruction format: rd, rj. */
324 /* Data types in instruction templates: VOID, UDI, USI. */
326 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
327 __iocsrwr_d (unsigned long int _1
, unsigned int _2
)
329 __builtin_loongarch_iocsrwr_d (_1
, _2
);
333 #ifdef __loongarch_frecipe
334 /* Assembly instruction format: fd, fj. */
335 /* Data types in instruction templates: SF, SF. */
336 extern __inline
float
337 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
338 __frecipe_s (float _1
)
340 return __builtin_loongarch_frecipe_s (_1
);
343 /* Assembly instruction format: fd, fj. */
344 /* Data types in instruction templates: DF, DF. */
345 extern __inline
double
346 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
347 __frecipe_d (double _1
)
349 return __builtin_loongarch_frecipe_d (_1
);
352 /* Assembly instruction format: fd, fj. */
353 /* Data types in instruction templates: SF, SF. */
354 extern __inline
float
355 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
356 __frsqrte_s (float _1
)
358 return __builtin_loongarch_frsqrte_s (_1
);
361 /* Assembly instruction format: fd, fj. */
362 /* Data types in instruction templates: DF, DF. */
363 extern __inline
double
364 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
365 __frsqrte_d (double _1
)
367 return __builtin_loongarch_frsqrte_d (_1
);
371 /* Assembly instruction format: ui15. */
372 /* Data types in instruction templates: USI. */
373 #define __dbar(/*ui15*/ _1) __builtin_loongarch_dbar ((_1))
375 /* Assembly instruction format: ui15. */
376 /* Data types in instruction templates: USI. */
377 #define __ibar(/*ui15*/ _1) __builtin_loongarch_ibar ((_1))
379 /* Assembly instruction format: ui15. */
380 /* Data types in instruction templates: USI. */
381 #define __syscall(/*ui15*/ _1) __builtin_loongarch_syscall ((_1))
383 /* Assembly instruction format: ui15. */
384 /* Data types in instruction templates: USI. */
385 #define __break(/*ui15*/ _1) __builtin_loongarch_break ((_1))
390 #endif /* _GCC_LOONGARCH_BASE_INTRIN_H */