Skip to content

Commit 3ac08ee

Browse files
committed
Update fast alloc pattern on arm32 to use (combined_limit - alloc_ptr) >= size, fix few typos in comments
1 parent 39e5b6f commit 3ac08ee

File tree

6 files changed

+62
-53
lines changed

6 files changed

+62
-53
lines changed

src/coreclr/runtime/amd64/AllocFast.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ LEAF_ENTRY RhpNewFast, _TEXT
4141
// Calculate the new alloc pointer to account for the allocation.
4242
add rdx, rsi
4343

44-
// Set the new objects MethodTable pointer.
44+
// Set the new object's MethodTable pointer.
4545
mov [rsi + OFFSETOF__Object__m_pEEType], rbx
4646

4747
// Update the alloc pointer to the newly calculated one.

src/coreclr/runtime/arm/AllocFast.S

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,84 @@
1010
// r0 == MethodTable
1111
.macro NEW_FAST Variation
1212
PROLOG_PUSH "{r4,lr}"
13-
mov r4, r0 // save MethodTable
13+
mov r4, r0 // save MethodTable
1414

1515
// r0 = ee_alloc_context pointer; trashes volatile registers, expects saved lr
1616
INLINE_GET_ALLOC_CONTEXT_BASE
1717

18+
ldr r2, [r4, #OFFSETOF__MethodTable__m_uBaseSize]
19+
20+
// Load potential new object address into r3.
21+
ldr r3, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
22+
23+
// Load and calculate the maximum size of object we can fit.
24+
ldr r1, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
25+
sub r1, r3
26+
1827
// When doing aligned or misaligned allocation we first check
1928
// the alignment and skip to the regular path if it's already
2029
// matching the expectation.
2130
// Otherwise, we try to allocate size + ASM_MIN_OBJECT_SIZE and
2231
// then prepend a dummy free object at the beginning of the
2332
// allocation.
2433
.ifnc \Variation,
25-
ldr r3, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
2634
tst r3, #0x7
2735
.ifc \Variation,Align8
2836
beq 1f // AlreadyAligned
2937
.else // Variation == "Misalign"
3038
bne 1f // AlreadyAligned
3139
.endif
3240

33-
ldr r2, [r4, #OFFSETOF__MethodTable__m_uBaseSize]
3441
add r2, ASM_MIN_OBJECT_SIZE
35-
ldr r3, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
36-
add r2, r3
37-
bcs 2f // AllocFailed
38-
ldr r1, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
42+
43+
// Determine whether the end of the object is too big for the current allocation context. If so,
44+
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
3945
cmp r2, r1
4046
bhi 2f // AllocFailed
4147

42-
// set the new alloc pointer
48+
// Update the alloc pointer to account for the allocation.
49+
add r2, r3
4350
str r2, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
4451

45-
// initialize the padding object preceeding the new object
52+
// Initialize the padding object preceeding the new object.
4653
PREPARE_EXTERNAL_VAR_INDIRECT G_FREE_OBJECT_METHOD_TABLE, r2
4754
str r2, [r3, #OFFSETOF__Object__m_pEEType]
4855
mov r2, #0
4956
str r2, [r3, #OFFSETOF__Array__m_Length]
5057

51-
// calc the new object pointer and initialize it
58+
// Calculate the new object pointer and initialize it.
5259
add r3, ASM_MIN_OBJECT_SIZE
5360
str r4, [r3, #OFFSETOF__Object__m_pEEType]
5461

62+
// Return the object allocated in r0.
5563
mov r0, r3
5664

5765
EPILOG_POP "{r4,pc}"
5866
.endif // Variation != ""
5967

6068
1: // AlreadyAligned
6169

62-
// r4 contains MethodTable pointer
63-
ldr r2, [r4, #OFFSETOF__MethodTable__m_uBaseSize]
64-
6570
// r0: ee_alloc_context pointer
66-
// r4: MethodTable pointer
71+
// r1: ee_alloc_context.combined_limit
6772
// r2: base size
73+
// r3: ee_alloc_context.alloc_ptr
74+
// r4: MethodTable pointer
6875

69-
ldr r3, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
70-
add r2, r3
71-
bcs 2f // AllocFailed
72-
ldr r1, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
76+
// Determine whether the end of the object is too big for the current allocation context. If so,
77+
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
7378
cmp r2, r1
7479
bhi 2f // AllocFailed
7580

76-
// set the new alloc pointer
77-
str r2, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
81+
// Calculate the new alloc pointer to account for the allocation.
82+
add r2, r3
7883

79-
// Set the new object's MethodTable pointer
84+
// Set the new object's MethodTable pointer.
8085
str r4, [r3, #OFFSETOF__Object__m_pEEType]
8186

87+
// Update the alloc pointer to the newly calculated one.
88+
str r2, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
89+
90+
// Return the object allocated in r0.
8291
mov r0, r3
8392

8493
EPILOG_POP "{r4,pc}"
@@ -198,27 +207,27 @@ NESTED_END RhpNewObject, _TEXT
198207
// r6 == string/array size
199208
// r0 == ee_alloc_context*
200209

201-
// Load potential new object address into r12.
202-
ldr r12, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
210+
// Load potential new object address into r3.
211+
ldr r3, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
203212

204-
// Determine whether the end of the object would lie outside of the current allocation context. If so,
205-
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
206-
adds r6, r12
207-
bcs 1f // if we get a carry here, the string/array is too large to fit below 4 GB
213+
// Load and calculate the maximum size of object we can fit
214+
ldr r1, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
215+
sub r1, r3
208216

209-
ldr r12, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
210-
cmp r6, r12
217+
// Determine whether the end of the object is too big for the current allocation context. If so,
218+
// we abandon the attempt to allocate the object directly and fall back to the slow helper.
219+
cmp r6, r1
211220
bhi 1f
212221

213-
// Reload new object address into r12.
214-
ldr r12, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
215-
216-
// Update the alloc pointer to account for the allocation.
217-
str r6, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
222+
// Calculate the alloc pointer to account for the allocation.
223+
add r6, r3
218224

219225
// Set the new object's MethodTable pointer and element count.
220-
str r4, [r12, #OFFSETOF__Object__m_pEEType]
221-
str r5, [r12, #OFFSETOF__Array__m_Length]
226+
str r4, [r3, #OFFSETOF__Object__m_pEEType]
227+
str r5, [r3, #OFFSETOF__Array__m_Length]
228+
229+
// Update the alloc pointer to the newly calculated one.
230+
str r6, [r0, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
222231

223232
// Return the object allocated in r0.
224233
mov r0, r12

src/coreclr/runtime/arm64/AllocFast.S

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Calculate the new alloc pointer to account for the allocation.
3838
add x2, x2, x12
3939

40-
// Set the new objects MethodTable pointer.
40+
// Set the new object's MethodTable pointer.
4141
str x0, [x12, #OFFSETOF__Object__m_pEEType]
4242

4343
// Update the alloc pointer to the newly calculated one.
@@ -79,7 +79,7 @@ LOCAL_LABEL(RhpNewFast_RarePath):
7979
// void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
8080
bl C_FUNC(RhpGcAlloc)
8181

82-
// Set the new objects MethodTable pointer on success.
82+
// Set the new object's MethodTable pointer on success.
8383
cbz x0, LOCAL_LABEL(NewOutOfMemory)
8484

8585
.cfi_remember_state
@@ -111,7 +111,7 @@ LOCAL_LABEL(NewOutOfMemory):
111111
// Load potential new object address into x12.
112112
ldr x12, [x3, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
113113

114-
// Load and calculate the maximum size of object we can fit
114+
// Load and calculate the maximum size of object we can fit.
115115
ldr x13, [x3, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
116116
sub x13, x13, x12
117117

@@ -124,10 +124,10 @@ LOCAL_LABEL(NewOutOfMemory):
124124
bhi C_FUNC(RhpNewVariableSizeObject)
125125
#endif
126126

127-
// Calculate the alloc pointer to account for the allocation.
127+
// Calculate the new alloc pointer to account for the allocation.
128128
add x2, x2, x12
129129

130-
// Set the new objects MethodTable pointer and element count.
130+
// Set the new object's MethodTable pointer and element count.
131131
str x0, [x12, #OFFSETOF__Object__m_pEEType]
132132
str x1, [x12, #OFFSETOF__Array__m_Length]
133133

@@ -263,7 +263,7 @@ LOCAL_LABEL(ArraySizeOverflow):
263263
// void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
264264
bl C_FUNC(RhpGcAlloc)
265265

266-
// Set the new objects MethodTable pointer and length on success.
266+
// Set the new object's MethodTable pointer and length on success.
267267
cbz x0, LOCAL_LABEL(RhpNewVariableSizeObject_OutOfMemory)
268268

269269
.cfi_remember_state

src/coreclr/runtime/arm64/AllocFast.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
;; Load potential new object address into x12.
2828
ldr x12, [x3, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__alloc_ptr)]
2929

30-
;; Load and calculate the maximum size of object we can fit
30+
;; Load and calculate the maximum size of object we can fit.
3131
ldr x13, [x3, #(OFFSETOF__ee_alloc_context + OFFSETOF__ee_alloc_context__combined_limit)]
3232
sub x13, x13, x12
3333

@@ -36,10 +36,10 @@
3636
cmp x2, x13
3737
bhi RhpNewFast_RarePath
3838

39-
;; Calculate the alloc pointer to account for the allocation.
39+
;; Calculate the new alloc pointer to account for the allocation.
4040
add x2, x2, x12
4141

42-
;; Set the new objects MethodTable pointer.
42+
;; Set the new object's MethodTable pointer.
4343
str x0, [x12, #OFFSETOF__Object__m_pEEType]
4444

4545
;; Update the alloc pointer to the newly calculated one.
@@ -119,7 +119,7 @@ NewOutOfMemory
119119
;; Calculate the new alloc pointer to account for the allocation.
120120
add x2, x2, x12
121121

122-
;; Set the new objects MethodTable pointer and element count.
122+
;; Set the new object's MethodTable pointer and element count.
123123
str x0, [x12, #OFFSETOF__Object__m_pEEType]
124124
str x1, [x12, #OFFSETOF__Array__m_Length]
125125

src/coreclr/runtime/loongarch64/AllocFast.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// Calculate the new alloc pointer to account for the allocation.
3737
add.d $a2, $a2, $t3
3838

39-
// Set the new objects MethodTable pointer.
39+
// Set the new object's MethodTable pointer.
4040
st.d $a0, $t3, OFFSETOF__Object__m_pEEType
4141

4242
// Update the alloc pointer to the newly calculated one.
@@ -75,7 +75,7 @@ LOCAL_LABEL(RhpNewFast_RarePath):
7575
// void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
7676
bl C_FUNC(RhpGcAlloc)
7777

78-
// Set the new objects MethodTable pointer on success.
78+
// Set the new object's MethodTable pointer on success.
7979
beqz $a0, LOCAL_LABEL(NewOutOfMemory)
8080

8181
.cfi_remember_state
@@ -117,7 +117,7 @@ LOCAL_LABEL(NewOutOfMemory):
117117
// Calculate the new alloc pointer to account for the allocation.
118118
add.d $a2, $a2, $t3
119119

120-
// Set the new objects MethodTable pointer and element count.
120+
// Set the new object's MethodTable pointer and element count.
121121
st.d $a0, $t3, OFFSETOF__Object__m_pEEType
122122
st.d $a1, $t3, OFFSETOF__Array__m_Length
123123

@@ -233,7 +233,7 @@ LOCAL_LABEL(ArraySizeOverflow):
233233
// void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
234234
bl C_FUNC(RhpGcAlloc)
235235

236-
// Set the new objects MethodTable pointer and length on success.
236+
// Set the new object's MethodTable pointer and length on success.
237237
beqz $a0, LOCAL_LABEL(RhpNewVariableSizeObject_OutOfMemory)
238238

239239
.cfi_remember_state

src/coreclr/runtime/riscv64/AllocFast.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// Calculate the new alloc pointer to account for the allocation.
4242
add t0, t0, t1
4343

44-
// Set the new objects MethodTable pointer.
44+
// Set the new object's MethodTable pointer.
4545
sd s1, OFFSETOF__Object__m_pEEType(t1)
4646

4747
// Update the alloc pointer to the newly calculated one.
@@ -144,7 +144,7 @@ LOCAL_LABEL(NewOutOfMemory):
144144
// Calculate the new alloc pointer to account for the allocation.
145145
add t0, t0, t1
146146

147-
// Set the new objects MethodTable pointer.
147+
// Set the new object's MethodTable pointer.
148148
sd s1, OFFSETOF__Object__m_pEEType(t1)
149149
sd s2, OFFSETOF__Array__m_Length(t1)
150150

0 commit comments

Comments
 (0)