blob: 26717ad79858588b5440bc5ad4eca7ea997d4ad3 [file] [log] [blame]
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_mips64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21 .set noreorder
22 .balign 16
23
24 /* Deliver the given exception */
25 .extern artDeliverExceptionFromCode
26 /* Deliver an exception pending on a thread */
27 .extern artDeliverPendingExceptionFromCode
28
29 /*
Goran Jakovljevic04568812015-04-23 15:27:23 +020030 * Macro that sets up $gp and stores the previous $gp value to $t8.
31 * This macro modifies v1 and t8.
32 */
33.macro SETUP_GP
34 move $v1, $ra
35 bal 1f
36 nop
371:
38 .cpsetup $ra, $t8, 1b
39 move $ra, $v1
40.endm
41
42 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -080043 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Andreas Gampe1a5c4062015-01-15 12:10:47 -080045 * callee-save: padding + $f24-$f31 + $s0-$s7 + $gp + $ra + $s8 = 19 total + 1x8 bytes padding
46 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010047.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -080048 daddiu $sp, $sp, -160
49 .cfi_adjust_cfa_offset 160
50
51 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010052#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 160)
53#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -080054#endif
55
56 sd $ra, 152($sp)
57 .cfi_rel_offset 31, 152
58 sd $s8, 144($sp)
59 .cfi_rel_offset 30, 144
Goran Jakovljevic04568812015-04-23 15:27:23 +020060 sd $t8, 136($sp) # t8 holds caller's gp, now save it to the stack.
61 .cfi_rel_offset 28, 136 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080062 sd $s7, 128($sp)
63 .cfi_rel_offset 23, 128
64 sd $s6, 120($sp)
65 .cfi_rel_offset 22, 120
66 sd $s5, 112($sp)
67 .cfi_rel_offset 21, 112
68 sd $s4, 104($sp)
69 .cfi_rel_offset 20, 104
70 sd $s3, 96($sp)
71 .cfi_rel_offset 19, 96
72 sd $s2, 88($sp)
73 .cfi_rel_offset 18, 88
74 sd $s1, 80($sp)
75 .cfi_rel_offset 17, 80
76 sd $s0, 72($sp)
77 .cfi_rel_offset 16, 72
78
79 // FP callee-saves
80 s.d $f31, 64($sp)
81 s.d $f30, 56($sp)
82 s.d $f29, 48($sp)
83 s.d $f28, 40($sp)
84 s.d $f27, 32($sp)
85 s.d $f26, 24($sp)
86 s.d $f25, 16($sp)
87 s.d $f24, 8($sp)
88
89 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +020090 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
91 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +010092 ld $t1, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +020093 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080094 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
95.endm
96
97 /*
98 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010099 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly). Restoration assumes
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800100 * non-moving GC.
101 * Does not include rSUSPEND or rSELF
102 * callee-save: padding + $s2-$s7 + $gp + $ra + $s8 = 9 total + 1x8 bytes padding
103 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100104.macro SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800105 daddiu $sp, $sp, -80
106 .cfi_adjust_cfa_offset 80
107
108 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100109#if (FRAME_SIZE_SAVE_REFS_ONLY != 80)
110#error "FRAME_SIZE_SAVE_REFS_ONLY(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800111#endif
112
113 sd $ra, 72($sp)
114 .cfi_rel_offset 31, 72
115 sd $s8, 64($sp)
116 .cfi_rel_offset 30, 64
Goran Jakovljevic04568812015-04-23 15:27:23 +0200117 sd $t8, 56($sp) # t8 holds caller's gp, now save it to the stack.
118 .cfi_rel_offset 28, 56 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800119 sd $s7, 48($sp)
120 .cfi_rel_offset 23, 48
121 sd $s6, 40($sp)
122 .cfi_rel_offset 22, 40
123 sd $s5, 32($sp)
124 .cfi_rel_offset 21, 32
125 sd $s4, 24($sp)
126 .cfi_rel_offset 20, 24
127 sd $s3, 16($sp)
128 .cfi_rel_offset 19, 16
129 sd $s2, 8($sp)
130 .cfi_rel_offset 18, 8
131 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200132 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
133 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100134 ld $t1, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200135 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800136 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
137.endm
138
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100139.macro RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800140 ld $ra, 72($sp)
141 .cfi_restore 31
142 ld $s8, 64($sp)
143 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200144 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800145 .cfi_restore 28
146 ld $s7, 48($sp)
147 .cfi_restore 23
148 ld $s6, 40($sp)
149 .cfi_restore 22
150 ld $s5, 32($sp)
151 .cfi_restore 21
152 ld $s4, 24($sp)
153 .cfi_restore 20
154 ld $s3, 16($sp)
155 .cfi_restore 19
156 ld $s2, 8($sp)
157 .cfi_restore 18
158 daddiu $sp, $sp, 80
159 .cfi_adjust_cfa_offset -80
Goran Jakovljevic04568812015-04-23 15:27:23 +0200160 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800161.endm
162
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100163.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800164 ld $ra, 72($sp)
165 .cfi_restore 31
166 ld $s8, 64($sp)
167 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200168 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800169 .cfi_restore 28
170 ld $s7, 48($sp)
171 .cfi_restore 23
172 ld $s6, 40($sp)
173 .cfi_restore 22
174 ld $s5, 32($sp)
175 .cfi_restore 21
176 ld $s4, 24($sp)
177 .cfi_restore 20
178 ld $s3, 16($sp)
179 .cfi_restore 19
180 ld $s2, 8($sp)
181 .cfi_restore 18
Goran Jakovljevic04568812015-04-23 15:27:23 +0200182 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800183 jalr $zero, $ra
184 daddiu $sp, $sp, 80
185 .cfi_adjust_cfa_offset -80
186.endm
187
188// This assumes the top part of these stack frame types are identical.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100189#define REFS_AND_ARGS_MINUS_REFS_SIZE (FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800190
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100191.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800192 daddiu $sp, $sp, -208
193 .cfi_adjust_cfa_offset 208
194
195 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100196#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 208)
197#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800198#endif
199
200 sd $ra, 200($sp) # = kQuickCalleeSaveFrame_RefAndArgs_LrOffset
201 .cfi_rel_offset 31, 200
202 sd $s8, 192($sp)
203 .cfi_rel_offset 30, 192
Goran Jakovljevic04568812015-04-23 15:27:23 +0200204 sd $t8, 184($sp) # t8 holds caller's gp, now save it to the stack.
205 .cfi_rel_offset 28, 184 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800206 sd $s7, 176($sp)
207 .cfi_rel_offset 23, 176
208 sd $s6, 168($sp)
209 .cfi_rel_offset 22, 168
210 sd $s5, 160($sp)
211 .cfi_rel_offset 21, 160
212 sd $s4, 152($sp)
213 .cfi_rel_offset 20, 152
214 sd $s3, 144($sp)
215 .cfi_rel_offset 19, 144
216 sd $s2, 136($sp)
217 .cfi_rel_offset 18, 136
218
219 sd $a7, 128($sp)
220 .cfi_rel_offset 11, 128
221 sd $a6, 120($sp)
222 .cfi_rel_offset 10, 120
223 sd $a5, 112($sp)
224 .cfi_rel_offset 9, 112
225 sd $a4, 104($sp)
226 .cfi_rel_offset 8, 104
227 sd $a3, 96($sp)
228 .cfi_rel_offset 7, 96
229 sd $a2, 88($sp)
230 .cfi_rel_offset 6, 88
231 sd $a1, 80($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset
232 .cfi_rel_offset 5, 80
233
234 s.d $f19, 72($sp)
235 s.d $f18, 64($sp)
236 s.d $f17, 56($sp)
237 s.d $f16, 48($sp)
238 s.d $f15, 40($sp)
239 s.d $f14, 32($sp)
240 s.d $f13, 24($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset
241 s.d $f12, 16($sp) # This isn't necessary to store.
Douglas Leung8223b802015-04-28 17:22:29 -0700242 # 1x8 bytes padding + Method*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800243.endm
244
Douglas Leung8223b802015-04-28 17:22:29 -0700245 /*
246 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100247 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes
Douglas Leung8223b802015-04-28 17:22:29 -0700248 * non-moving GC.
249 * callee-save: padding + $f12-$f19 + $a1-$a7 + $s2-$s7 + $gp + $ra + $s8 = 24 total + 1 words padding + Method*
250 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100251.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
252 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800253 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200254 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
255 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100256 ld $t1, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200257 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800258 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
259.endm
260
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100261.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
262 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Mathieu Chartiere401d142015-04-22 13:56:20 -0700263 sd $a0, 0($sp) # Place Method* at bottom of stack.
Douglas Leung8223b802015-04-28 17:22:29 -0700264 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
265.endm
266
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100267.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800268 ld $ra, 200($sp)
269 .cfi_restore 31
270 ld $s8, 192($sp)
271 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200272 ld $t8, 184($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800273 .cfi_restore 28
274 ld $s7, 176($sp)
275 .cfi_restore 23
276 ld $s6, 168($sp)
277 .cfi_restore 22
278 ld $s5, 160($sp)
279 .cfi_restore 21
280 ld $s4, 152($sp)
281 .cfi_restore 20
282 ld $s3, 144($sp)
283 .cfi_restore 19
284 ld $s2, 136($sp)
285 .cfi_restore 18
286
287 ld $a7, 128($sp)
288 .cfi_restore 11
289 ld $a6, 120($sp)
290 .cfi_restore 10
291 ld $a5, 112($sp)
292 .cfi_restore 9
293 ld $a4, 104($sp)
294 .cfi_restore 8
295 ld $a3, 96($sp)
296 .cfi_restore 7
297 ld $a2, 88($sp)
298 .cfi_restore 6
299 ld $a1, 80($sp)
300 .cfi_restore 5
301
302 l.d $f19, 72($sp)
303 l.d $f18, 64($sp)
304 l.d $f17, 56($sp)
305 l.d $f16, 48($sp)
306 l.d $f15, 40($sp)
307 l.d $f14, 32($sp)
308 l.d $f13, 24($sp)
309 l.d $f12, 16($sp)
310
Goran Jakovljevic04568812015-04-23 15:27:23 +0200311 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800312 daddiu $sp, $sp, 208
313 .cfi_adjust_cfa_offset -208
314.endm
315
316 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100317 * Macro that sets up the callee save frame to conform with
318 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
319 * callee-save: $at + $v0-$v1 + $a0-$a7 + $t0-$t3 + $s0-$s7 + $t8-$t9 + $gp + $s8 + $ra + $s8,
320 * $f0-$f31; 28(GPR)+ 32(FPR) + 1x8 bytes padding + method*
321 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
322 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100323.macro SETUP_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100324 daddiu $sp, $sp, -496
325 .cfi_adjust_cfa_offset 496
326
327 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100328#if (FRAME_SIZE_SAVE_EVERYTHING != 496)
329#error "FRAME_SIZE_SAVE_EVERYTHING(MIPS64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100330#endif
331
332 // Save core registers.
333 sd $ra, 488($sp)
334 .cfi_rel_offset 31, 488
335 sd $s8, 480($sp)
336 .cfi_rel_offset 30, 480
Vladimir Marko952dbb12016-07-28 12:01:51 +0100337 sd $t9, 464($sp)
338 .cfi_rel_offset 25, 464
339 sd $t8, 456($sp)
340 .cfi_rel_offset 24, 456
341 sd $s7, 448($sp)
342 .cfi_rel_offset 23, 448
343 sd $s6, 440($sp)
344 .cfi_rel_offset 22, 440
345 sd $s5, 432($sp)
346 .cfi_rel_offset 21, 432
347 sd $s4, 424($sp)
348 .cfi_rel_offset 20, 424
349 sd $s3, 416($sp)
350 .cfi_rel_offset 19, 416
351 sd $s2, 408($sp)
352 .cfi_rel_offset 18, 408
353 sd $s1, 400($sp)
354 .cfi_rel_offset 17, 400
355 sd $s0, 392($sp)
356 .cfi_rel_offset 16, 392
357 sd $t3, 384($sp)
358 .cfi_rel_offset 15, 384
359 sd $t2, 376($sp)
360 .cfi_rel_offset 14, 376
361 sd $t1, 368($sp)
362 .cfi_rel_offset 13, 368
363 sd $t0, 360($sp)
364 .cfi_rel_offset 12, 360
365 sd $a7, 352($sp)
366 .cfi_rel_offset 11, 352
367 sd $a6, 344($sp)
368 .cfi_rel_offset 10, 344
369 sd $a5, 336($sp)
370 .cfi_rel_offset 9, 336
371 sd $a4, 328($sp)
372 .cfi_rel_offset 8, 328
373 sd $a3, 320($sp)
374 .cfi_rel_offset 7, 320
375 sd $a2, 312($sp)
376 .cfi_rel_offset 6, 312
377 sd $a1, 304($sp)
378 .cfi_rel_offset 5, 304
379 sd $a0, 296($sp)
380 .cfi_rel_offset 4, 296
381 sd $v1, 288($sp)
382 .cfi_rel_offset 3, 288
383 sd $v0, 280($sp)
384 .cfi_rel_offset 2, 280
385
386 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
387 bal 1f
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200388 .set push
389 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100390 sd $at, 272($sp)
391 .cfi_rel_offset 1, 272
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200392 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +01003931:
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200394 .cpsetup $ra, 472, 1b
Vladimir Marko952dbb12016-07-28 12:01:51 +0100395
396 // Save FP registers.
397 s.d $f31, 264($sp)
398 s.d $f30, 256($sp)
399 s.d $f29, 248($sp)
400 s.d $f28, 240($sp)
401 s.d $f27, 232($sp)
402 s.d $f26, 224($sp)
403 s.d $f25, 216($sp)
404 s.d $f24, 208($sp)
405 s.d $f23, 200($sp)
406 s.d $f22, 192($sp)
407 s.d $f21, 184($sp)
408 s.d $f20, 176($sp)
409 s.d $f19, 168($sp)
410 s.d $f18, 160($sp)
411 s.d $f17, 152($sp)
412 s.d $f16, 144($sp)
413 s.d $f15, 136($sp)
414 s.d $f14, 128($sp)
415 s.d $f13, 120($sp)
416 s.d $f12, 112($sp)
417 s.d $f11, 104($sp)
418 s.d $f10, 96($sp)
419 s.d $f9, 88($sp)
420 s.d $f8, 80($sp)
421 s.d $f7, 72($sp)
422 s.d $f6, 64($sp)
423 s.d $f5, 56($sp)
424 s.d $f4, 48($sp)
425 s.d $f3, 40($sp)
426 s.d $f2, 32($sp)
427 s.d $f1, 24($sp)
428 s.d $f0, 16($sp)
429
430 # load appropriate callee-save-method
431 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
432 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100433 ld $t1, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET($t1)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100434 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
435 # Place sp in Thread::Current()->top_quick_frame.
436 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
437.endm
438
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100439.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100440 // Restore FP registers.
441 l.d $f31, 264($sp)
442 l.d $f30, 256($sp)
443 l.d $f29, 248($sp)
444 l.d $f28, 240($sp)
445 l.d $f27, 232($sp)
446 l.d $f26, 224($sp)
447 l.d $f25, 216($sp)
448 l.d $f24, 208($sp)
449 l.d $f23, 200($sp)
450 l.d $f22, 192($sp)
451 l.d $f21, 184($sp)
452 l.d $f20, 176($sp)
453 l.d $f19, 168($sp)
454 l.d $f18, 160($sp)
455 l.d $f17, 152($sp)
456 l.d $f16, 144($sp)
457 l.d $f15, 136($sp)
458 l.d $f14, 128($sp)
459 l.d $f13, 120($sp)
460 l.d $f12, 112($sp)
461 l.d $f11, 104($sp)
462 l.d $f10, 96($sp)
463 l.d $f9, 88($sp)
464 l.d $f8, 80($sp)
465 l.d $f7, 72($sp)
466 l.d $f6, 64($sp)
467 l.d $f5, 56($sp)
468 l.d $f4, 48($sp)
469 l.d $f3, 40($sp)
470 l.d $f2, 32($sp)
471 l.d $f1, 24($sp)
472 l.d $f0, 16($sp)
473
474 // Restore core registers.
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200475 .cpreturn
Vladimir Marko952dbb12016-07-28 12:01:51 +0100476 ld $ra, 488($sp)
477 .cfi_restore 31
478 ld $s8, 480($sp)
479 .cfi_restore 30
Vladimir Marko952dbb12016-07-28 12:01:51 +0100480 ld $t9, 464($sp)
481 .cfi_restore 25
482 ld $t8, 456($sp)
483 .cfi_restore 24
484 ld $s7, 448($sp)
485 .cfi_restore 23
486 ld $s6, 440($sp)
487 .cfi_restore 22
488 ld $s5, 432($sp)
489 .cfi_restore 21
490 ld $s4, 424($sp)
491 .cfi_restore 20
492 ld $s3, 416($sp)
493 .cfi_restore 19
494 ld $s2, 408($sp)
495 .cfi_restore 18
496 ld $s1, 400($sp)
497 .cfi_restore 17
498 ld $s0, 392($sp)
499 .cfi_restore 16
500 ld $t3, 384($sp)
501 .cfi_restore 15
502 ld $t2, 376($sp)
503 .cfi_restore 14
504 ld $t1, 368($sp)
505 .cfi_restore 13
506 ld $t0, 360($sp)
507 .cfi_restore 12
508 ld $a7, 352($sp)
509 .cfi_restore 11
510 ld $a6, 344($sp)
511 .cfi_restore 10
512 ld $a5, 336($sp)
513 .cfi_restore 9
514 ld $a4, 328($sp)
515 .cfi_restore 8
516 ld $a3, 320($sp)
517 .cfi_restore 7
518 ld $a2, 312($sp)
519 .cfi_restore 6
520 ld $a1, 304($sp)
521 .cfi_restore 5
522 ld $a0, 296($sp)
523 .cfi_restore 4
524 ld $v1, 288($sp)
525 .cfi_restore 3
526 ld $v0, 280($sp)
527 .cfi_restore 2
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200528 .set push
529 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100530 ld $at, 272($sp)
531 .cfi_restore 1
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200532 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +0100533
Vladimir Marko952dbb12016-07-28 12:01:51 +0100534 daddiu $sp, $sp, 496
535 .cfi_adjust_cfa_offset -496
536.endm
537
538 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800539 * Macro that set calls through to artDeliverPendingExceptionFromCode,
540 * where the pending
541 * exception is Thread::Current()->exception_
542 */
543.macro DELIVER_PENDING_EXCEPTION
Goran Jakovljevic04568812015-04-23 15:27:23 +0200544 SETUP_GP
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100545 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME # save callee saves for throw
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800546 dla $t9, artDeliverPendingExceptionFromCode
547 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
548 move $a0, rSELF # pass Thread::Current
549.endm
550
551.macro RETURN_IF_NO_EXCEPTION
552 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100553 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800554 bne $t0, $zero, 1f # success if no exception is pending
555 nop
556 jalr $zero, $ra
557 nop
5581:
559 DELIVER_PENDING_EXCEPTION
560.endm
561
562.macro RETURN_IF_ZERO
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100563 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800564 bne $v0, $zero, 1f # success?
565 nop
566 jalr $zero, $ra # return on success
567 nop
5681:
569 DELIVER_PENDING_EXCEPTION
570.endm
571
572.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100573 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800574 beq $v0, $zero, 1f # success?
575 nop
576 jalr $zero, $ra # return on success
577 nop
5781:
579 DELIVER_PENDING_EXCEPTION
580.endm
581
582 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100583 * On stack replacement stub.
584 * On entry:
585 * a0 = stack to copy
586 * a1 = size of stack
587 * a2 = pc to call
588 * a3 = JValue* result
589 * a4 = shorty
590 * a5 = thread
591 */
592ENTRY art_quick_osr_stub
593 move $t0, $sp # save stack pointer
594 daddiu $t1, $sp, -112 # reserve stack space
595 dsrl $t1, $t1, 4 # enforce 16 byte stack alignment
596 dsll $sp, $t1, 4 # update stack pointer
597
598 // Save callee general purpose registers, SP, T8(GP), RA, A3, and A4 (8x14 bytes)
599 sd $ra, 104($sp)
600 .cfi_rel_offset 31, 104
601 sd $s8, 96($sp)
602 .cfi_rel_offset 30, 96
603 sd $t0, 88($sp) # save original stack pointer stored in t0
604 .cfi_rel_offset 29, 88
605 sd $t8, 80($sp) # t8 holds caller's gp, now save it to the stack.
606 .cfi_rel_offset 28, 80 # Value from gp is pushed, so set the cfi offset accordingly.
607 sd $s7, 72($sp)
608 .cfi_rel_offset 23, 72
609 sd $s6, 64($sp)
610 .cfi_rel_offset 22, 64
611 sd $s5, 56($sp)
612 .cfi_rel_offset 21, 56
613 sd $s4, 48($sp)
614 .cfi_rel_offset 20, 48
615 sd $s3, 40($sp)
616 .cfi_rel_offset 19, 40
617 sd $s2, 32($sp)
618 .cfi_rel_offset 18, 32
619 sd $s1, 24($sp)
620 .cfi_rel_offset 17, 24
621 sd $s0, 16($sp)
622 .cfi_rel_offset 16, 16
623 sd $a4, 8($sp)
624 .cfi_rel_offset 8, 8
625 sd $a3, 0($sp)
626 .cfi_rel_offset 7, 0
627 move rSELF, $a5 # Save managed thread pointer into rSELF
628
629 daddiu $sp, $sp, -16
630 jal .Losr_entry
631 sd $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
632 daddiu $sp, $sp, 16
633
634 // Restore return value address and shorty address
635 ld $a4, 8($sp) # shorty address
636 .cfi_restore 8
637 ld $a3, 0($sp) # result value address
638 .cfi_restore 7
639
640 lbu $t1, 0($a4) # load return type
641 li $t2, 'D' # put char 'D' into t2
642 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'D'
643 li $t2, 'F' # put char 'F' into t2
644 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'F'
645 nop
646 b .Losr_exit
647 dsrl $v1, $v0, 32 # put high half of result in v1
648.Losr_fp_result:
649 mfc1 $v0, $f0
650 mfhc1 $v1, $f0 # put high half of FP result in v1
651.Losr_exit:
652 sw $v0, 0($a3) # store low half of result
653 sw $v1, 4($a3) # store high half of result
654
655 // Restore callee registers
656 ld $ra, 104($sp)
657 .cfi_restore 31
658 ld $s8, 96($sp)
659 .cfi_restore 30
660 ld $t0, 88($sp) # save SP into t0 for now
661 .cfi_restore 29
662 ld $t8, 80($sp) # Restore gp back to it's temp storage.
663 .cfi_restore 28
664 ld $s7, 72($sp)
665 .cfi_restore 23
666 ld $s6, 64($sp)
667 .cfi_restore 22
668 ld $s5, 56($sp)
669 .cfi_restore 21
670 ld $s4, 48($sp)
671 .cfi_restore 20
672 ld $s3, 40($sp)
673 .cfi_restore 19
674 ld $s2, 32($sp)
675 .cfi_restore 18
676 ld $s1, 24($sp)
677 .cfi_restore 17
678 ld $s0, 16($sp)
679 .cfi_restore 16
680 jalr $zero, $ra
681 move $sp, $t0
682
683.Losr_entry:
684 dsubu $sp, $sp, $a1 # Reserve space for callee stack
685 daddiu $a1, $a1, -8
686 daddu $t0, $a1, $sp
687 sw $ra, 0($t0) # Store low half of RA per compiler ABI
688 dsrl $t1, $ra, 32
689 sw $t1, 4($t0) # Store high half of RA per compiler ABI
690
691 // Copy arguments into callee stack
692 // Use simple copy routine for now.
693 // 4 bytes per slot.
694 // a0 = source address
695 // a1 = args length in bytes (does not include 8 bytes for RA)
696 // sp = destination address
697 beqz $a1, .Losr_loop_exit
698 daddiu $a1, $a1, -4
699 daddu $t1, $a0, $a1
700 daddu $t2, $sp, $a1
701.Losr_loop_entry:
702 lw $t0, 0($t1)
703 daddiu $t1, $t1, -4
704 sw $t0, 0($t2)
705 bne $sp, $t2, .Losr_loop_entry
706 daddiu $t2, $t2, -4
707
708.Losr_loop_exit:
709 move $t9, $a2
710 jalr $zero, $t9 # Jump to the OSR entry point.
711 nop
712END art_quick_osr_stub
713
714 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800715 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
716 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
717 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200718ENTRY_NO_GP art_quick_do_long_jump
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800719 l.d $f0, 0($a1)
720 l.d $f1, 8($a1)
721 l.d $f2, 16($a1)
722 l.d $f3, 24($a1)
723 l.d $f4, 32($a1)
724 l.d $f5, 40($a1)
725 l.d $f6, 48($a1)
726 l.d $f7, 56($a1)
727 l.d $f8, 64($a1)
728 l.d $f9, 72($a1)
729 l.d $f10, 80($a1)
730 l.d $f11, 88($a1)
731 l.d $f12, 96($a1)
732 l.d $f13, 104($a1)
733 l.d $f14, 112($a1)
734 l.d $f15, 120($a1)
735 l.d $f16, 128($a1)
736 l.d $f17, 136($a1)
737 l.d $f18, 144($a1)
738 l.d $f19, 152($a1)
739 l.d $f20, 160($a1)
740 l.d $f21, 168($a1)
741 l.d $f22, 176($a1)
742 l.d $f23, 184($a1)
743 l.d $f24, 192($a1)
744 l.d $f25, 200($a1)
745 l.d $f26, 208($a1)
746 l.d $f27, 216($a1)
747 l.d $f28, 224($a1)
748 l.d $f29, 232($a1)
749 l.d $f30, 240($a1)
750 l.d $f31, 248($a1)
751 .set push
752 .set nomacro
753 .set noat
754# no need to load zero
755 ld $at, 8($a0)
756 .set pop
757 ld $v0, 16($a0)
758 ld $v1, 24($a0)
759# a0 has to be loaded last
760 ld $a1, 40($a0)
761 ld $a2, 48($a0)
762 ld $a3, 56($a0)
763 ld $a4, 64($a0)
764 ld $a5, 72($a0)
765 ld $a6, 80($a0)
766 ld $a7, 88($a0)
767 ld $t0, 96($a0)
768 ld $t1, 104($a0)
769 ld $t2, 112($a0)
770 ld $t3, 120($a0)
771 ld $s0, 128($a0)
772 ld $s1, 136($a0)
773 ld $s2, 144($a0)
774 ld $s3, 152($a0)
775 ld $s4, 160($a0)
776 ld $s5, 168($a0)
777 ld $s6, 176($a0)
778 ld $s7, 184($a0)
779 ld $t8, 192($a0)
780 ld $t9, 200($a0)
781# no need to load k0, k1
782 ld $gp, 224($a0)
783 ld $sp, 232($a0)
784 ld $s8, 240($a0)
785 ld $ra, 248($a0)
786 ld $a0, 32($a0)
787 move $v0, $zero # clear result registers v0 and v1
Andreas Gampedbf056d2015-09-25 08:24:13 -0700788 jalr $zero, $t9 # do long jump (do not use ra, it must not be clobbered)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800789 move $v1, $zero
790END art_quick_do_long_jump
791
Maja Gagic6ea651f2015-02-24 16:55:04 +0100792 /*
793 * Called by managed code, saves most registers (forms basis of long jump
794 * context) and passes the bottom of the stack.
795 * artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200796 * the bottom of the thread. On entry a0 holds Throwable*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100797 */
798ENTRY art_quick_deliver_exception
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100799 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100800 dla $t9, artDeliverExceptionFromCode
801 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
802 move $a1, rSELF # pass Thread::Current
803END art_quick_deliver_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800804
Maja Gagic6ea651f2015-02-24 16:55:04 +0100805 /*
806 * Called by managed code to create and deliver a NullPointerException
807 */
808 .extern artThrowNullPointerExceptionFromCode
809ENTRY art_quick_throw_null_pointer_exception
810.Lart_quick_throw_null_pointer_exception_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100811 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100812 dla $t9, artThrowNullPointerExceptionFromCode
813 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
814 move $a0, rSELF # pass Thread::Current
815END art_quick_throw_null_pointer_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800816
Maja Gagic6ea651f2015-02-24 16:55:04 +0100817 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100818 * Call installed by a signal handler to create and deliver a NullPointerException
819 */
820 .extern artThrowNullPointerExceptionFromSignal
821ENTRY art_quick_throw_null_pointer_exception_from_signal
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100822 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100823 dla $t9, artThrowNullPointerExceptionFromSignal
824 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uinptr_t, Thread*)
825 move $a1, rSELF # pass Thread::Current
826END art_quick_throw_null_pointer_exception
827
828 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100829 * Called by managed code to create and deliver an ArithmeticException
830 */
831 .extern artThrowDivZeroFromCode
832ENTRY art_quick_throw_div_zero
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100833 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100834 dla $t9, artThrowDivZeroFromCode
835 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
836 move $a0, rSELF # pass Thread::Current
837END art_quick_throw_div_zero
838
839 /*
840 * Called by managed code to create and deliver an
841 * ArrayIndexOutOfBoundsException
842 */
843 .extern artThrowArrayBoundsFromCode
844ENTRY art_quick_throw_array_bounds
845.Lart_quick_throw_array_bounds_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100846 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100847 dla $t9, artThrowArrayBoundsFromCode
848 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
849 move $a2, rSELF # pass Thread::Current
850END art_quick_throw_array_bounds
851
852 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100853 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
854 * as if thrown from a call to String.charAt().
855 */
856 .extern artThrowStringBoundsFromCode
857ENTRY art_quick_throw_string_bounds
858.Lart_quick_throw_string_bounds_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100859 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100860 dla $t9, artThrowStringBoundsFromCode
861 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
862 move $a2, rSELF # pass Thread::Current
863END art_quick_throw_string_bounds
864
865 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100866 * Called by managed code to create and deliver a StackOverflowError.
867 */
868 .extern artThrowStackOverflowFromCode
869ENTRY art_quick_throw_stack_overflow
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100870 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100871 dla $t9, artThrowStackOverflowFromCode
872 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
873 move $a0, rSELF # pass Thread::Current
874END art_quick_throw_stack_overflow
875
876 /*
877 * Called by managed code to create and deliver a NoSuchMethodError.
878 */
879 .extern artThrowNoSuchMethodFromCode
880ENTRY art_quick_throw_no_such_method
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100881 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100882 dla $t9, artThrowNoSuchMethodFromCode
883 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
884 move $a1, rSELF # pass Thread::Current
885END art_quick_throw_no_such_method
886
887 /*
888 * All generated callsites for interface invokes and invocation slow paths will load arguments
889 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
890 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
891 * stack and call the appropriate C helper.
892 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
893 *
894 * The helper will attempt to locate the target and return a 128-bit result in $v0/$v1 consisting
895 * of the target Method* in $v0 and method->code_ in $v1.
896 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700897 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
Maja Gagic6ea651f2015-02-24 16:55:04 +0100898 * thread and we branch to another stub to deliver it.
899 *
900 * On success this wrapper will restore arguments and *jump* to the target, leaving the ra
901 * pointing back to the original caller.
902 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700903.macro INVOKE_TRAMPOLINE_BODY cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100904 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100905 SETUP_SAVE_REFS_AND_ARGS_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100906 move $a2, rSELF # pass Thread::Current
907 jal \cxx_name # (method_idx, this, Thread*, $sp)
908 move $a3, $sp # pass $sp
Maja Gagic6ea651f2015-02-24 16:55:04 +0100909 move $a0, $v0 # save target Method*
910 move $t9, $v1 # save $v0->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100911 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100912 beq $v0, $zero, 1f
913 nop
914 jalr $zero, $t9
915 nop
9161:
917 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700918.endm
919.macro INVOKE_TRAMPOLINE c_name, cxx_name
920ENTRY \c_name
921 INVOKE_TRAMPOLINE_BODY \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100922END \c_name
923.endm
924
Maja Gagic6ea651f2015-02-24 16:55:04 +0100925INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
926
927INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
928INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
929INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
930INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800931
932 # On entry:
933 # t0 = shorty
934 # t1 = ptr to arg_array
935 # t2 = number of argument bytes remain
936 # v0 = ptr to stack frame where to copy arg_array
937 # This macro modifies t3, t9 and v0
938.macro LOOP_OVER_SHORTY_LOADING_REG gpu, fpu, label
939 lbu $t3, 0($t0) # get argument type from shorty
940 beqz $t3, \label
941 daddiu $t0, 1
942 li $t9, 68 # put char 'D' into t9
943 beq $t9, $t3, 1f # branch if result type char == 'D'
944 li $t9, 70 # put char 'F' into t9
945 beq $t9, $t3, 2f # branch if result type char == 'F'
946 li $t9, 74 # put char 'J' into t9
947 beq $t9, $t3, 3f # branch if result type char == 'J'
948 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +0100949 lw $\gpu, 0($t1)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800950 sw $\gpu, 0($v0)
951 daddiu $v0, 4
952 daddiu $t1, 4
953 b 4f
954 daddiu $t2, -4 # delay slot
955
9561: # found double
957 lwu $t3, 0($t1)
958 mtc1 $t3, $\fpu
959 sw $t3, 0($v0)
960 lwu $t3, 4($t1)
961 mthc1 $t3, $\fpu
962 sw $t3, 4($v0)
963 daddiu $v0, 8
964 daddiu $t1, 8
965 b 4f
966 daddiu $t2, -8 # delay slot
967
9682: # found float
969 lwu $t3, 0($t1)
970 mtc1 $t3, $\fpu
971 sw $t3, 0($v0)
972 daddiu $v0, 4
973 daddiu $t1, 4
974 b 4f
975 daddiu $t2, -4 # delay slot
976
9773: # found long (8 bytes)
978 lwu $t3, 0($t1)
979 sw $t3, 0($v0)
980 lwu $t9, 4($t1)
981 sw $t9, 4($v0)
982 dsll $t9, $t9, 32
983 or $\gpu, $t9, $t3
984 daddiu $v0, 8
985 daddiu $t1, 8
986 daddiu $t2, -8
9874:
988.endm
989
990 /*
991 * Invocation stub for quick code.
992 * On entry:
993 * a0 = method pointer
994 * a1 = argument array that must at least contain the this ptr.
995 * a2 = size of argument array in bytes
996 * a3 = (managed) thread pointer
997 * a4 = JValue* result
998 * a5 = shorty
999 */
Goran Jakovljevic04568812015-04-23 15:27:23 +02001000ENTRY_NO_GP art_quick_invoke_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001001 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra onto the stack
1002 daddiu $sp, $sp, -48
1003 .cfi_adjust_cfa_offset 48
1004 sd $ra, 40($sp)
1005 .cfi_rel_offset 31, 40
1006 sd $s8, 32($sp)
1007 .cfi_rel_offset 30, 32
1008 sd $s1, 24($sp)
1009 .cfi_rel_offset 17, 24
1010 sd $s0, 16($sp)
1011 .cfi_rel_offset 16, 16
1012 sd $a5, 8($sp)
1013 .cfi_rel_offset 9, 8
1014 sd $a4, 0($sp)
1015 .cfi_rel_offset 8, 0
1016
1017 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1018 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1019 move $s8, $sp # save sp in s8 (fp)
1020
Mathieu Chartiere401d142015-04-22 13:56:20 -07001021 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001022 dsrl $t3, $t3, 4 # shift the frame size right 4
1023 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1024 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1025
1026 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1027 daddiu $t1, $a1, 4 # t1 = ptr to arg_array[4] (skip this ptr)
1028 daddiu $t2, $a2, -4 # t2 = number of argument bytes remain (skip this ptr)
Nikola Veljkovic80f7a572015-06-02 17:27:53 +02001029 daddiu $v0, $sp, 12 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001030 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_fn
1031 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_fn
1032 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_fn
1033 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_fn
1034 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_fn
1035 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_fn
1036
1037 # copy arguments onto stack (t2 should be multiples of 4)
1038 ble $t2, $zero, call_fn # t2 = number of argument bytes remain
10391:
1040 lw $t3, 0($t1) # load from argument array
1041 daddiu $t1, $t1, 4
1042 sw $t3, 0($v0) # save to stack
1043 daddiu $t2, -4
1044 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1045 daddiu $v0, $v0, 4
1046
1047call_fn:
1048 # call method (a0 and a1 have been untouched)
1049 lwu $a1, 0($a1) # make a1 = this ptr
Mathieu Chartiere401d142015-04-22 13:56:20 -07001050 sw $a1, 8($sp) # copy this ptr (skip 8 bytes for ArtMethod*)
1051 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1052 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001053 jalr $t9 # call the method
1054 nop
1055 move $sp, $s8 # restore sp
1056
1057 # pop a4, a5, s1(rSELF), s8, ra off of the stack
1058 ld $a4, 0($sp)
1059 .cfi_restore 8
1060 ld $a5, 8($sp)
1061 .cfi_restore 9
1062 ld $s0, 16($sp)
1063 .cfi_restore 16
1064 ld $s1, 24($sp)
1065 .cfi_restore 17
1066 ld $s8, 32($sp)
1067 .cfi_restore 30
1068 ld $ra, 40($sp)
1069 .cfi_restore 31
1070 daddiu $sp, $sp, 48
1071 .cfi_adjust_cfa_offset -48
1072
1073 # a4 = JValue* result
1074 # a5 = shorty string
1075 lbu $t1, 0($a5) # get result type from shorty
1076 li $t2, 68 # put char 'D' into t2
1077 beq $t1, $t2, 1f # branch if result type char == 'D'
1078 li $t3, 70 # put char 'F' into t3
1079 beq $t1, $t3, 1f # branch if result type char == 'F'
1080 sw $v0, 0($a4) # store the result
1081 dsrl $v1, $v0, 32
1082 jalr $zero, $ra
1083 sw $v1, 4($a4) # store the other half of the result
10841:
1085 mfc1 $v0, $f0
1086 mfhc1 $v1, $f0
1087 sw $v0, 0($a4) # store the result
1088 jalr $zero, $ra
1089 sw $v1, 4($a4) # store the other half of the result
1090END art_quick_invoke_stub
1091
1092 /*
1093 * Invocation static stub for quick code.
1094 * On entry:
1095 * a0 = method pointer
1096 * a1 = argument array that must at least contain the this ptr.
1097 * a2 = size of argument array in bytes
1098 * a3 = (managed) thread pointer
1099 * a4 = JValue* result
1100 * a5 = shorty
1101 */
Goran Jakovljevic04568812015-04-23 15:27:23 +02001102ENTRY_NO_GP art_quick_invoke_static_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001103
1104 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra, onto the stack
1105 daddiu $sp, $sp, -48
1106 .cfi_adjust_cfa_offset 48
1107 sd $ra, 40($sp)
1108 .cfi_rel_offset 31, 40
1109 sd $s8, 32($sp)
1110 .cfi_rel_offset 30, 32
1111 sd $s1, 24($sp)
1112 .cfi_rel_offset 17, 24
1113 sd $s0, 16($sp)
1114 .cfi_rel_offset 16, 16
1115 sd $a5, 8($sp)
1116 .cfi_rel_offset 9, 8
1117 sd $a4, 0($sp)
1118 .cfi_rel_offset 8, 0
1119
1120 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1121 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1122 move $s8, $sp # save sp in s8 (fp)
1123
Mathieu Chartiere401d142015-04-22 13:56:20 -07001124 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001125 dsrl $t3, $t3, 4 # shift the frame size right 4
1126 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1127 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1128
1129 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1130 move $t1, $a1 # t1 = arg_array
1131 move $t2, $a2 # t2 = number of argument bytes remain
Mathieu Chartiere401d142015-04-22 13:56:20 -07001132 daddiu $v0, $sp, 8 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001133 LOOP_OVER_SHORTY_LOADING_REG a1, f13, call_sfn
1134 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_sfn
1135 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_sfn
1136 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_sfn
1137 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_sfn
1138 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_sfn
1139 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_sfn
1140
1141 # copy arguments onto stack (t2 should be multiples of 4)
1142 ble $t2, $zero, call_sfn # t2 = number of argument bytes remain
11431:
1144 lw $t3, 0($t1) # load from argument array
1145 daddiu $t1, $t1, 4
1146 sw $t3, 0($v0) # save to stack
1147 daddiu $t2, -4
1148 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1149 daddiu $v0, $v0, 4
1150
1151call_sfn:
1152 # call method (a0 has been untouched)
Mathieu Chartiere401d142015-04-22 13:56:20 -07001153 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1154 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001155 jalr $t9 # call the method
1156 nop
1157 move $sp, $s8 # restore sp
1158
1159 # pop a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra off of the stack
1160 ld $a4, 0($sp)
1161 .cfi_restore 8
1162 ld $a5, 8($sp)
1163 .cfi_restore 9
1164 ld $s0, 16($sp)
1165 .cfi_restore 16
1166 ld $s1, 24($sp)
1167 .cfi_restore 17
1168 ld $s8, 32($sp)
1169 .cfi_restore 30
1170 ld $ra, 40($sp)
1171 .cfi_restore 31
1172 daddiu $sp, $sp, 48
1173 .cfi_adjust_cfa_offset -48
1174
1175 # a4 = JValue* result
1176 # a5 = shorty string
1177 lbu $t1, 0($a5) # get result type from shorty
1178 li $t2, 68 # put char 'D' into t2
1179 beq $t1, $t2, 1f # branch if result type char == 'D'
1180 li $t3, 70 # put char 'F' into t3
1181 beq $t1, $t3, 1f # branch if result type char == 'F'
1182 sw $v0, 0($a4) # store the result
1183 dsrl $v1, $v0, 32
1184 jalr $zero, $ra
1185 sw $v1, 4($a4) # store the other half of the result
11861:
1187 mfc1 $v0, $f0
1188 mfhc1 $v1, $f0
1189 sw $v0, 0($a4) # store the result
1190 jalr $zero, $ra
1191 sw $v1, 4($a4) # store the other half of the result
1192END art_quick_invoke_static_stub
1193
Maja Gagic6ea651f2015-02-24 16:55:04 +01001194 /*
1195 * Entry from managed code that calls artHandleFillArrayDataFromCode and
1196 * delivers exception on failure.
1197 */
1198 .extern artHandleFillArrayDataFromCode
1199ENTRY art_quick_handle_fill_data
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001200 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
1201 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001202 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*)
1203 move $a3, rSELF # pass Thread::Current
1204 RETURN_IF_ZERO
1205END art_quick_handle_fill_data
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001206
Maja Gagic6ea651f2015-02-24 16:55:04 +01001207 /*
1208 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
1209 */
1210 .extern artLockObjectFromCode
1211ENTRY art_quick_lock_object
1212 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1213 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001214 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Maja Gagic6ea651f2015-02-24 16:55:04 +01001215 jal artLockObjectFromCode # (Object* obj, Thread*)
1216 move $a1, rSELF # pass Thread::Current
1217 RETURN_IF_ZERO
1218END art_quick_lock_object
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001219
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001220ENTRY art_quick_lock_object_no_inline
1221 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1222 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001223 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001224 jal artLockObjectFromCode # (Object* obj, Thread*)
1225 move $a1, rSELF # pass Thread::Current
1226 RETURN_IF_ZERO
1227END art_quick_lock_object_no_inline
1228
Maja Gagic6ea651f2015-02-24 16:55:04 +01001229 /*
1230 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1231 */
1232 .extern artUnlockObjectFromCode
1233ENTRY art_quick_unlock_object
1234 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1235 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001236 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001237 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1238 move $a1, rSELF # pass Thread::Current
1239 RETURN_IF_ZERO
1240END art_quick_unlock_object
1241
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001242ENTRY art_quick_unlock_object_no_inline
1243 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1244 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001245 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001246 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1247 move $a1, rSELF # pass Thread::Current
1248 RETURN_IF_ZERO
1249END art_quick_unlock_object_no_inline
1250
Maja Gagic6ea651f2015-02-24 16:55:04 +01001251 /*
1252 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1253 */
1254 .extern artThrowClassCastException
1255ENTRY art_quick_check_cast
1256 daddiu $sp, $sp, -32
1257 .cfi_adjust_cfa_offset 32
1258 sd $ra, 24($sp)
1259 .cfi_rel_offset 31, 24
1260 sd $t9, 16($sp)
1261 sd $a1, 8($sp)
1262 sd $a0, 0($sp)
1263 jal artIsAssignableFromCode
Goran Jakovljevic04568812015-04-23 15:27:23 +02001264 .cpreturn # Restore gp from t8 in branch delay slot.
1265 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001266 beq $v0, $zero, .Lthrow_class_cast_exception
1267 ld $ra, 24($sp)
1268 jalr $zero, $ra
1269 daddiu $sp, $sp, 32
1270 .cfi_adjust_cfa_offset -32
1271.Lthrow_class_cast_exception:
1272 ld $t9, 16($sp)
1273 ld $a1, 8($sp)
1274 ld $a0, 0($sp)
1275 daddiu $sp, $sp, 32
1276 .cfi_adjust_cfa_offset -32
Goran Jakovljevic04568812015-04-23 15:27:23 +02001277 SETUP_GP
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001278 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01001279 dla $t9, artThrowClassCastException
1280 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
1281 move $a2, rSELF # pass Thread::Current
1282END art_quick_check_cast
1283
Man Cao1aee9002015-07-14 22:31:42 -07001284
1285 /*
1286 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1287 * nReg is the register number for rReg.
1288 */
1289.macro POP_REG_NE rReg, nReg, offset, rExclude
1290 .ifnc \rReg, \rExclude
1291 ld \rReg, \offset($sp) # restore rReg
1292 .cfi_restore \nReg
1293 .endif
1294.endm
1295
1296 /*
1297 * Macro to insert read barrier, only used in art_quick_aput_obj.
1298 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1299 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1300 */
1301.macro READ_BARRIER rDest, rObj, offset
1302#ifdef USE_READ_BARRIER
1303 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 16B-aligned.
1304 daddiu $sp, $sp, -64
1305 .cfi_adjust_cfa_offset 64
1306 sd $ra, 56($sp)
1307 .cfi_rel_offset 31, 56
1308 sd $t9, 48($sp)
1309 .cfi_rel_offset 25, 48
1310 sd $t1, 40($sp)
1311 .cfi_rel_offset 13, 40
1312 sd $t0, 32($sp)
1313 .cfi_rel_offset 12, 32
1314 sd $a2, 16($sp) # padding slot at offset 24 (padding can be any slot in the 64B)
1315 .cfi_rel_offset 6, 16
1316 sd $a1, 8($sp)
1317 .cfi_rel_offset 5, 8
1318 sd $a0, 0($sp)
1319 .cfi_rel_offset 4, 0
1320
Man Cao63069212015-08-21 15:51:39 -07001321 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001322 .ifnc \rObj, $a1
1323 move $a1, \rObj # pass rObj
1324 .endif
1325 daddiu $a2, $zero, \offset # pass offset
1326 jal artReadBarrierSlow # artReadBarrierSlow(ref, rObj, offset)
1327 .cpreturn # Restore gp from t8 in branch delay slot.
1328 # t8 may be clobbered in artReadBarrierSlow.
1329 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1330 move \rDest, $v0 # save return value in rDest
1331 # (rDest cannot be v0 in art_quick_aput_obj)
1332
1333 ld $a0, 0($sp) # restore registers except rDest
1334 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1335 .cfi_restore 4
1336 ld $a1, 8($sp)
1337 .cfi_restore 5
1338 ld $a2, 16($sp)
1339 .cfi_restore 6
1340 POP_REG_NE $t0, 12, 32, \rDest
1341 POP_REG_NE $t1, 13, 40, \rDest
1342 ld $t9, 48($sp)
1343 .cfi_restore 25
1344 ld $ra, 56($sp) # restore $ra
1345 .cfi_restore 31
1346 daddiu $sp, $sp, 64
1347 .cfi_adjust_cfa_offset -64
1348 SETUP_GP # set up gp because we are not returning
1349#else
1350 lwu \rDest, \offset(\rObj)
1351 UNPOISON_HEAP_REF \rDest
1352#endif // USE_READ_BARRIER
1353.endm
1354
Maja Gagic6ea651f2015-02-24 16:55:04 +01001355 /*
1356 * Entry from managed code for array put operations of objects where the value being stored
1357 * needs to be checked for compatibility.
1358 * a0 = array, a1 = index, a2 = value
1359 */
1360ENTRY art_quick_aput_obj_with_null_and_bound_check
1361 bne $a0, $zero, .Lart_quick_aput_obj_with_bound_check_gp_set
1362 nop
1363 b .Lart_quick_throw_null_pointer_exception_gp_set
1364 nop
1365END art_quick_aput_obj_with_null_and_bound_check
1366
1367ENTRY art_quick_aput_obj_with_bound_check
1368 lwu $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
1369 sltu $t1, $a1, $t0
1370 bne $t1, $zero, .Lart_quick_aput_obj_gp_set
1371 nop
1372 move $a0, $a1
1373 b .Lart_quick_throw_array_bounds_gp_set
1374 move $a1, $t0
1375END art_quick_aput_obj_with_bound_check
1376
1377ENTRY art_quick_aput_obj
1378 beq $a2, $zero, .Ldo_aput_null
1379 nop
Man Cao1aee9002015-07-14 22:31:42 -07001380 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1381 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1382 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Maja Gagic6ea651f2015-02-24 16:55:04 +01001383 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
1384 nop
1385.Ldo_aput:
1386 dsll $a1, $a1, 2
1387 daddu $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001388 POISON_HEAP_REF $a2
Maja Gagic6ea651f2015-02-24 16:55:04 +01001389 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1390 ld $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1391 dsrl $t1, $a0, 7
1392 daddu $t1, $t1, $t0
1393 sb $t0, ($t1)
1394 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001395 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001396.Ldo_aput_null:
1397 dsll $a1, $a1, 2
1398 daddu $t0, $a0, $a1
1399 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1400 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001401 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001402.Lcheck_assignability:
1403 daddiu $sp, $sp, -64
1404 .cfi_adjust_cfa_offset 64
1405 sd $ra, 56($sp)
1406 .cfi_rel_offset 31, 56
1407 sd $t9, 24($sp)
1408 sd $a2, 16($sp)
1409 sd $a1, 8($sp)
1410 sd $a0, 0($sp)
1411 move $a1, $t1
1412 move $a0, $t0
1413 jal artIsAssignableFromCode # (Class*, Class*)
Goran Jakovljevic04568812015-04-23 15:27:23 +02001414 .cpreturn # Restore gp from t8 in branch delay slot.
1415 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001416 ld $ra, 56($sp)
1417 ld $t9, 24($sp)
1418 ld $a2, 16($sp)
1419 ld $a1, 8($sp)
1420 ld $a0, 0($sp)
1421 daddiu $sp, $sp, 64
1422 .cfi_adjust_cfa_offset -64
Goran Jakovljevic04568812015-04-23 15:27:23 +02001423 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001424 bne $v0, $zero, .Ldo_aput
1425 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001426 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01001427 move $a1, $a2
1428 dla $t9, artThrowArrayStoreException
1429 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
1430 move $a2, rSELF # pass Thread::Current
1431END art_quick_aput_obj
1432
1433 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001434 * Called by managed code to resolve a static field and load a boolean primitive value.
1435 */
1436 .extern artGetBooleanStaticFromCode
1437ENTRY art_quick_get_boolean_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001438 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1439 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001440 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1441 move $a2, rSELF # pass Thread::Current
1442 RETURN_IF_NO_EXCEPTION
1443END art_quick_get_boolean_static
1444
1445 /*
1446 * Called by managed code to resolve a static field and load a byte primitive value.
1447 */
1448 .extern artGetByteStaticFromCode
1449ENTRY art_quick_get_byte_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001450 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1451 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001452 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1453 move $a2, rSELF # pass Thread::Current
1454 RETURN_IF_NO_EXCEPTION
1455END art_quick_get_byte_static
1456
1457 /*
1458 * Called by managed code to resolve a static field and load a char primitive value.
1459 */
1460 .extern artGetCharStaticFromCode
1461ENTRY art_quick_get_char_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001462 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1463 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001464 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1465 move $a2, rSELF # pass Thread::Current
1466 RETURN_IF_NO_EXCEPTION
1467END art_quick_get_char_static
1468
1469 /*
1470 * Called by managed code to resolve a static field and load a short primitive value.
1471 */
1472 .extern artGetShortStaticFromCode
1473ENTRY art_quick_get_short_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001474 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1475 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001476 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1477 move $a2, rSELF # pass Thread::Current
1478 RETURN_IF_NO_EXCEPTION
1479END art_quick_get_short_static
1480
1481 /*
1482 * Called by managed code to resolve a static field and load a 32-bit primitive value.
1483 */
1484 .extern artGet32StaticFromCode
1485ENTRY art_quick_get32_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001486 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1487 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001488 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1489 move $a2, rSELF # pass Thread::Current
Goran Jakovljevicfd0740a2016-09-09 17:53:01 +02001490 sll $v0, $v0, 0 # sign-extend result
Maja Gagic6ea651f2015-02-24 16:55:04 +01001491 RETURN_IF_NO_EXCEPTION
1492END art_quick_get32_static
1493
1494 /*
1495 * Called by managed code to resolve a static field and load a 64-bit primitive value.
1496 */
1497 .extern artGet64StaticFromCode
1498ENTRY art_quick_get64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001499 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1500 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001501 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1502 move $a2, rSELF # pass Thread::Current
1503 RETURN_IF_NO_EXCEPTION
1504END art_quick_get64_static
1505
1506 /*
1507 * Called by managed code to resolve a static field and load an object reference.
1508 */
1509 .extern artGetObjStaticFromCode
1510ENTRY art_quick_get_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001511 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1512 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001513 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1514 move $a2, rSELF # pass Thread::Current
1515 RETURN_IF_NO_EXCEPTION
1516END art_quick_get_obj_static
1517
1518 /*
1519 * Called by managed code to resolve an instance field and load a boolean primitive value.
1520 */
1521 .extern artGetBooleanInstanceFromCode
1522ENTRY art_quick_get_boolean_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001523 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1524 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001525 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1526 move $a3, rSELF # pass Thread::Current
1527 RETURN_IF_NO_EXCEPTION
1528END art_quick_get_boolean_instance
1529
1530 /*
1531 * Called by managed code to resolve an instance field and load a byte primitive value.
1532 */
1533 .extern artGetByteInstanceFromCode
1534ENTRY art_quick_get_byte_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001535 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1536 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001537 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1538 move $a3, rSELF # pass Thread::Current
1539 RETURN_IF_NO_EXCEPTION
1540END art_quick_get_byte_instance
1541
1542 /*
1543 * Called by managed code to resolve an instance field and load a char primitive value.
1544 */
1545 .extern artGetCharInstanceFromCode
1546ENTRY art_quick_get_char_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001547 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1548 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001549 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1550 move $a3, rSELF # pass Thread::Current
1551 RETURN_IF_NO_EXCEPTION
1552END art_quick_get_char_instance
1553
1554 /*
1555 * Called by managed code to resolve an instance field and load a short primitive value.
1556 */
1557 .extern artGetShortInstanceFromCode
1558ENTRY art_quick_get_short_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001559 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1560 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001561 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1562 move $a3, rSELF # pass Thread::Current
1563 RETURN_IF_NO_EXCEPTION
1564END art_quick_get_short_instance
1565
1566 /*
1567 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1568 */
1569 .extern artGet32InstanceFromCode
1570ENTRY art_quick_get32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001571 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1572 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001573 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1574 move $a3, rSELF # pass Thread::Current
Goran Jakovljevicfd0740a2016-09-09 17:53:01 +02001575 sll $v0, $v0, 0 # sign-extend result
Maja Gagic6ea651f2015-02-24 16:55:04 +01001576 RETURN_IF_NO_EXCEPTION
1577END art_quick_get32_instance
1578
1579 /*
1580 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1581 */
1582 .extern artGet64InstanceFromCode
1583ENTRY art_quick_get64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001584 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1585 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001586 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1587 move $a3, rSELF # pass Thread::Current
1588 RETURN_IF_NO_EXCEPTION
1589END art_quick_get64_instance
1590
1591 /*
1592 * Called by managed code to resolve an instance field and load an object reference.
1593 */
1594 .extern artGetObjInstanceFromCode
1595ENTRY art_quick_get_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001596 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1597 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001598 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1599 move $a3, rSELF # pass Thread::Current
1600 RETURN_IF_NO_EXCEPTION
1601END art_quick_get_obj_instance
1602
1603 /*
1604 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1605 */
1606 .extern artSet8StaticFromCode
1607ENTRY art_quick_set8_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001608 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1609 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001610 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
1611 move $a3, rSELF # pass Thread::Current
1612 RETURN_IF_ZERO
1613END art_quick_set8_static
1614
1615 /*
1616 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1617 */
1618 .extern artSet16StaticFromCode
1619ENTRY art_quick_set16_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001620 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1621 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001622 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*)
1623 move $a3, rSELF # pass Thread::Current
1624 RETURN_IF_ZERO
1625END art_quick_set16_static
1626
1627 /*
1628 * Called by managed code to resolve a static field and store a 32-bit primitive value.
1629 */
1630 .extern artSet32StaticFromCode
1631ENTRY art_quick_set32_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001632 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1633 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001634 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
1635 move $a3, rSELF # pass Thread::Current
1636 RETURN_IF_ZERO
1637END art_quick_set32_static
1638
1639 /*
1640 * Called by managed code to resolve a static field and store a 64-bit primitive value.
1641 */
1642 .extern artSet64StaticFromCode
1643ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001644 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001645 # a2 contains the new val
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001646 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001647 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
1648 move $a3, rSELF # pass Thread::Current
1649 RETURN_IF_ZERO
1650END art_quick_set64_static
1651
1652 /*
1653 * Called by managed code to resolve a static field and store an object reference.
1654 */
1655 .extern artSetObjStaticFromCode
1656ENTRY art_quick_set_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001657 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1658 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001659 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
1660 move $a3, rSELF # pass Thread::Current
1661 RETURN_IF_ZERO
1662END art_quick_set_obj_static
1663
1664 /*
1665 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1666 */
1667 .extern artSet8InstanceFromCode
1668ENTRY art_quick_set8_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001669 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1670 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001671 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1672 move $a4, rSELF # pass Thread::Current
1673 RETURN_IF_ZERO
1674END art_quick_set8_instance
1675
1676 /*
1677 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1678 */
1679 .extern artSet16InstanceFromCode
1680ENTRY art_quick_set16_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001681 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1682 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001683 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1684 move $a4, rSELF # pass Thread::Current
1685 RETURN_IF_ZERO
1686END art_quick_set16_instance
1687
1688 /*
1689 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1690 */
1691 .extern artSet32InstanceFromCode
1692ENTRY art_quick_set32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001693 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1694 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001695 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1696 move $a4, rSELF # pass Thread::Current
1697 RETURN_IF_ZERO
1698END art_quick_set32_instance
1699
1700 /*
1701 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1702 */
1703 .extern artSet64InstanceFromCode
1704ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001705 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1706 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001707 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1708 move $a4, rSELF # pass Thread::Current
1709 RETURN_IF_ZERO
1710END art_quick_set64_instance
1711
1712 /*
1713 * Called by managed code to resolve an instance field and store an object reference.
1714 */
1715 .extern artSetObjInstanceFromCode
1716ENTRY art_quick_set_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001717 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1718 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001719 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1720 move $a4, rSELF # pass Thread::Current
1721 RETURN_IF_ZERO
1722END art_quick_set_obj_instance
1723
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001724// Macro to facilitate adding new allocation entrypoints.
1725.macro ONE_ARG_DOWNCALL name, entrypoint, return
1726 .extern \entrypoint
1727ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001728 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001729 jal \entrypoint
1730 move $a1, rSELF # pass Thread::Current
1731 \return
1732END \name
1733.endm
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001734
1735// Macro to facilitate adding new allocation entrypoints.
1736.macro TWO_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001737 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001738ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001739 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001740 jal \entrypoint
1741 move $a2, rSELF # pass Thread::Current
1742 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001743END \name
1744.endm
1745
1746.macro THREE_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001747 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001748ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001749 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001750 jal \entrypoint
1751 move $a3, rSELF # pass Thread::Current
1752 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001753END \name
1754.endm
1755
Vladimir Markoe85e1232015-04-28 14:14:58 +01001756.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1757 .extern \entrypoint
1758ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001759 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Markoe85e1232015-04-28 14:14:58 +01001760 jal \entrypoint
1761 move $a4, rSELF # pass Thread::Current
1762 \return
1763END \name
1764.endm
1765
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001766// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001767GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001768
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001769// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1770ENTRY art_quick_alloc_object_rosalloc
1771
1772 # Fast path rosalloc allocation
1773 # a0: type_idx
1774 # a1: ArtMethod*
1775 # s1: Thread::Current
1776 # -----------------------------
1777 # t0: class
1778 # t1: object size
1779 # t2: rosalloc run
1780 # t3: thread stack top offset
1781 # a4: thread stack bottom offset
1782 # v0: free list head
1783 #
1784 # a5, a6 : temps
1785
1786 ld $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_64($a1) # Load dex cache resolved types array.
1787
1788 dsll $a5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1789 daddu $a5, $t0, $a5 # Compute the index.
1790 lwu $t0, 0($a5) # Load class (t0).
1791 beqzc $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1792
1793 li $a6, MIRROR_CLASS_STATUS_INITIALIZED
1794 lwu $a5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1795 bnec $a5, $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1796
1797 # Add a fake dependence from the following access flag and size loads to the status load. This
1798 # is to prevent those loads from being reordered above the status load and reading wrong values.
1799 xor $a5, $a5, $a5
1800 daddu $t0, $t0, $a5
1801
1802 lwu $a5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1803 li $a6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1804 and $a6, $a5, $a6
1805 bnezc $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1806
1807 ld $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation stack
1808 ld $a4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # has any room left.
1809 bgeuc $t3, $a4, .Lart_quick_alloc_object_rosalloc_slow_path
1810
1811 lwu $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1812 li $a5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1813 # allocation.
1814 bltuc $a5, $t1, .Lart_quick_alloc_object_rosalloc_slow_path
1815
1816 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1817 # quantum size and divide by the quantum size and subtract by 1.
1818 daddiu $t1, $t1, -1 # Decrease obj size and shift right by
1819 dsrl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # quantum.
1820
1821 dsll $t2, $t1, POINTER_SIZE_SHIFT
1822 daddu $t2, $t2, $s1
1823 ld $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1824
1825 # Load the free list head (v0).
1826 # NOTE: this will be the return val.
1827 ld $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1828 beqzc $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1829
1830 # Load the next pointer of the head and update the list head with the next pointer.
1831 ld $a5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1832 sd $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1833
1834 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1835 # asserted to match.
1836
1837#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1838#error "Class pointer needs to overwrite next pointer."
1839#endif
1840
1841 POISON_HEAP_REF $t0
1842 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1843
1844 # Push the new object onto the thread local allocation stack and increment the thread local
1845 # allocation stack top.
1846 sd $v0, 0($t3)
1847 daddiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1848 sd $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1849
1850 # Decrement the size of the free list.
1851 lw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1852 addiu $a5, $a5, -1
1853 sw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1854
1855 sync # Fence.
1856
1857 jalr $zero, $ra
1858 .cpreturn # Restore gp from t8 in branch delay slot.
1859
1860.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001861 SETUP_SAVE_REFS_ONLY_FRAME
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001862 jal artAllocObjectFromCodeRosAlloc
1863 move $a2 ,$s1 # Pass self as argument.
1864 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1865
1866END art_quick_alloc_object_rosalloc
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001867
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001868GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1869GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1870
Maja Gagic6ea651f2015-02-24 16:55:04 +01001871 /*
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001872 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1873 * exception on error. On success the String is returned. A0 holds the string index. The fast
1874 * path check for hit in strings cache has already been performed.
1875 */
1876ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1877
1878 /*
1879 * Entry from managed code when uninitialized static storage, this stub will run the class
1880 * initializer and deliver the exception on error. On success the static storage base is
1881 * returned.
1882 */
1883ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1884
1885 /*
1886 * Entry from managed code when dex cache misses for a type_idx.
1887 */
1888ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1889
1890 /*
1891 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1892 * miss.
1893 */
1894ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1895
1896 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001897 * Called by managed code when the value in rSUSPEND has been decremented to 0.
1898 */
1899 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001900ENTRY_NO_GP art_quick_test_suspend
1901 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1902 bne rSUSPEND, $zero, 1f
Maja Gagic6ea651f2015-02-24 16:55:04 +01001903 daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1904 jalr $zero, $ra
Vladimir Marko952dbb12016-07-28 12:01:51 +01001905 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +010019061:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001907 SETUP_SAVE_EVERYTHING_FRAME # save everything for stack crawl
Maja Gagic6ea651f2015-02-24 16:55:04 +01001908 jal artTestSuspendFromCode # (Thread*)
1909 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001910 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001911 jalr $zero, $ra
1912 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +01001913END art_quick_test_suspend
Douglas Leung6461d192015-01-30 18:13:58 -08001914
1915 /*
1916 * Called by managed code that is attempting to call a method on a proxy class. On entry
1917 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1918 */
1919 .extern artQuickProxyInvokeHandler
1920ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001921 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung6461d192015-01-30 18:13:58 -08001922 move $a2, rSELF # pass Thread::Current
1923 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
1924 move $a3, $sp # pass $sp
1925 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1926 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001927 RESTORE_SAVE_REFS_ONLY_FRAME
Douglas Leung6461d192015-01-30 18:13:58 -08001928 bne $t0, $zero, 1f
1929 dmtc1 $v0, $f0 # place return value to FP return value
1930 jalr $zero, $ra
1931 dmtc1 $v1, $f1 # place return value to FP return value
19321:
1933 DELIVER_PENDING_EXCEPTION
1934END art_quick_proxy_invoke_handler
1935
Maja Gagic6ea651f2015-02-24 16:55:04 +01001936 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001937 * Called to resolve an imt conflict.
1938 * a0 is the conflict ArtMethod.
1939 * t0 is a hidden argument that holds the target interface method's dex method index.
1940 *
1941 * Mote that this stub writes to a0, t0 and t1.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001942 */
1943ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001944 ld $t1, 0($sp) # Load referrer.
1945 ld $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_64($t1) # Load dex cache methods array.
1946 dsll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1947 daddu $t0, $t1, $t0 # Add offset to base.
1948 ld $t0, 0($t0) # Load interface method.
1949 ld $a0, ART_METHOD_JNI_OFFSET_64($a0) # Load ImtConflictTable.
1950
1951.Limt_table_iterate:
1952 ld $t1, 0($a0) # Load next entry in ImtConflictTable.
1953 # Branch if found.
1954 beq $t1, $t0, .Limt_table_found
1955 nop
1956 # If the entry is null, the interface method is not in the ImtConflictTable.
1957 beqzc $t1, .Lconflict_trampoline
1958 # Iterate over the entries of the ImtConflictTable.
1959 daddiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1960 bc .Limt_table_iterate
1961
1962.Limt_table_found:
1963 # We successfully hit an entry in the table. Load the target method and jump to it.
1964 ld $a0, __SIZEOF_POINTER__($a0)
1965 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)
1966 jr $t9
1967 .cpreturn # Restore gp from t8 in branch delay slot.
1968
1969.Lconflict_trampoline:
1970 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001971 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Maja Gagic6ea651f2015-02-24 16:55:04 +01001972END art_quick_imt_conflict_trampoline
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001973
1974 .extern artQuickResolutionTrampoline
1975ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001976 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001977 move $a2, rSELF # pass Thread::Current
1978 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
1979 move $a3, $sp # pass $sp
1980 beq $v0, $zero, 1f
Mathieu Chartiere401d142015-04-22 13:56:20 -07001981 ld $a0, 0($sp) # load resolved method in $a0
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001982 # artQuickResolutionTrampoline puts resolved method in *SP
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001983 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001984 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
1985 jalr $zero, $t9 # tail call to method
1986 nop
19871:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001988 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001989 DELIVER_PENDING_EXCEPTION
1990END art_quick_resolution_trampoline
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001991
1992 .extern artQuickGenericJniTrampoline
1993 .extern artQuickGenericJniEndTrampoline
1994ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001995 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001996 move $s8, $sp # save $sp
1997
1998 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1999 move $a0, rSELF # pass Thread::Current
2000 move $a1, $sp # pass $sp
2001 jal artQuickGenericJniTrampoline # (Thread*, SP)
2002 daddiu $sp, $sp, -5120 # reserve space on the stack
2003
2004 # The C call will have registered the complete save-frame on success.
2005 # The result of the call is:
2006 # v0: ptr to native code, 0 on error.
2007 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
2008 beq $v0, $zero, 1f # check entry error
2009 move $t9, $v0 # save the code ptr
2010 move $sp, $v1 # release part of the alloca
2011
2012 # Load parameters from stack into registers
2013 ld $a0, 0($sp)
2014 ld $a1, 8($sp)
2015 ld $a2, 16($sp)
2016 ld $a3, 24($sp)
2017 ld $a4, 32($sp)
2018 ld $a5, 40($sp)
2019 ld $a6, 48($sp)
2020 ld $a7, 56($sp)
2021 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
2022 l.d $f12, 0($sp)
2023 l.d $f13, 8($sp)
2024 l.d $f14, 16($sp)
2025 l.d $f15, 24($sp)
2026 l.d $f16, 32($sp)
2027 l.d $f17, 40($sp)
2028 l.d $f18, 48($sp)
2029 l.d $f19, 56($sp)
2030 jalr $t9 # native call
2031 daddiu $sp, $sp, 64
2032
2033 # result sign extension is handled in C code
2034 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
2035 move $a0, rSELF # pass Thread::Current
2036 move $a1, $v0
2037 jal artQuickGenericJniEndTrampoline
2038 dmfc1 $a2, $f0
2039
2040 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002041 bne $t0, $zero, 1f # check for pending exceptions
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002042 move $sp, $s8 # tear down the alloca
2043
2044 # tear dpown the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002045 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002046
2047 jalr $zero, $ra
2048 dmtc1 $v0, $f0 # place return value to FP return value
2049
20501:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002051 ld $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2052 # This will create a new save-all frame, required by the runtime.
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002053 DELIVER_PENDING_EXCEPTION
2054END art_quick_generic_jni_trampoline
2055
2056 .extern artQuickToInterpreterBridge
2057ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002058 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002059 move $a1, rSELF # pass Thread::Current
2060 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
2061 move $a2, $sp # pass $sp
2062 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
2063 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002064 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002065 bne $t0, $zero, 1f
2066 dmtc1 $v0, $f0 # place return value to FP return value
2067 jalr $zero, $ra
2068 dmtc1 $v1, $f1 # place return value to FP return value
20691:
2070 DELIVER_PENDING_EXCEPTION
2071END art_quick_to_interpreter_bridge
2072
2073 /*
2074 * Routine that intercepts method calls and returns.
2075 */
2076 .extern artInstrumentationMethodEntryFromCode
2077 .extern artInstrumentationMethodExitFromCode
2078ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002079 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002080 daddiu $sp, $sp, -16 # space for saving arg0
2081 .cfi_adjust_cfa_offset 16
2082 sd $a0, 0($sp) # save arg0
2083 move $a3, $ra # pass $ra
2084 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, RA)
2085 move $a2, rSELF # pass Thread::Current
2086 move $t9, $v0 # $t9 holds reference to code
2087 ld $a0, 0($sp) # restore arg0
2088 daddiu $sp, $sp, 16 # remove args
2089 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002090 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002091 jalr $t9 # call method
2092 nop
2093END art_quick_instrumentation_entry
2094 /* intentional fallthrough */
2095 .global art_quick_instrumentation_exit
2096art_quick_instrumentation_exit:
2097 .cfi_startproc
Goran Jakovljevic04568812015-04-23 15:27:23 +02002098 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002099 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002100 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002101 move $t0, $sp # remember bottom of caller's frame
2102 daddiu $sp, $sp, -16 # save return values and set up args
2103 .cfi_adjust_cfa_offset 16
2104 sd $v0, 0($sp)
2105 .cfi_rel_offset 2, 0
2106 s.d $f0, 8($sp)
2107 mov.d $f15, $f0 # pass fpr result
2108 move $a2, $v0 # pass gpr result
2109 move $a1, $t0 # pass $sp
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002110 move $a0, rSELF # pass Thread::Current
Goran Jakovljevic04568812015-04-23 15:27:23 +02002111 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
2112 .cpreturn # Restore gp from t8 in branch delay slot. gp is not used anymore,
2113 # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
2114
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002115 move $t9, $v0 # set aside returned link register
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002116 move $ra, $v1 # set link register for deoptimization
2117 ld $v0, 0($sp) # restore return values
2118 l.d $f0, 8($sp)
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002119 jalr $zero, $t9 # return
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002120 # restore stack, 16 bytes of saved values + ref_only callee save frame
2121 daddiu $sp, $sp, 16+FRAME_SIZE_SAVE_REFS_ONLY
2122 .cfi_adjust_cfa_offset -(16+FRAME_SIZE_SAVE_REFS_ONLY)
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002123END art_quick_instrumentation_exit
2124
Maja Gagic6ea651f2015-02-24 16:55:04 +01002125 /*
2126 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2127 * will long jump to the upcall with a special exception of -1.
2128 */
2129 .extern artDeoptimize
2130 .extern artEnterInterpreterFromDeoptimize
2131ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002132 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01002133 jal artDeoptimize # artDeoptimize(Thread*, SP)
2134 # Returns caller method's frame size.
2135 move $a0, rSELF # pass Thread::current
2136END art_quick_deoptimize
2137
Sebastien Hertz07474662015-08-25 15:12:33 +00002138 /*
2139 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2140 * will long jump to the upcall with a special exception of -1.
2141 */
2142 .extern artDeoptimizeFromCompiledCode
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002143ENTRY_NO_GP art_quick_deoptimize_from_compiled_code
2144 SETUP_SAVE_EVERYTHING_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002145 jal artDeoptimizeFromCompiledCode # artDeoptimizeFromCompiledCode(Thread*, SP)
2146 # Returns caller method's frame size.
2147 move $a0, rSELF # pass Thread::current
2148END art_quick_deoptimize_from_compiled_code
2149
Chris Larsen9701c2e2015-09-04 17:22:47 -07002150 .set push
2151 .set noat
2152/* java.lang.String.compareTo(String anotherString) */
2153ENTRY_NO_GP art_quick_string_compareto
2154/* $a0 holds address of "this" */
2155/* $a1 holds address of "anotherString" */
2156 beq $a0,$a1,9f # this and anotherString are the same object
2157 move $v0,$zero
2158
2159 lw $a2,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2160 lw $a3,MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002161 MINu $t2, $a2, $a3
2162# $t2 now holds min(this.length(),anotherString.length())
Chris Larsen9701c2e2015-09-04 17:22:47 -07002163
2164 beqz $t2,9f # while min(this.length(),anotherString.length())-i != 0
2165 subu $v0,$a2,$a3 # if $t2==0 return
2166 # (this.length() - anotherString.length())
21671:
2168 lhu $t0,MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2169 lhu $t1,MIRROR_STRING_VALUE_OFFSET($a1)
2170 bne $t0,$t1,9f # if this.charAt(i) != anotherString.charAt(i)
2171 subu $v0,$t0,$t1 # return (this.charAt(i) - anotherString.charAt(i))
2172 daddiu $a0,$a0,2 # point at this.charAt(i++)
2173 subu $t2,$t2,1 # new value of
2174 # min(this.length(),anotherString.length())-i
2175 bnez $t2,1b
2176 daddiu $a1,$a1,2 # point at anotherString.charAt(i++)
2177 subu $v0,$a2,$a3
2178
21799:
2180 j $ra
2181 nop
2182END art_quick_string_compareto
2183
2184/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2185ENTRY_NO_GP art_quick_indexof
2186/* $a0 holds address of "this" */
Chris Larsencf283da2016-01-19 16:45:35 -08002187/* $a1 holds "ch" */
2188/* $a2 holds "fromIndex" */
Chris Larsen9701c2e2015-09-04 17:22:47 -07002189 lw $t0,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002190 slt $at, $a2, $zero # if fromIndex < 0
2191 seleqz $a2, $a2, $at # fromIndex = 0;
2192 subu $t0,$t0,$a2 # this.length() - fromIndex
2193 blez $t0,6f # if this.length()-fromIndex <= 0
Chris Larsen9701c2e2015-09-04 17:22:47 -07002194 li $v0,-1 # return -1;
2195
2196 sll $v0,$a2,1 # $a0 += $a2 * 2
2197 daddu $a0,$a0,$v0 # " " " " "
Chris Larsencf283da2016-01-19 16:45:35 -08002198 move $v0,$a2 # Set i to fromIndex.
Chris Larsen9701c2e2015-09-04 17:22:47 -07002199
22001:
2201 lhu $t3,MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2202 beq $t3,$a1,6f # return i;
2203 daddu $a0,$a0,2 # i++
2204 subu $t0,$t0,1 # this.length() - i
2205 bnez $t0,1b # while this.length() - i > 0
2206 addu $v0,$v0,1 # i++
2207
2208 li $v0,-1 # if this.length() - i <= 0
2209 # return -1;
2210
22116:
2212 j $ra
2213 nop
2214END art_quick_indexof
2215
2216 .set pop