2 * FP/SIMD state saving and restoring macros
4 * Copyright (C) 2012 ARM Ltd.
5 * Author: Catalin Marinas <catalin.marinas@arm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 .macro fpsimd_save state
, tmpnr
21 stp q0
, q1
, [\state
, #16 * 0]
22 stp q2
, q3
, [\state
, #16 * 2]
23 stp q4
, q5
, [\state
, #16 * 4]
24 stp q6
, q7
, [\state
, #16 * 6]
25 stp q8
, q9
, [\state
, #16 * 8]
26 stp q10
, q11
, [\state
, #16 * 10]
27 stp q12
, q13
, [\state
, #16 * 12]
28 stp q14
, q15
, [\state
, #16 * 14]
29 stp q16
, q17
, [\state
, #16 * 16]
30 stp q18
, q19
, [\state
, #16 * 18]
31 stp q20
, q21
, [\state
, #16 * 20]
32 stp q22
, q23
, [\state
, #16 * 22]
33 stp q24
, q25
, [\state
, #16 * 24]
34 stp q26
, q27
, [\state
, #16 * 26]
35 stp q28
, q29
, [\state
, #16 * 28]
36 stp q30
, q31
, [\state
, #16 * 30]!
38 str w
\tmpnr
, [\state
, #16 * 2]
40 str w
\tmpnr
, [\state
, #16 * 2 + 4]
43 .macro fpsimd_restore_fpcr state
, tmp
45 * Writes to fpcr may be self-synchronising, so avoid restoring
46 * the register if it hasn't changed.
56 .macro fpsimd_restore state
, tmpnr
57 ldp q0
, q1
, [\state
, #16 * 0]
58 ldp q2
, q3
, [\state
, #16 * 2]
59 ldp q4
, q5
, [\state
, #16 * 4]
60 ldp q6
, q7
, [\state
, #16 * 6]
61 ldp q8
, q9
, [\state
, #16 * 8]
62 ldp q10
, q11
, [\state
, #16 * 10]
63 ldp q12
, q13
, [\state
, #16 * 12]
64 ldp q14
, q15
, [\state
, #16 * 14]
65 ldp q16
, q17
, [\state
, #16 * 16]
66 ldp q18
, q19
, [\state
, #16 * 18]
67 ldp q20
, q21
, [\state
, #16 * 20]
68 ldp q22
, q23
, [\state
, #16 * 22]
69 ldp q24
, q25
, [\state
, #16 * 24]
70 ldp q26
, q27
, [\state
, #16 * 26]
71 ldp q28
, q29
, [\state
, #16 * 28]
72 ldp q30
, q31
, [\state
, #16 * 30]!
73 ldr w
\tmpnr
, [\state
, #16 * 2]
75 ldr w
\tmpnr
, [\state
, #16 * 2 + 4]
76 fpsimd_restore_fpcr x
\tmpnr
, \state
79 /* Sanity-check macros to help avoid encoding garbage instructions */
81 .macro _check_general_reg nr
82 .if (\nr
) < 0 || (\nr
) > 30
83 .error
"Bad register number \nr."
87 .macro _sve_check_zreg znr
88 .if (\znr
) < 0 || (\znr
) > 31
89 .error
"Bad Scalable Vector Extension vector register number \znr."
93 .macro _sve_check_preg pnr
94 .if (\pnr
) < 0 || (\pnr
) > 15
95 .error
"Bad Scalable Vector Extension predicate register number \pnr."
99 .macro _check_num n
, min
, max
100 .if (\n) < (\min
) || (\n) > (\max
)
101 .error
"Number \n out of range [\min,\max]"
105 /* SVE instruction encodings for non-SVE-capable assemblers */
107 /* STR (vector): STR Z\nz, [X\nxbase, #\offset, MUL VL] */
108 .macro _sve_str_v nz
, nxbase
, offset
=0
110 _check_general_reg
\nxbase
111 _check_num (\offset
), -0x100, 0xff
115 | (((\offset
) & 7) << 10) \
116 | (((\offset
) & 0x1f8) << 13)
119 /* LDR (vector): LDR Z\nz, [X\nxbase, #\offset, MUL VL] */
120 .macro _sve_ldr_v nz
, nxbase
, offset
=0
122 _check_general_reg
\nxbase
123 _check_num (\offset
), -0x100, 0xff
127 | (((\offset
) & 7) << 10) \
128 | (((\offset
) & 0x1f8) << 13)
131 /* STR (predicate): STR P\np, [X\nxbase, #\offset, MUL VL] */
132 .macro _sve_str_p np
, nxbase
, offset
=0
134 _check_general_reg
\nxbase
135 _check_num (\offset
), -0x100, 0xff
139 | (((\offset
) & 7) << 10) \
140 | (((\offset
) & 0x1f8) << 13)
143 /* LDR (predicate): LDR P\np, [X\nxbase, #\offset, MUL VL] */
144 .macro _sve_ldr_p np
, nxbase
, offset
=0
146 _check_general_reg
\nxbase
147 _check_num (\offset
), -0x100, 0xff
151 | (((\offset
) & 7) << 10) \
152 | (((\offset
) & 0x1f8) << 13)
155 /* RDVL X\nx, #\imm */
156 .macro _sve_rdvl nx
, imm
157 _check_general_reg
\nx
158 _check_num (\imm
), -0x20, 0x1f
161 | (((\imm
) & 0x3f) << 5)
164 /* RDFFR (unpredicated): RDFFR P\np.B */
178 .macro __for from
:req
, to
:req
182 __for
\from
, (\from
) + ((\to
) - (\from
)) / 2
183 __for (\from
) + ((\to
) - (\from
)) / 2 + 1, \to
187 .macro _for var
:req
, from
:req
, to
:req
, insn
:vararg
188 .macro _for__body
\var
:req
197 .macro sve_save nxbase
, xpfpsr
, nxtmp
198 _for n
, 0, 31, _sve_str_v
\n, \nxbase
, \n - 34
199 _for n
, 0, 15, _sve_str_p
\n, \nxbase
, \n - 16
201 _sve_str_p
0, \nxbase
202 _sve_ldr_p
0, \nxbase
, -16
205 str w
\nxtmp
, [\xpfpsr
]
207 str w
\nxtmp
, [\xpfpsr
, #4]
210 .macro sve_load nxbase
, xpfpsr
, xvqminus1
, nxtmp
, xtmp2
211 mrs_s x
\nxtmp
, SYS_ZCR_EL1
212 bic \xtmp2
, x
\nxtmp
, ZCR_ELx_LEN_MASK
213 orr \xtmp2
, \xtmp2
, \xvqminus1
216 msr_s SYS_ZCR_EL1
, \xtmp2
// self-synchronising
218 _for n
, 0, 31, _sve_ldr_v
\n, \nxbase
, \n - 34
219 _sve_ldr_p
0, \nxbase
221 _for n
, 0, 15, _sve_ldr_p
\n, \nxbase
, \n - 16
223 ldr w
\nxtmp
, [\xpfpsr
]
225 ldr w
\nxtmp
, [\xpfpsr
, #4]