Skip to content

Commit 6dc15b5

Browse files
[LoongArch64] Handle LASX/LSX/FP context depending on ISA availability. (#118007)
* [LoongArch64] Fix SDK running on 2K series SoC. --------- Co-authored-by: driver1998 <[email protected]>
1 parent fae90a6 commit 6dc15b5

File tree

7 files changed

+182
-118
lines changed

7 files changed

+182
-118
lines changed

src/coreclr/pal/inc/pal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,9 @@ typedef union IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_XDATA {
18961896

18971897
#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
18981898

1899+
#define CONTEXT_LSX 0x10
1900+
#define CONTEXT_LASX 0x20
1901+
18991902
#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
19001903
#define CONTEXT_SERVICE_ACTIVE 0x10000000
19011904
#define CONTEXT_EXCEPTION_REQUEST 0x40000000

src/coreclr/pal/inc/unixasmmacrosloongarch64.inc

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,8 @@ C_FUNC(\Name\()_End):
8282

8383
////NOTE: reg1 and reg2 must be the number and GPR type !!!
8484
.macro PROLOG_SAVE_REG_PAIR reg1, reg2, ofs, __def_cfa_save=0
85-
//#ifdef FEATURE_LOONGSONISA
86-
// //NOTE:The offset of gssq/gslq must be 16-bytes aligned.
87-
// // here ofs must be 16-bytes aligned.
88-
// gssq \reg2, \reg1, \ofs(sp)
89-
//#else
9085
st.d $r\reg1, $sp, \ofs
9186
st.d $r\reg2, $sp, \ofs+8
92-
//#endif
9387

9488
.cfi_rel_offset \reg1, \ofs
9589
.cfi_rel_offset \reg2, \ofs + 8
@@ -123,23 +117,15 @@ C_FUNC(\Name\()_End):
123117
.endm
124118

125119
.macro EPILOG_RESTORE_REG_PAIR reg1, reg2, ofs
126-
//#ifdef FEATURE_LOONGSONISA
127-
// gslq \reg2, \reg1, \ofs(sp)
128-
//#else
129120
ld.d $r\reg2, $sp, \ofs+8
130121
ld.d $r\reg1, $sp, \ofs
131-
//#endif
132122
.cfi_restore \reg2
133123
.cfi_restore \reg1
134124
.endm
135125

136126
.macro EPILOG_RESTORE_REG_PAIR_INDEXED reg1, reg2, ssize
137-
//#ifdef FEATURE_LOONGSONISA
138-
// gslq \reg2, \reg1, 0(sp)
139-
//#else
140127
ld.d $r\reg2, $sp, 8
141128
ld.d $r\reg1, $sp, 0
142-
//#endif
143129
.cfi_restore \reg2
144130
.cfi_restore \reg1
145131

@@ -183,14 +169,6 @@ C_FUNC(\Name\()_End):
183169
// Reserve 64 bytes of memory before calling SAVE_ARGUMENT_REGISTERS
184170
.macro SAVE_ARGUMENT_REGISTERS reg, ofs
185171

186-
//#ifdef FEATURE_LOONGSONISA
187-
// //NOTE:The offset of gssq/gslq must be 16-bytes aligned.
188-
// // here ofs must be 16-bytes aligned.
189-
// gssq a1, a0, \ofs(\reg)
190-
// gssq a3, a2, \ofs+16(\reg)
191-
// gssq a5, a4, \ofs+32(\reg)
192-
// gssq a7, a6, \ofs+48(\reg)
193-
//#else
194172
st.d $a0, \reg, \ofs
195173
st.d $a1, \reg, \ofs+8
196174
st.d $a2, \reg, \ofs+16
@@ -199,21 +177,12 @@ C_FUNC(\Name\()_End):
199177
st.d $a5, \reg, \ofs+40
200178
st.d $a6, \reg, \ofs+48
201179
st.d $a7, \reg, \ofs+56
202-
//#endif
203180

204181
.endm
205182

206183
// Reserve 64 bytes of memory before calling SAVE_FLOAT_ARGUMENT_REGISTERS
207184
.macro SAVE_FLOAT_ARGUMENT_REGISTERS reg, ofs
208185

209-
//#ifdef FEATURE_LOONGSONISA
210-
// //NOTE:The offset of gssqc1/gslqc1 must be 16-bytes aligned.
211-
// // here ofs must be 16-bytes aligned.
212-
// gssqc1 $f13, $f12, \ofs(\reg)
213-
// gssqc1 $f15, $f14, \ofs+16(\reg)
214-
// gssqc1 $f17, $f16, \ofs+32(\reg)
215-
// gssqc1 $f19, $f18, \ofs+48(\reg)
216-
//#else
217186
fst.d $f0, \reg, \ofs
218187
fst.d $f1, \reg, \ofs+8
219188
fst.d $f2, \reg, \ofs+16
@@ -222,21 +191,12 @@ C_FUNC(\Name\()_End):
222191
fst.d $f5, \reg, \ofs+40
223192
fst.d $f6, \reg, \ofs+48
224193
fst.d $f7, \reg, \ofs+56
225-
//#endif
226194

227195
.endm
228196

229197
// Reserve 64 bytes of memory before calling SAVE_FLOAT_CALLEESAVED_REGISTERS
230198
.macro SAVE_FLOAT_CALLEESAVED_REGISTERS reg, ofs
231199

232-
//#ifdef FEATURE_LOONGSONISA
233-
// //NOTE:The offset of gssqc1/gslqc1 must be 16-bytes aligned.
234-
// // here ofs must be 16-bytes aligned.
235-
// gssqc1 $f25, $f24, \ofs(\reg)
236-
// gssqc1 $f27, $f26, \ofs+16(\reg)
237-
// gssqc1 $f29, $f28, \ofs+32(\reg)
238-
// gssqc1 $f31, $f30, \ofs+48(\reg)
239-
//#else
240200
fst.d $f24, \reg, \ofs
241201
fst.d $f25, \reg, \ofs+8
242202
fst.d $f26, \reg, \ofs+16
@@ -245,7 +205,6 @@ C_FUNC(\Name\()_End):
245205
fst.d $f29, \reg, \ofs+40
246206
fst.d $f30, \reg, \ofs+48
247207
fst.d $f31, \reg, \ofs+56
248-
//#endif
249208

250209
.endm
251210

@@ -260,14 +219,6 @@ C_FUNC(\Name\()_End):
260219

261220
.macro RESTORE_ARGUMENT_REGISTERS reg, ofs
262221

263-
//#ifdef FEATURE_LOONGSONISA
264-
// //NOTE:The offset of gssq/gslq must be 16-bytes aligned.
265-
// // here ofs must be 16-bytes aligned.
266-
// gslq a7, a6, \ofs+48(\reg)
267-
// gslq a5, a4, \ofs+32(\reg)
268-
// gslq a3, a2, \ofs+16(\reg)
269-
// gslq a1, a0, \ofs(\reg)
270-
//#else
271222
ld.d $a7, \reg, \ofs+56
272223
ld.d $a6, \reg, \ofs+48
273224
ld.d $a5, \reg, \ofs+40
@@ -276,18 +227,11 @@ C_FUNC(\Name\()_End):
276227
ld.d $a2, \reg, \ofs+16
277228
ld.d $a1, \reg, \ofs+8
278229
ld.d $a0, \reg, \ofs
279-
//#endif
280230

281231
.endm
282232

283233
.macro RESTORE_FLOAT_ARGUMENT_REGISTERS reg, ofs
284234

285-
//#ifdef FEATURE_LOONGSONISA
286-
// gslqc1 $f19, $f18, \ofs+48(\reg)
287-
// gslqc1 $f17, $f16, \ofs+32(\reg)
288-
// gslqc1 $f15, $f14, \ofs+16(\reg)
289-
// gslqc1 $f13, $f12, \ofs(\reg)
290-
//#else
291235
fld.d $f7, \reg, \ofs+56
292236
fld.d $f6, \reg, \ofs+48
293237
fld.d $f5, \reg, \ofs+40
@@ -296,20 +240,11 @@ C_FUNC(\Name\()_End):
296240
fld.d $f2, \reg, \ofs+16
297241
fld.d $f1, \reg, \ofs+8
298242
fld.d $f0, \reg, \ofs
299-
//#endif
300243

301244
.endm
302245

303246
.macro RESTORE_FLOAT_CALLEESAVED_REGISTERS reg, ofs
304247

305-
//#ifdef FEATURE_LOONGSONISA
306-
// //NOTE:The offset of gssqc1/gslqc1 must be 16-bytes aligned.
307-
// // here ofs must be 16-bytes aligned.
308-
// gslqc1 $f25, $f24, \ofs(\reg)
309-
// gslqc1 $f27, $f26, \ofs+16(\reg)
310-
// gslqc1 $f29, $f28, \ofs+32(\reg)
311-
// gslqc1 $f31, $f30, \ofs+48(\reg)
312-
//#else
313248
fld.d $f24, $r\reg, \ofs
314249
fld.d $f25, $r\reg, \ofs+8
315250
fld.d $f26, $r\reg, \ofs+16
@@ -318,7 +253,6 @@ C_FUNC(\Name\()_End):
318253
fld.d $f29, $r\reg, \ofs+40
319254
fld.d $f30, $r\reg, \ofs+48
320255
fld.d $f31, $r\reg, \ofs+56
321-
//#endif
322256

323257
.endm
324258

src/coreclr/pal/src/arch/loongarch64/asmconstants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
2121

22+
#define CONTEXT_LSX_BIT (4)
23+
#define CONTEXT_LASX_BIT (5)
24+
#define CONTEXT_LSX (1 << CONTEXT_LSX_BIT)
25+
#define CONTEXT_LASX (1 << CONTEXT_LASX_BIT)
26+
2227
#define SIZEOF_LOONGARCH_GPR 8
2328
#define SIZEOF_LOONGARCH_FPR 8
2429

0 commit comments

Comments
 (0)