blob: 9774eb9f83b013c7c4d36fa272fbae4c22f841ce [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
1490 RETURN_IF_NO_EXCEPTION
1491END art_quick_get32_static
1492
1493 /*
1494 * Called by managed code to resolve a static field and load a 64-bit primitive value.
1495 */
1496 .extern artGet64StaticFromCode
1497ENTRY art_quick_get64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001498 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1499 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001500 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1501 move $a2, rSELF # pass Thread::Current
1502 RETURN_IF_NO_EXCEPTION
1503END art_quick_get64_static
1504
1505 /*
1506 * Called by managed code to resolve a static field and load an object reference.
1507 */
1508 .extern artGetObjStaticFromCode
1509ENTRY art_quick_get_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001510 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1511 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001512 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1513 move $a2, rSELF # pass Thread::Current
1514 RETURN_IF_NO_EXCEPTION
1515END art_quick_get_obj_static
1516
1517 /*
1518 * Called by managed code to resolve an instance field and load a boolean primitive value.
1519 */
1520 .extern artGetBooleanInstanceFromCode
1521ENTRY art_quick_get_boolean_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001522 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1523 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001524 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1525 move $a3, rSELF # pass Thread::Current
1526 RETURN_IF_NO_EXCEPTION
1527END art_quick_get_boolean_instance
1528
1529 /*
1530 * Called by managed code to resolve an instance field and load a byte primitive value.
1531 */
1532 .extern artGetByteInstanceFromCode
1533ENTRY art_quick_get_byte_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001534 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1535 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001536 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1537 move $a3, rSELF # pass Thread::Current
1538 RETURN_IF_NO_EXCEPTION
1539END art_quick_get_byte_instance
1540
1541 /*
1542 * Called by managed code to resolve an instance field and load a char primitive value.
1543 */
1544 .extern artGetCharInstanceFromCode
1545ENTRY art_quick_get_char_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001546 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1547 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001548 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1549 move $a3, rSELF # pass Thread::Current
1550 RETURN_IF_NO_EXCEPTION
1551END art_quick_get_char_instance
1552
1553 /*
1554 * Called by managed code to resolve an instance field and load a short primitive value.
1555 */
1556 .extern artGetShortInstanceFromCode
1557ENTRY art_quick_get_short_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001558 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1559 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001560 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1561 move $a3, rSELF # pass Thread::Current
1562 RETURN_IF_NO_EXCEPTION
1563END art_quick_get_short_instance
1564
1565 /*
1566 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1567 */
1568 .extern artGet32InstanceFromCode
1569ENTRY art_quick_get32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001570 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1571 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001572 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1573 move $a3, rSELF # pass Thread::Current
1574 RETURN_IF_NO_EXCEPTION
1575END art_quick_get32_instance
1576
1577 /*
1578 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1579 */
1580 .extern artGet64InstanceFromCode
1581ENTRY art_quick_get64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001582 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1583 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001584 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1585 move $a3, rSELF # pass Thread::Current
1586 RETURN_IF_NO_EXCEPTION
1587END art_quick_get64_instance
1588
1589 /*
1590 * Called by managed code to resolve an instance field and load an object reference.
1591 */
1592 .extern artGetObjInstanceFromCode
1593ENTRY art_quick_get_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001594 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1595 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001596 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1597 move $a3, rSELF # pass Thread::Current
1598 RETURN_IF_NO_EXCEPTION
1599END art_quick_get_obj_instance
1600
1601 /*
1602 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1603 */
1604 .extern artSet8StaticFromCode
1605ENTRY art_quick_set8_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001606 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1607 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001608 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
1609 move $a3, rSELF # pass Thread::Current
1610 RETURN_IF_ZERO
1611END art_quick_set8_static
1612
1613 /*
1614 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1615 */
1616 .extern artSet16StaticFromCode
1617ENTRY art_quick_set16_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001618 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1619 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001620 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*)
1621 move $a3, rSELF # pass Thread::Current
1622 RETURN_IF_ZERO
1623END art_quick_set16_static
1624
1625 /*
1626 * Called by managed code to resolve a static field and store a 32-bit primitive value.
1627 */
1628 .extern artSet32StaticFromCode
1629ENTRY art_quick_set32_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001630 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1631 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001632 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
1633 move $a3, rSELF # pass Thread::Current
1634 RETURN_IF_ZERO
1635END art_quick_set32_static
1636
1637 /*
1638 * Called by managed code to resolve a static field and store a 64-bit primitive value.
1639 */
1640 .extern artSet64StaticFromCode
1641ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001642 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001643 # a2 contains the new val
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001644 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001645 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
1646 move $a3, rSELF # pass Thread::Current
1647 RETURN_IF_ZERO
1648END art_quick_set64_static
1649
1650 /*
1651 * Called by managed code to resolve a static field and store an object reference.
1652 */
1653 .extern artSetObjStaticFromCode
1654ENTRY art_quick_set_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001655 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1656 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001657 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
1658 move $a3, rSELF # pass Thread::Current
1659 RETURN_IF_ZERO
1660END art_quick_set_obj_static
1661
1662 /*
1663 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1664 */
1665 .extern artSet8InstanceFromCode
1666ENTRY art_quick_set8_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001667 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1668 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001669 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1670 move $a4, rSELF # pass Thread::Current
1671 RETURN_IF_ZERO
1672END art_quick_set8_instance
1673
1674 /*
1675 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1676 */
1677 .extern artSet16InstanceFromCode
1678ENTRY art_quick_set16_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001679 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1680 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001681 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1682 move $a4, rSELF # pass Thread::Current
1683 RETURN_IF_ZERO
1684END art_quick_set16_instance
1685
1686 /*
1687 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1688 */
1689 .extern artSet32InstanceFromCode
1690ENTRY art_quick_set32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001691 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1692 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001693 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1694 move $a4, rSELF # pass Thread::Current
1695 RETURN_IF_ZERO
1696END art_quick_set32_instance
1697
1698 /*
1699 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1700 */
1701 .extern artSet64InstanceFromCode
1702ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001703 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1704 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001705 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1706 move $a4, rSELF # pass Thread::Current
1707 RETURN_IF_ZERO
1708END art_quick_set64_instance
1709
1710 /*
1711 * Called by managed code to resolve an instance field and store an object reference.
1712 */
1713 .extern artSetObjInstanceFromCode
1714ENTRY art_quick_set_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001715 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1716 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001717 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1718 move $a4, rSELF # pass Thread::Current
1719 RETURN_IF_ZERO
1720END art_quick_set_obj_instance
1721
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001722// Macro to facilitate adding new allocation entrypoints.
1723.macro ONE_ARG_DOWNCALL name, entrypoint, return
1724 .extern \entrypoint
1725ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001726 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001727 jal \entrypoint
1728 move $a1, rSELF # pass Thread::Current
1729 \return
1730END \name
1731.endm
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001732
1733// Macro to facilitate adding new allocation entrypoints.
1734.macro TWO_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001735 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001736ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001737 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001738 jal \entrypoint
1739 move $a2, rSELF # pass Thread::Current
1740 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001741END \name
1742.endm
1743
1744.macro THREE_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001745 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001746ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001747 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001748 jal \entrypoint
1749 move $a3, rSELF # pass Thread::Current
1750 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001751END \name
1752.endm
1753
Vladimir Markoe85e1232015-04-28 14:14:58 +01001754.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1755 .extern \entrypoint
1756ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001757 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Markoe85e1232015-04-28 14:14:58 +01001758 jal \entrypoint
1759 move $a4, rSELF # pass Thread::Current
1760 \return
1761END \name
1762.endm
1763
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001764// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001765GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001766
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001767// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1768ENTRY art_quick_alloc_object_rosalloc
1769
1770 # Fast path rosalloc allocation
1771 # a0: type_idx
1772 # a1: ArtMethod*
1773 # s1: Thread::Current
1774 # -----------------------------
1775 # t0: class
1776 # t1: object size
1777 # t2: rosalloc run
1778 # t3: thread stack top offset
1779 # a4: thread stack bottom offset
1780 # v0: free list head
1781 #
1782 # a5, a6 : temps
1783
1784 ld $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_64($a1) # Load dex cache resolved types array.
1785
1786 dsll $a5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1787 daddu $a5, $t0, $a5 # Compute the index.
1788 lwu $t0, 0($a5) # Load class (t0).
1789 beqzc $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1790
1791 li $a6, MIRROR_CLASS_STATUS_INITIALIZED
1792 lwu $a5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1793 bnec $a5, $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1794
1795 # Add a fake dependence from the following access flag and size loads to the status load. This
1796 # is to prevent those loads from being reordered above the status load and reading wrong values.
1797 xor $a5, $a5, $a5
1798 daddu $t0, $t0, $a5
1799
1800 lwu $a5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1801 li $a6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1802 and $a6, $a5, $a6
1803 bnezc $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1804
1805 ld $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation stack
1806 ld $a4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # has any room left.
1807 bgeuc $t3, $a4, .Lart_quick_alloc_object_rosalloc_slow_path
1808
1809 lwu $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1810 li $a5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1811 # allocation.
1812 bltuc $a5, $t1, .Lart_quick_alloc_object_rosalloc_slow_path
1813
1814 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1815 # quantum size and divide by the quantum size and subtract by 1.
1816 daddiu $t1, $t1, -1 # Decrease obj size and shift right by
1817 dsrl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # quantum.
1818
1819 dsll $t2, $t1, POINTER_SIZE_SHIFT
1820 daddu $t2, $t2, $s1
1821 ld $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1822
1823 # Load the free list head (v0).
1824 # NOTE: this will be the return val.
1825 ld $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1826 beqzc $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1827
1828 # Load the next pointer of the head and update the list head with the next pointer.
1829 ld $a5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1830 sd $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1831
1832 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1833 # asserted to match.
1834
1835#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1836#error "Class pointer needs to overwrite next pointer."
1837#endif
1838
1839 POISON_HEAP_REF $t0
1840 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1841
1842 # Push the new object onto the thread local allocation stack and increment the thread local
1843 # allocation stack top.
1844 sd $v0, 0($t3)
1845 daddiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1846 sd $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1847
1848 # Decrement the size of the free list.
1849 lw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1850 addiu $a5, $a5, -1
1851 sw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1852
1853 sync # Fence.
1854
1855 jalr $zero, $ra
1856 .cpreturn # Restore gp from t8 in branch delay slot.
1857
1858.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001859 SETUP_SAVE_REFS_ONLY_FRAME
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001860 jal artAllocObjectFromCodeRosAlloc
1861 move $a2 ,$s1 # Pass self as argument.
1862 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1863
1864END art_quick_alloc_object_rosalloc
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001865
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001866GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1867GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1868
Maja Gagic6ea651f2015-02-24 16:55:04 +01001869 /*
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001870 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1871 * exception on error. On success the String is returned. A0 holds the string index. The fast
1872 * path check for hit in strings cache has already been performed.
1873 */
1874ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1875
1876 /*
1877 * Entry from managed code when uninitialized static storage, this stub will run the class
1878 * initializer and deliver the exception on error. On success the static storage base is
1879 * returned.
1880 */
1881ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1882
1883 /*
1884 * Entry from managed code when dex cache misses for a type_idx.
1885 */
1886ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1887
1888 /*
1889 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1890 * miss.
1891 */
1892ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1893
1894 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001895 * Called by managed code when the value in rSUSPEND has been decremented to 0.
1896 */
1897 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001898ENTRY_NO_GP art_quick_test_suspend
1899 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1900 bne rSUSPEND, $zero, 1f
Maja Gagic6ea651f2015-02-24 16:55:04 +01001901 daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1902 jalr $zero, $ra
Vladimir Marko952dbb12016-07-28 12:01:51 +01001903 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +010019041:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001905 SETUP_SAVE_EVERYTHING_FRAME # save everything for stack crawl
Maja Gagic6ea651f2015-02-24 16:55:04 +01001906 jal artTestSuspendFromCode # (Thread*)
1907 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001908 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001909 jalr $zero, $ra
1910 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +01001911END art_quick_test_suspend
Douglas Leung6461d192015-01-30 18:13:58 -08001912
1913 /*
1914 * Called by managed code that is attempting to call a method on a proxy class. On entry
1915 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1916 */
1917 .extern artQuickProxyInvokeHandler
1918ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001919 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung6461d192015-01-30 18:13:58 -08001920 move $a2, rSELF # pass Thread::Current
1921 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
1922 move $a3, $sp # pass $sp
1923 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1924 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001925 RESTORE_SAVE_REFS_ONLY_FRAME
Douglas Leung6461d192015-01-30 18:13:58 -08001926 bne $t0, $zero, 1f
1927 dmtc1 $v0, $f0 # place return value to FP return value
1928 jalr $zero, $ra
1929 dmtc1 $v1, $f1 # place return value to FP return value
19301:
1931 DELIVER_PENDING_EXCEPTION
1932END art_quick_proxy_invoke_handler
1933
Maja Gagic6ea651f2015-02-24 16:55:04 +01001934 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001935 * Called to resolve an imt conflict.
1936 * a0 is the conflict ArtMethod.
1937 * t0 is a hidden argument that holds the target interface method's dex method index.
1938 *
1939 * Mote that this stub writes to a0, t0 and t1.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001940 */
1941ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001942 ld $t1, 0($sp) # Load referrer.
1943 ld $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_64($t1) # Load dex cache methods array.
1944 dsll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1945 daddu $t0, $t1, $t0 # Add offset to base.
1946 ld $t0, 0($t0) # Load interface method.
1947 ld $a0, ART_METHOD_JNI_OFFSET_64($a0) # Load ImtConflictTable.
1948
1949.Limt_table_iterate:
1950 ld $t1, 0($a0) # Load next entry in ImtConflictTable.
1951 # Branch if found.
1952 beq $t1, $t0, .Limt_table_found
1953 nop
1954 # If the entry is null, the interface method is not in the ImtConflictTable.
1955 beqzc $t1, .Lconflict_trampoline
1956 # Iterate over the entries of the ImtConflictTable.
1957 daddiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1958 bc .Limt_table_iterate
1959
1960.Limt_table_found:
1961 # We successfully hit an entry in the table. Load the target method and jump to it.
1962 ld $a0, __SIZEOF_POINTER__($a0)
1963 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)
1964 jr $t9
1965 .cpreturn # Restore gp from t8 in branch delay slot.
1966
1967.Lconflict_trampoline:
1968 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001969 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Maja Gagic6ea651f2015-02-24 16:55:04 +01001970END art_quick_imt_conflict_trampoline
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001971
1972 .extern artQuickResolutionTrampoline
1973ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001974 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001975 move $a2, rSELF # pass Thread::Current
1976 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
1977 move $a3, $sp # pass $sp
1978 beq $v0, $zero, 1f
Mathieu Chartiere401d142015-04-22 13:56:20 -07001979 ld $a0, 0($sp) # load resolved method in $a0
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001980 # artQuickResolutionTrampoline puts resolved method in *SP
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001981 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001982 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
1983 jalr $zero, $t9 # tail call to method
1984 nop
19851:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001986 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001987 DELIVER_PENDING_EXCEPTION
1988END art_quick_resolution_trampoline
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001989
1990 .extern artQuickGenericJniTrampoline
1991 .extern artQuickGenericJniEndTrampoline
1992ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001993 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001994 move $s8, $sp # save $sp
1995
1996 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1997 move $a0, rSELF # pass Thread::Current
1998 move $a1, $sp # pass $sp
1999 jal artQuickGenericJniTrampoline # (Thread*, SP)
2000 daddiu $sp, $sp, -5120 # reserve space on the stack
2001
2002 # The C call will have registered the complete save-frame on success.
2003 # The result of the call is:
2004 # v0: ptr to native code, 0 on error.
2005 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
2006 beq $v0, $zero, 1f # check entry error
2007 move $t9, $v0 # save the code ptr
2008 move $sp, $v1 # release part of the alloca
2009
2010 # Load parameters from stack into registers
2011 ld $a0, 0($sp)
2012 ld $a1, 8($sp)
2013 ld $a2, 16($sp)
2014 ld $a3, 24($sp)
2015 ld $a4, 32($sp)
2016 ld $a5, 40($sp)
2017 ld $a6, 48($sp)
2018 ld $a7, 56($sp)
2019 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
2020 l.d $f12, 0($sp)
2021 l.d $f13, 8($sp)
2022 l.d $f14, 16($sp)
2023 l.d $f15, 24($sp)
2024 l.d $f16, 32($sp)
2025 l.d $f17, 40($sp)
2026 l.d $f18, 48($sp)
2027 l.d $f19, 56($sp)
2028 jalr $t9 # native call
2029 daddiu $sp, $sp, 64
2030
2031 # result sign extension is handled in C code
2032 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
2033 move $a0, rSELF # pass Thread::Current
2034 move $a1, $v0
2035 jal artQuickGenericJniEndTrampoline
2036 dmfc1 $a2, $f0
2037
2038 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002039 bne $t0, $zero, 1f # check for pending exceptions
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002040 move $sp, $s8 # tear down the alloca
2041
2042 # tear dpown the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002043 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002044
2045 jalr $zero, $ra
2046 dmtc1 $v0, $f0 # place return value to FP return value
2047
20481:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002049 ld $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2050 # This will create a new save-all frame, required by the runtime.
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002051 DELIVER_PENDING_EXCEPTION
2052END art_quick_generic_jni_trampoline
2053
2054 .extern artQuickToInterpreterBridge
2055ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002056 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002057 move $a1, rSELF # pass Thread::Current
2058 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
2059 move $a2, $sp # pass $sp
2060 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
2061 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002062 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002063 bne $t0, $zero, 1f
2064 dmtc1 $v0, $f0 # place return value to FP return value
2065 jalr $zero, $ra
2066 dmtc1 $v1, $f1 # place return value to FP return value
20671:
2068 DELIVER_PENDING_EXCEPTION
2069END art_quick_to_interpreter_bridge
2070
2071 /*
2072 * Routine that intercepts method calls and returns.
2073 */
2074 .extern artInstrumentationMethodEntryFromCode
2075 .extern artInstrumentationMethodExitFromCode
2076ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002077 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002078 daddiu $sp, $sp, -16 # space for saving arg0
2079 .cfi_adjust_cfa_offset 16
2080 sd $a0, 0($sp) # save arg0
2081 move $a3, $ra # pass $ra
2082 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, RA)
2083 move $a2, rSELF # pass Thread::Current
2084 move $t9, $v0 # $t9 holds reference to code
2085 ld $a0, 0($sp) # restore arg0
2086 daddiu $sp, $sp, 16 # remove args
2087 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002088 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002089 jalr $t9 # call method
2090 nop
2091END art_quick_instrumentation_entry
2092 /* intentional fallthrough */
2093 .global art_quick_instrumentation_exit
2094art_quick_instrumentation_exit:
2095 .cfi_startproc
Goran Jakovljevic04568812015-04-23 15:27:23 +02002096 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002097 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002098 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002099 move $t0, $sp # remember bottom of caller's frame
2100 daddiu $sp, $sp, -16 # save return values and set up args
2101 .cfi_adjust_cfa_offset 16
2102 sd $v0, 0($sp)
2103 .cfi_rel_offset 2, 0
2104 s.d $f0, 8($sp)
2105 mov.d $f15, $f0 # pass fpr result
2106 move $a2, $v0 # pass gpr result
2107 move $a1, $t0 # pass $sp
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002108 move $a0, rSELF # pass Thread::Current
Goran Jakovljevic04568812015-04-23 15:27:23 +02002109 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
2110 .cpreturn # Restore gp from t8 in branch delay slot. gp is not used anymore,
2111 # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
2112
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002113 move $t9, $v0 # set aside returned link register
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002114 move $ra, $v1 # set link register for deoptimization
2115 ld $v0, 0($sp) # restore return values
2116 l.d $f0, 8($sp)
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002117 jalr $zero, $t9 # return
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002118 # restore stack, 16 bytes of saved values + ref_only callee save frame
2119 daddiu $sp, $sp, 16+FRAME_SIZE_SAVE_REFS_ONLY
2120 .cfi_adjust_cfa_offset -(16+FRAME_SIZE_SAVE_REFS_ONLY)
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002121END art_quick_instrumentation_exit
2122
Maja Gagic6ea651f2015-02-24 16:55:04 +01002123 /*
2124 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2125 * will long jump to the upcall with a special exception of -1.
2126 */
2127 .extern artDeoptimize
2128 .extern artEnterInterpreterFromDeoptimize
2129ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002130 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01002131 jal artDeoptimize # artDeoptimize(Thread*, SP)
2132 # Returns caller method's frame size.
2133 move $a0, rSELF # pass Thread::current
2134END art_quick_deoptimize
2135
Sebastien Hertz07474662015-08-25 15:12:33 +00002136 /*
2137 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2138 * will long jump to the upcall with a special exception of -1.
2139 */
2140 .extern artDeoptimizeFromCompiledCode
2141ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002142 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002143 jal artDeoptimizeFromCompiledCode # artDeoptimizeFromCompiledCode(Thread*, SP)
2144 # Returns caller method's frame size.
2145 move $a0, rSELF # pass Thread::current
2146END art_quick_deoptimize_from_compiled_code
2147
Chris Larsen9701c2e2015-09-04 17:22:47 -07002148 .set push
2149 .set noat
2150/* java.lang.String.compareTo(String anotherString) */
2151ENTRY_NO_GP art_quick_string_compareto
2152/* $a0 holds address of "this" */
2153/* $a1 holds address of "anotherString" */
2154 beq $a0,$a1,9f # this and anotherString are the same object
2155 move $v0,$zero
2156
2157 lw $a2,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2158 lw $a3,MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002159 MINu $t2, $a2, $a3
2160# $t2 now holds min(this.length(),anotherString.length())
Chris Larsen9701c2e2015-09-04 17:22:47 -07002161
2162 beqz $t2,9f # while min(this.length(),anotherString.length())-i != 0
2163 subu $v0,$a2,$a3 # if $t2==0 return
2164 # (this.length() - anotherString.length())
21651:
2166 lhu $t0,MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2167 lhu $t1,MIRROR_STRING_VALUE_OFFSET($a1)
2168 bne $t0,$t1,9f # if this.charAt(i) != anotherString.charAt(i)
2169 subu $v0,$t0,$t1 # return (this.charAt(i) - anotherString.charAt(i))
2170 daddiu $a0,$a0,2 # point at this.charAt(i++)
2171 subu $t2,$t2,1 # new value of
2172 # min(this.length(),anotherString.length())-i
2173 bnez $t2,1b
2174 daddiu $a1,$a1,2 # point at anotherString.charAt(i++)
2175 subu $v0,$a2,$a3
2176
21779:
2178 j $ra
2179 nop
2180END art_quick_string_compareto
2181
2182/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2183ENTRY_NO_GP art_quick_indexof
2184/* $a0 holds address of "this" */
Chris Larsencf283da2016-01-19 16:45:35 -08002185/* $a1 holds "ch" */
2186/* $a2 holds "fromIndex" */
Chris Larsen9701c2e2015-09-04 17:22:47 -07002187 lw $t0,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002188 slt $at, $a2, $zero # if fromIndex < 0
2189 seleqz $a2, $a2, $at # fromIndex = 0;
2190 subu $t0,$t0,$a2 # this.length() - fromIndex
2191 blez $t0,6f # if this.length()-fromIndex <= 0
Chris Larsen9701c2e2015-09-04 17:22:47 -07002192 li $v0,-1 # return -1;
2193
2194 sll $v0,$a2,1 # $a0 += $a2 * 2
2195 daddu $a0,$a0,$v0 # " " " " "
Chris Larsencf283da2016-01-19 16:45:35 -08002196 move $v0,$a2 # Set i to fromIndex.
Chris Larsen9701c2e2015-09-04 17:22:47 -07002197
21981:
2199 lhu $t3,MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2200 beq $t3,$a1,6f # return i;
2201 daddu $a0,$a0,2 # i++
2202 subu $t0,$t0,1 # this.length() - i
2203 bnez $t0,1b # while this.length() - i > 0
2204 addu $v0,$v0,1 # i++
2205
2206 li $v0,-1 # if this.length() - i <= 0
2207 # return -1;
2208
22096:
2210 j $ra
2211 nop
2212END art_quick_indexof
2213
2214 .set pop