1/* Miscellaneous macros.
2 Copyright (C) 2022-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_ASM_H
20#define _SYS_ASM_H
21
22#include <sys/regdef.h>
23#include <sysdeps/generic/sysdep.h>
24
25/* Macros to handle different pointer/register sizes for 32/64-bit code. */
26#if __loongarch_grlen == 64
27#define SZREG 8
28#define REG_L ld.d
29#define REG_S st.d
30#define SRLI srli.d
31#define SLLI slli.d
32#define ADDI addi.d
33#define ADD add.d
34#define SUB sub.d
35#define LI li.d
36#define BSTRINS bstrins.d
37
38#elif __loongarch_grlen == 32
39
40#define SZREG 4
41#define REG_L ld.w
42#define REG_S st.w
43#define SRLI srli.w
44#define SLLI slli.w
45#define ADDI addi.w
46#define ADD add.w
47#define SUB sub.w
48#define LI li.w
49#define BSTRINS bstrins.w
50
51#else
52#error __loongarch_grlen must equal 32 or 64
53#endif
54
55#if __loongarch_frlen == 64
56 #define SZFREG 8
57 #define FREG_L fld.d
58 #define FREG_S fst.d
59#elif __loongarch_frlen == 32
60 #define SZFREG 4
61 #define FREG_L fld.s
62 #define FREG_S fst.s
63#endif
64
65#define SZVREG 16
66#define SZXREG 32
67
68/* Declare leaf routine.
69 The usage of macro LEAF/ENTRY is as follows:
70 1. LEAF(fcn) -- the align value of fcn is .align 3 (default value)
71 2. LEAF(fcn, 6) -- the align value of fcn is .align 6
72*/
73#define LEAF_IMPL(symbol, aln, ...) \
74 .text; \
75 .globl symbol; \
76 .align aln; \
77 .type symbol, @function; \
78symbol: \
79 cfi_startproc;
80
81
82#define LEAF(...) LEAF_IMPL(__VA_ARGS__, 3)
83#define ENTRY(...) LEAF(__VA_ARGS__)
84
85#define LEAF_NO_ALIGN(symbol) \
86 .text; \
87 .globl symbol; \
88 .type symbol, @function; \
89symbol: \
90 cfi_startproc;
91
92#define ENTRY_NO_ALIGN(symbol) LEAF_NO_ALIGN(symbol)
93
94
95/* Mark end of function. */
96#undef END
97#define END(function) \
98 cfi_endproc; \
99 .size function, .- function;
100
101/* Stack alignment. */
102#define ALMASK ~15
103
104#endif /* sys/asm.h */