Skip to content

Commit 96be510

Browse files
authored
[LoongArch64] Modify several atomic instructions in nativeaot. (#108377)
1 parent c049b85 commit 96be510

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

src/coreclr/nativeaot/Runtime/loongarch64/AllocFast.S

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
4646
add.d $a2, $a2, $t3
4747
ld.d $t4, $a1, OFFSETOF__Thread__m_alloc_context__alloc_limit
48-
bltu $t4, $a2, RhpNewFast_RarePath
48+
bltu $t4, $a2, LOCAL_LABEL(RhpNewFast_RarePath)
4949

5050
// Update the alloc pointer to account for the allocation.
5151
st.d $a2, $a1, OFFSETOF__Thread__m_alloc_context__alloc_ptr
@@ -56,7 +56,7 @@
5656
ori $a0, $t3, 0
5757
jirl $r0, $ra, 0
5858

59-
RhpNewFast_RarePath:
59+
LOCAL_LABEL(RhpNewFast_RarePath):
6060
ori $a1, $zero, 0
6161
b RhpNewObject
6262
LEAF_END RhpNewFast, _TEXT
@@ -87,14 +87,14 @@ RhpNewFast_RarePath:
8787
bl C_FUNC(RhpGcAlloc)
8888

8989
// Set the new objects MethodTable pointer on success.
90-
beq $a0, $zero, NewOutOfMemory
90+
beq $a0, $zero, LOCAL_LABEL(NewOutOfMemory)
9191

9292
.cfi_remember_state
9393
POP_COOP_PINVOKE_FRAME
9494
EPILOG_RETURN
9595

9696
.cfi_restore_state
97-
NewOutOfMemory:
97+
LOCAL_LABEL(NewOutOfMemory):
9898
// This is the OOM failure path. We are going to tail-call to a managed helper that will throw
9999
// an out of memory exception that the caller of this allocator understands.
100100

@@ -113,7 +113,7 @@ NewOutOfMemory:
113113
// Make sure computing the overall allocation size wont overflow
114114
lu12i.w $a2, ((MAX_STRING_LENGTH >> 12) & 0xFFFFF)
115115
ori $a2, $a2, (MAX_STRING_LENGTH & 0xFFF)
116-
bltu $a2, $a1, StringSizeOverflow
116+
bltu $a2, $a1, LOCAL_LABEL(StringSizeOverflow)
117117

118118
// Compute overall allocation size (align(base size + (element size * elements), 8)).
119119
ori $a2, $zero, STRING_COMPONENT_SIZE
@@ -138,7 +138,7 @@ NewOutOfMemory:
138138
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
139139
add.d $a2, $a2, $t3
140140
ld.d $t3, $a3, OFFSETOF__Thread__m_alloc_context__alloc_limit
141-
bltu $t3, $a2, RhNewString_Rare
141+
bltu $t3, $a2, LOCAL_LABEL(RhNewString_Rare)
142142

143143
// Reload new object address into r12.
144144
ld.d $t3, $a3, OFFSETOF__Thread__m_alloc_context__alloc_ptr
@@ -155,7 +155,7 @@ NewOutOfMemory:
155155

156156
jirl $r0, $ra, 0
157157

158-
StringSizeOverflow:
158+
LOCAL_LABEL(StringSizeOverflow):
159159
// We get here if the length of the final string object can not be represented as an unsigned
160160
// 32-bit value. We are going to tail-call to a managed helper that will throw
161161
// an OOM exception that the caller of this allocator understands.
@@ -164,7 +164,7 @@ StringSizeOverflow:
164164
ori $a1, $zero, 1 // Indicate that we should throw OverflowException
165165
b C_FUNC(RhExceptionHandling_FailedAllocation)
166166

167-
RhNewString_Rare:
167+
LOCAL_LABEL(RhNewString_Rare):
168168
b C_FUNC(RhpNewArrayRare)
169169
LEAF_END RhNewString, _Text
170170

@@ -179,7 +179,7 @@ RhNewString_Rare:
179179
// case (32 dimensional MdArray) is less than 0xffff, and thus the product fits in 64 bits.
180180
lu12i.w $a2, 0x7ffff
181181
ori $a2, $a2, 0xfff
182-
bltu $a2, $a1, ArraySizeOverflow
182+
bltu $a2, $a1, LOCAL_LABEL(ArraySizeOverflow)
183183

184184
ld.h $a2, $a0, OFFSETOF__MethodTable__m_usComponentSize
185185
mulw.d.w $a2, $a1, $a2
@@ -200,7 +200,7 @@ RhNewString_Rare:
200200
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
201201
add.d $a2, $a2, $t3
202202
ld.d $t3, $a3, OFFSETOF__Thread__m_alloc_context__alloc_limit
203-
bltu $t3, $a2, RhpNewArray_Rare
203+
bltu $t3, $a2, LOCAL_LABEL(RhpNewArray_Rare)
204204

205205
// Reload new object address into t3.
206206
ld.d $t3, $a3, OFFSETOF__Thread__m_alloc_context__alloc_ptr
@@ -217,7 +217,7 @@ RhNewString_Rare:
217217

218218
jirl $r0, $ra, 0
219219

220-
ArraySizeOverflow:
220+
LOCAL_LABEL(ArraySizeOverflow):
221221
// We get here if the size of the final array object can not be represented as an unsigned
222222
// 32-bit value. We are going to tail-call to a managed helper that will throw
223223
// an overflow exception that the caller of this allocator understands.
@@ -226,7 +226,7 @@ ArraySizeOverflow:
226226
ori $a1, $zero, 1 // Indicate that we should throw OverflowException
227227
b C_FUNC(RhExceptionHandling_FailedAllocation)
228228

229-
RhpNewArray_Rare:
229+
LOCAL_LABEL(RhpNewArray_Rare):
230230
b C_FUNC(RhpNewArrayRare)
231231
LEAF_END RhpNewArray, _TEXT
232232

@@ -253,14 +253,14 @@ RhpNewArray_Rare:
253253
bl C_FUNC(RhpGcAlloc)
254254

255255
// Set the new objects MethodTable pointer and length on success.
256-
beq $a0, $zero, ArrayOutOfMemory
256+
beq $a0, $zero, LOCAL_LABEL(ArrayOutOfMemory)
257257

258258
.cfi_remember_state
259259
POP_COOP_PINVOKE_FRAME
260260
EPILOG_RETURN
261261

262262
.cfi_restore_state
263-
ArrayOutOfMemory:
263+
LOCAL_LABEL(ArrayOutOfMemory):
264264
// This is the OOM failure path. We are going to tail-call to a managed helper that will throw
265265
// an out of memory exception that the caller of this allocator understands.
266266

src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
// where the tail-calling thread had saved RA, which may not match where we have saved RA.
289289

290290
ld.d $a1, $a2, OFFSETOF__Thread__m_pvHijackedReturnAddress
291-
beq $a1, $zero, NotHijacked
291+
beq $a1, $zero, LOCAL_LABEL(NotHijacked)
292292

293293
ld.d $a3, $a2, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation
294294

@@ -298,13 +298,13 @@
298298
// a3: hijacked return address location
299299

300300
addi.d $t3, $sp, (STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) // re-compute SP at callsite
301-
bltu $a3, $t3, TailCallWasHijacked // if (m_ppvHijackedReturnAddressLocation < SP at callsite)
301+
bltu $a3, $t3, LOCAL_LABEL(TailCallWasHijacked) // if (m_ppvHijackedReturnAddressLocation < SP at callsite)
302302

303303
// normal case where a valid return address location is hijacked
304304
st.d $a1, $a3, 0
305-
b ClearThreadState
305+
b LOCAL_LABEL(ClearThreadState)
306306

307-
TailCallWasHijacked:
307+
LOCAL_LABEL(TailCallWasHijacked):
308308

309309
// Abnormal case where the return address location is now invalid because we ended up here via a tail
310310
// call. In this case, our hijacked return address should be the correct caller of this method.
@@ -314,13 +314,13 @@ TailCallWasHijacked:
314314
st.d $ra, $sp, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__RA)
315315
st.d $ra, $sp, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)
316316

317-
ClearThreadState:
317+
LOCAL_LABEL(ClearThreadState):
318318

319319
// clear the Thread's hijack state
320320
st.d $zero, $a2, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation
321321
st.d $zero, $a2, OFFSETOF__Thread__m_pvHijackedReturnAddress
322322

323-
NotHijacked:
323+
LOCAL_LABEL(NotHijacked):
324324

325325
addi.d $a1, $sp, rsp_offsetof_ExInfo // a1 <- ExInfo*
326326
st.d $zero, $a1, OFFSETOF__ExInfo__m_exception // pExInfo->m_exception = null
@@ -502,21 +502,21 @@ NotHijacked:
502502
ld.d $a3, $sp, rsp_offset_a3 // a3 <- current ExInfo*
503503
ld.d $a2, $a2, OFFSETOF__REGDISPLAY__SP // a2 <- resume SP value
504504

505-
PopExInfoLoop:
505+
LOCAL_LABEL(PopExInfoLoop):
506506
ld.d $a3, $a3, OFFSETOF__ExInfo__m_pPrevExInfo // a3 <- next ExInfo
507-
beq $a3, $zero, DonePopping // if (pExInfo == null) { we're done }
508-
blt $a3, $a2, PopExInfoLoop // if (pExInfo < resume SP} { keep going }
507+
beq $a3, $zero, LOCAL_LABEL(DonePopping) // if (pExInfo == null) { we're done }
508+
blt $a3, $a2, LOCAL_LABEL(PopExInfoLoop) // if (pExInfo < resume SP} { keep going }
509509

510-
DonePopping:
510+
LOCAL_LABEL(DonePopping):
511511
st.d $a3, $a1, OFFSETOF__Thread__m_pExInfoStackHead // store the new head on the Thread
512512

513513
PREPARE_EXTERNAL_VAR_INDIRECT_W RhpTrapThreads, $a3
514514

515515
andi $t7, $a3, TrapThreadsFlags_AbortInProgress_Bit
516-
beq $t7, $zero, NoAbort
516+
beq $t7, $zero, LOCAL_LABEL(NoAbort)
517517

518518
ld.d $a3, $sp, rsp_offset_is_not_handling_thread_abort
519-
bne $a3, $zero, NoAbort
519+
bne $a3, $zero, LOCAL_LABEL(NoAbort)
520520

521521
// It was the ThreadAbortException, so rethrow it
522522
// reset SP
@@ -525,7 +525,7 @@ DonePopping:
525525
ori $sp, $a2, 0
526526
b C_FUNC(RhpThrowHwEx)
527527

528-
NoAbort:
528+
LOCAL_LABEL(NoAbort):
529529
// reset SP and jump to continuation address
530530
ori $sp, $a2, 0
531531
jirl $r0, $a0, 0
@@ -618,8 +618,8 @@ NoAbort:
618618
ld.d $a2, $sp, rsp_FinallyFunclet_offset_thread
619619

620620
addi.d $t3, $a2, OFFSETOF__Thread__m_ThreadStateFlags
621-
addi.w $a3, $zero, -17 // $a3 = $a3 & ~TSF_DoNotTriggerGc, TSF_DoNotTriggerGc=0x10.
622-
amand_db.w $a1, $a3, $t3
621+
addi.w $a3, $zero, 16 // $a3 = $a3 | TSF_DoNotTriggerGc, TSF_DoNotTriggerGc=0x10.
622+
amor_db.w $a1, $a3, $t3
623623

624624
fld.d $f24, $sp, 0x00
625625
fld.d $f25, $sp, 0x08
@@ -771,12 +771,12 @@ NoAbort:
771771
ld.d $a3, $sp, rsp_offset_a3 // a3 <- current ExInfo*
772772
ld.d $a2, $a2, OFFSETOF__REGDISPLAY__SP // a2 <- resume SP value
773773

774-
Propagate_PopExInfoLoop:
775-
ld.d $a3, $a3, OFFSETOF__ExInfo__m_pPrevExInfo // a3 <- next ExInfo
776-
beq $a3, $zero, Propagate_DonePopping // if (pExInfo == null) { we're done }
777-
blt $a3, $a2, Propagate_PopExInfoLoop // if (pExInfo < resume SP} { keep going }
774+
LOCAL_LABEL(Propagate_PopExInfoLoop):
775+
ld.d $a3, $a3, OFFSETOF__ExInfo__m_pPrevExInfo // a3 <- next ExInfo
776+
beq $a3, $zero, LOCAL_LABEL(Propagate_DonePopping) // if (pExInfo == null) { we're done }
777+
blt $a3, $a2, LOCAL_LABEL(Propagate_PopExInfoLoop) // if (pExInfo < resume SP} { keep going }
778778

779-
Propagate_DonePopping:
779+
LOCAL_LABEL(Propagate_DonePopping):
780780
st.d $a3, $a1, OFFSETOF__Thread__m_pExInfoStackHead // store the new head on the Thread
781781

782782
// restore preemptive mode

src/coreclr/nativeaot/Runtime/loongarch64/GcProbe.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ NESTED_ENTRY RhpGcProbeHijack, _TEXT, NoHandler
135135

136136
PREPARE_EXTERNAL_VAR_INDIRECT_W RhpTrapThreads, $a3
137137
andi $t8, $a3, TrapThreadsFlags_TrapThreads_Bit
138-
bne $t8, $zero, WaitForGC
138+
bne $t8, $zero, LOCAL_LABEL(WaitForGC)
139139
jirl $r0, $ra, 0
140140

141-
WaitForGC:
141+
LOCAL_LABEL(WaitForGC):
142142
lu12i.w $t7, ((DEFAULT_FRAME_SAVE_FLAGS + PTFF_SAVE_R4 + PTFF_SAVE_R5) >> 12) & 0xfffff
143143
ori $t7, $t7, (DEFAULT_FRAME_SAVE_FLAGS + PTFF_SAVE_R4 + PTFF_SAVE_R5) & 0xfff
144144
or $t3, $t3, $t7
@@ -155,14 +155,14 @@ NESTED_ENTRY RhpWaitForGC, _TEXT, NoHandler
155155

156156
ld.d $a2,$sp, OFFSETOF__PInvokeTransitionFrame__m_Flags
157157
andi $t8, $a2, PTFF_THREAD_ABORT_BIT
158-
bne $t8, $zero, ThrowThreadAbort
158+
bne $t8, $zero, LOCAL_LABEL(ThrowThreadAbort)
159159

160160
.cfi_remember_state
161161
POP_PROBE_FRAME
162162
EPILOG_RETURN
163163

164164
.cfi_restore_state
165-
ThrowThreadAbort:
165+
LOCAL_LABEL(ThrowThreadAbort):
166166
POP_PROBE_FRAME
167167
addi.w $a0, $zero, STATUS_REDHAWK_THREAD_ABORT
168168
ori $a1, $ra, 0 // return address as exception PC

src/coreclr/nativeaot/Runtime/loongarch64/WriteBarriers.S

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ LEAF_END RhpByRefAssignRef, _TEXT
231231
or $t4, $t0, $t4
232232
beq $t4, $zero, C_FUNC(RhpAssignRefLoongArch64)
233233

234-
NotInHeap:
234+
LOCAL_LABEL(NotInHeap):
235235
ALTERNATE_ENTRY RhpCheckedAssignRefAVLocation
236236
st.d $t7, $t6, 0
237237
addi.d $t6, $t6, 8
@@ -293,26 +293,28 @@ LEAF_END RhpAssignRef, _TEXT
293293
//
294294
LEAF_ENTRY RhpCheckedLockCmpXchg
295295

296-
ori $t1, $a2, 0
297-
ld.d $t0, $a0, 0
298-
beq $t0, $t1, 12
299-
ori $t1, $t0, 0
300-
b EndOfExchange
301-
st.d $a1, $a0, 0
296+
LOCAL_LABEL(RetryLoop):
297+
ll.d $t3, $a0, 0
298+
ori $t1, $a1, 0
299+
bne $t3, $a2, LOCAL_LABEL(EndOfExchange)
300+
sc.d $t1, $a0, 0
301+
beqz $t1, LOCAL_LABEL(RetryLoop)
302+
b LOCAL_LABEL(DoCardsCmpXchg)
302303

303-
EndOfExchange:
304-
bne $a2, $t1, CmpXchgNoUpdate
304+
LOCAL_LABEL(EndOfExchange):
305+
dbar 0x700
306+
b LOCAL_LABEL(CmpXchgNoUpdate)
305307

306-
DoCardsCmpXchg:
308+
LOCAL_LABEL(DoCardsCmpXchg):
307309
// We have successfully updated the value of the objectref so now we need a GC write barrier.
308310
// The following barrier code takes the destination in $a0 and the value in $a1 so the arguments are
309311
// already correctly set up.
310312

311313
INSERT_CHECKED_WRITE_BARRIER_CORE $a0, $a1
312314

313-
CmpXchgNoUpdate:
314-
// t1 still contains the original value.
315-
ori $a0, $t1, 0
315+
LOCAL_LABEL(CmpXchgNoUpdate):
316+
// a2 still contains the original value.
317+
ori $a0, $a2, 0
316318

317319
jirl $r0, $ra, 0
318320

@@ -337,10 +339,8 @@ CmpXchgNoUpdate:
337339
//
338340
LEAF_ENTRY RhpCheckedXchg, _TEXT
339341

340-
ld.d $t1, $a0, 0
341-
st.d $a1, $a0, 0
342+
amswap_db.d $t1, $a1, $a0 // exchange
342343

343-
DoCardsXchg:
344344
// We have successfully updated the value of the objectref so now we need a GC write barrier.
345345
// The following barrier code takes the destination in $a0 and the value in $a1 so the arguments are
346346
// already correctly set up.

0 commit comments

Comments
 (0)