1/*
2 * Copyright (C) 2012 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_mips.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21    .set noreorder
22    .balign 4
23
24    /* Deliver the given exception */
25    .extern artDeliverExceptionFromCode
26    /* Deliver an exception pending on a thread */
27    .extern artDeliverPendingExceptionFromCode
28
29#define ARG_SLOT_SIZE   32    // space for a0-a3 plus 4 more words
30
31    /*
32     * Macro that sets up the callee save frame to conform with
33     * Runtime::CreateCalleeSaveMethod(kSaveAll)
34     * Callee-save: $s0-$s8 + $gp + $ra, 11 total + 1 word for Method*
35     * Clobbers $t0 and $sp
36     * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
37     * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
38     */
39.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
40    addiu  $sp, $sp, -96
41    .cfi_adjust_cfa_offset 96
42
43     // Ugly compile-time check, but we only have the preprocessor.
44#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 96)
45#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS) size not as expected."
46#endif
47
48    sw     $ra, 92($sp)
49    .cfi_rel_offset 31, 92
50    sw     $s8, 88($sp)
51    .cfi_rel_offset 30, 88
52    sw     $gp, 84($sp)
53    .cfi_rel_offset 28, 84
54    sw     $s7, 80($sp)
55    .cfi_rel_offset 23, 80
56    sw     $s6, 76($sp)
57    .cfi_rel_offset 22, 76
58    sw     $s5, 72($sp)
59    .cfi_rel_offset 21, 72
60    sw     $s4, 68($sp)
61    .cfi_rel_offset 20, 68
62    sw     $s3, 64($sp)
63    .cfi_rel_offset 19, 64
64    sw     $s2, 60($sp)
65    .cfi_rel_offset 18, 60
66    sw     $s1, 56($sp)
67    .cfi_rel_offset 17, 56
68    sw     $s0, 52($sp)
69    .cfi_rel_offset 16, 52
70
71    SDu $f30, $f31, 44, $sp, $t1
72    SDu $f28, $f29, 36, $sp, $t1
73    SDu $f26, $f27, 28, $sp, $t1
74    SDu $f24, $f25, 20, $sp, $t1
75    SDu $f22, $f23, 12, $sp, $t1
76    SDu $f20, $f21, 4,  $sp, $t1
77
78    # 1 word for holding Method*
79
80    lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
81    lw $t0, 0($t0)
82    lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t0)
83    sw $t0, 0($sp)                                # Place Method* at bottom of stack.
84    sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
85    addiu  $sp, $sp, -ARG_SLOT_SIZE               # reserve argument slots on the stack
86    .cfi_adjust_cfa_offset ARG_SLOT_SIZE
87.endm
88
89    /*
90     * Macro that sets up the callee save frame to conform with
91     * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC.
92     * Does not include rSUSPEND or rSELF
93     * callee-save: $s2-$s8 + $gp + $ra, 9 total + 2 words padding + 1 word to hold Method*
94     * Clobbers $t0 and $sp
95     * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
96     * Reserves FRAME_SIZE_REFS_ONLY_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
97     */
98.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
99    addiu  $sp, $sp, -48
100    .cfi_adjust_cfa_offset 48
101
102    // Ugly compile-time check, but we only have the preprocessor.
103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 48)
104#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS) size not as expected."
105#endif
106
107    sw     $ra, 44($sp)
108    .cfi_rel_offset 31, 44
109    sw     $s8, 40($sp)
110    .cfi_rel_offset 30, 40
111    sw     $gp, 36($sp)
112    .cfi_rel_offset 28, 36
113    sw     $s7, 32($sp)
114    .cfi_rel_offset 23, 32
115    sw     $s6, 28($sp)
116    .cfi_rel_offset 22, 28
117    sw     $s5, 24($sp)
118    .cfi_rel_offset 21, 24
119    sw     $s4, 20($sp)
120    .cfi_rel_offset 20, 20
121    sw     $s3, 16($sp)
122    .cfi_rel_offset 19, 16
123    sw     $s2, 12($sp)
124    .cfi_rel_offset 18, 12
125    # 2 words for alignment and bottom word will hold Method*
126
127    lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
128    lw $t0, 0($t0)
129    lw $t0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t0)
130    sw $t0, 0($sp)                                # Place Method* at bottom of stack.
131    sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
132    addiu  $sp, $sp, -ARG_SLOT_SIZE               # reserve argument slots on the stack
133    .cfi_adjust_cfa_offset ARG_SLOT_SIZE
134.endm
135
136.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
137    addiu  $sp, $sp, ARG_SLOT_SIZE                # remove argument slots on the stack
138    .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
139    lw     $ra, 44($sp)
140    .cfi_restore 31
141    lw     $s8, 40($sp)
142    .cfi_restore 30
143    lw     $gp, 36($sp)
144    .cfi_restore 28
145    lw     $s7, 32($sp)
146    .cfi_restore 23
147    lw     $s6, 28($sp)
148    .cfi_restore 22
149    lw     $s5, 24($sp)
150    .cfi_restore 21
151    lw     $s4, 20($sp)
152    .cfi_restore 20
153    lw     $s3, 16($sp)
154    .cfi_restore 19
155    lw     $s2, 12($sp)
156    .cfi_restore 18
157    addiu  $sp, $sp, 48
158    .cfi_adjust_cfa_offset -48
159.endm
160
161.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
162    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
163    jalr   $zero, $ra
164    nop
165.endm
166
167    /*
168     * Macro that sets up the callee save frame to conform with
169     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
170     * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
171     */
172.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
173    addiu  $sp, $sp, -80
174    .cfi_adjust_cfa_offset 80
175
176    // Ugly compile-time check, but we only have the preprocessor.
177#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 80)
178#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS) size not as expected."
179#endif
180
181    sw     $ra, 76($sp)
182    .cfi_rel_offset 31, 76
183    sw     $s8, 72($sp)
184    .cfi_rel_offset 30, 72
185    sw     $gp, 68($sp)
186    .cfi_rel_offset 28, 68
187    sw     $s7, 64($sp)
188    .cfi_rel_offset 23, 64
189    sw     $s6, 60($sp)
190    .cfi_rel_offset 22, 60
191    sw     $s5, 56($sp)
192    .cfi_rel_offset 21, 56
193    sw     $s4, 52($sp)
194    .cfi_rel_offset 20, 52
195    sw     $s3, 48($sp)
196    .cfi_rel_offset 19, 48
197    sw     $s2, 44($sp)
198    .cfi_rel_offset 18, 44
199    sw     $a3, 40($sp)
200    .cfi_rel_offset 7, 40
201    sw     $a2, 36($sp)
202    .cfi_rel_offset 6, 36
203    sw     $a1, 32($sp)
204    .cfi_rel_offset 5, 32
205    SDu $f14, $f15, 24, $sp, $t0
206    SDu $f12, $f13, 16, $sp, $t0
207    # bottom will hold Method*
208.endm
209
210    /*
211     * Macro that sets up the callee save frame to conform with
212     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
213     * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
214     * Clobbers $t0 and $sp
215     * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
216     * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
217     */
218.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
219    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
220    lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
221    lw $t0, 0($t0)
222    lw $t0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t0)
223    sw $t0, 0($sp)                                # Place Method* at bottom of stack.
224    sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
225    addiu  $sp, $sp, -ARG_SLOT_SIZE               # reserve argument slots on the stack
226    .cfi_adjust_cfa_offset ARG_SLOT_SIZE
227.endm
228
229    /*
230     * Macro that sets up the callee save frame to conform with
231     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
232     * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
233     * Clobbers $sp
234     * Use $a0 as the Method* and loads it into bottom of stack.
235     * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
236     * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
237     */
238.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
239    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
240    sw $a0, 0($sp)                                # Place Method* at bottom of stack.
241    sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
242    addiu  $sp, $sp, -ARG_SLOT_SIZE               # reserve argument slots on the stack
243    .cfi_adjust_cfa_offset ARG_SLOT_SIZE
244.endm
245
246.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
247    addiu  $sp, $sp, ARG_SLOT_SIZE                # remove argument slots on the stack
248    .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
249    lw     $ra, 76($sp)
250    .cfi_restore 31
251    lw     $s8, 72($sp)
252    .cfi_restore 30
253    lw     $gp, 68($sp)
254    .cfi_restore 28
255    lw     $s7, 64($sp)
256    .cfi_restore 23
257    lw     $s6, 60($sp)
258    .cfi_restore 22
259    lw     $s5, 56($sp)
260    .cfi_restore 21
261    lw     $s4, 52($sp)
262    .cfi_restore 20
263    lw     $s3, 48($sp)
264    .cfi_restore 19
265    lw     $s2, 44($sp)
266    .cfi_restore 18
267    lw     $a3, 40($sp)
268    .cfi_restore 7
269    lw     $a2, 36($sp)
270    .cfi_restore 6
271    lw     $a1, 32($sp)
272    .cfi_restore 5
273    LDu $f14, $f15, 24, $sp, $t1
274    LDu $f12, $f13, 16, $sp, $t1
275    addiu  $sp, $sp, 80           # pop frame
276    .cfi_adjust_cfa_offset -80
277.endm
278
279    /*
280     * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
281     * exception is Thread::Current()->exception_
282     */
283.macro DELIVER_PENDING_EXCEPTION
284    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME     # save callee saves for throw
285    la      $t9, artDeliverPendingExceptionFromCode
286    jalr    $zero, $t9                   # artDeliverPendingExceptionFromCode(Thread*)
287    move    $a0, rSELF                   # pass Thread::Current
288.endm
289
290.macro RETURN_IF_NO_EXCEPTION
291    lw     $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
292    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
293    bnez   $t0, 1f                       # success if no exception is pending
294    nop
295    jalr   $zero, $ra
296    nop
2971:
298    DELIVER_PENDING_EXCEPTION
299.endm
300
301.macro RETURN_IF_ZERO
302    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
303    bnez   $v0, 1f                       # success?
304    nop
305    jalr   $zero, $ra                    # return on success
306    nop
3071:
308    DELIVER_PENDING_EXCEPTION
309.endm
310
311.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
312    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
313    beqz   $v0, 1f                       # success?
314    nop
315    jalr   $zero, $ra                    # return on success
316    nop
3171:
318    DELIVER_PENDING_EXCEPTION
319.endm
320
321    /*
322     * On stack replacement stub.
323     * On entry:
324     *   a0 = stack to copy
325     *   a1 = size of stack
326     *   a2 = pc to call
327     *   a3 = JValue* result
328     *   [sp + 16] = shorty
329     *   [sp + 20] = thread
330     */
331ENTRY art_quick_osr_stub
332    // Save callee general purpose registers, RA and GP.
333    addiu  $sp, $sp, -48
334    .cfi_adjust_cfa_offset 48
335    sw     $ra, 44($sp)
336    .cfi_rel_offset 31, 44
337    sw     $s8, 40($sp)
338    .cfi_rel_offset 30, 40
339    sw     $gp, 36($sp)
340    .cfi_rel_offset 28, 36
341    sw     $s7, 32($sp)
342    .cfi_rel_offset 23, 32
343    sw     $s6, 28($sp)
344    .cfi_rel_offset 22, 28
345    sw     $s5, 24($sp)
346    .cfi_rel_offset 21, 24
347    sw     $s4, 20($sp)
348    .cfi_rel_offset 20, 20
349    sw     $s3, 16($sp)
350    .cfi_rel_offset 19, 16
351    sw     $s2, 12($sp)
352    .cfi_rel_offset 18, 12
353    sw     $s1, 8($sp)
354    .cfi_rel_offset 17, 8
355    sw     $s0, 4($sp)
356    .cfi_rel_offset 16, 4
357
358    move   $s8, $sp                        # Save the stack pointer
359    move   $s7, $a1                        # Save size of stack
360    move   $s6, $a2                        # Save the pc to call
361    lw     rSELF, 48+20($sp)               # Save managed thread pointer into rSELF
362    addiu  $t0, $sp, -12                   # Reserve space for stack pointer,
363                                           #    JValue* result, and ArtMethod* slot.
364    srl    $t0, $t0, 4                     # Align stack pointer to 16 bytes
365    sll    $sp, $t0, 4                     # Update stack pointer
366    sw     $s8, 4($sp)                     # Save old stack pointer
367    sw     $a3, 8($sp)                     # Save JValue* result
368    sw     $zero, 0($sp)                   # Store null for ArtMethod* at bottom of frame
369    subu   $sp, $a1                        # Reserve space for callee stack
370    move   $a2, $a1
371    move   $a1, $a0
372    move   $a0, $sp
373    la     $t9, memcpy
374    jalr   $t9                             # memcpy (dest a0, src a1, bytes a2)
375    addiu  $sp, $sp, -16                   # make space for argument slots for memcpy
376    bal    .Losr_entry                     # Call the method
377    addiu  $sp, $sp, 16                    # restore stack after memcpy
378    lw     $a2, 8($sp)                     # Restore JValue* result
379    lw     $sp, 4($sp)                     # Restore saved stack pointer
380    lw     $a0, 48+16($sp)                 # load shorty
381    lbu    $a0, 0($a0)                     # load return type
382    li     $a1, 'D'                        # put char 'D' into a1
383    beq    $a0, $a1, .Losr_fp_result       # Test if result type char == 'D'
384    li     $a1, 'F'                        # put char 'F' into a1
385    beq    $a0, $a1, .Losr_fp_result       # Test if result type char == 'F'
386    nop
387    sw     $v0, 0($a2)
388    b      .Losr_exit
389    sw     $v1, 4($a2)                     # store v0/v1 into result
390.Losr_fp_result:
391    SDu    $f0, $f1, 0, $a2, $t0           # store f0/f1 into result
392.Losr_exit:
393    lw     $ra, 44($sp)
394    .cfi_restore 31
395    lw     $s8, 40($sp)
396    .cfi_restore 30
397    lw     $gp, 36($sp)
398    .cfi_restore 28
399    lw     $s7, 32($sp)
400    .cfi_restore 23
401    lw     $s6, 28($sp)
402    .cfi_restore 22
403    lw     $s5, 24($sp)
404    .cfi_restore 21
405    lw     $s4, 20($sp)
406    .cfi_restore 20
407    lw     $s3, 16($sp)
408    .cfi_restore 19
409    lw     $s2, 12($sp)
410    .cfi_restore 18
411    lw     $s1, 8($sp)
412    .cfi_restore 17
413    lw     $s0, 4($sp)
414    .cfi_restore 16
415    jalr   $zero, $ra
416    addiu  $sp, $sp, 48
417    .cfi_adjust_cfa_offset -48
418.Losr_entry:
419    addiu  $s7, $s7, -4
420    addu   $t0, $s7, $sp
421    move   $t9, $s6
422    jalr   $zero, $t9
423    sw     $ra, 0($t0)                     # Store RA per the compiler ABI
424END art_quick_osr_stub
425
426    /*
427     * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
428     * FIXME: just guessing about the shape of the jmpbuf.  Where will pc be?
429     */
430ENTRY art_quick_do_long_jump
431    LDu  $f0,  $f1,   0*8, $a1, $t1
432    LDu  $f2,  $f3,   1*8, $a1, $t1
433    LDu  $f4,  $f5,   2*8, $a1, $t1
434    LDu  $f6,  $f7,   3*8, $a1, $t1
435    LDu  $f8,  $f9,   4*8, $a1, $t1
436    LDu  $f10, $f11,  5*8, $a1, $t1
437    LDu  $f12, $f13,  6*8, $a1, $t1
438    LDu  $f14, $f15,  7*8, $a1, $t1
439    LDu  $f16, $f17,  8*8, $a1, $t1
440    LDu  $f18, $f19,  9*8, $a1, $t1
441    LDu  $f20, $f21, 10*8, $a1, $t1
442    LDu  $f22, $f23, 11*8, $a1, $t1
443    LDu  $f24, $f25, 12*8, $a1, $t1
444    LDu  $f26, $f27, 13*8, $a1, $t1
445    LDu  $f28, $f29, 14*8, $a1, $t1
446    LDu  $f30, $f31, 15*8, $a1, $t1
447
448    .set push
449    .set nomacro
450    .set noat
451    lw      $at, 4($a0)
452    .set pop
453    lw      $v0, 8($a0)
454    lw      $v1, 12($a0)
455    lw      $a1, 20($a0)
456    lw      $a2, 24($a0)
457    lw      $a3, 28($a0)
458    lw      $t0, 32($a0)
459    lw      $t1, 36($a0)
460    lw      $t2, 40($a0)
461    lw      $t3, 44($a0)
462    lw      $t4, 48($a0)
463    lw      $t5, 52($a0)
464    lw      $t6, 56($a0)
465    lw      $t7, 60($a0)
466    lw      $s0, 64($a0)
467    lw      $s1, 68($a0)
468    lw      $s2, 72($a0)
469    lw      $s3, 76($a0)
470    lw      $s4, 80($a0)
471    lw      $s5, 84($a0)
472    lw      $s6, 88($a0)
473    lw      $s7, 92($a0)
474    lw      $t8, 96($a0)
475    lw      $t9, 100($a0)
476    lw      $gp, 112($a0)
477    lw      $sp, 116($a0)
478    lw      $fp, 120($a0)
479    lw      $ra, 124($a0)
480    lw      $a0, 16($a0)
481    move    $v0, $zero          # clear result registers v0 and v1 (in branch delay slot)
482    jalr    $zero, $t9          # do long jump
483    move    $v1, $zero
484END art_quick_do_long_jump
485
486    /*
487     * Called by managed code, saves most registers (forms basis of long jump context) and passes
488     * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
489     * the bottom of the thread. On entry a0 holds Throwable*
490     */
491ENTRY art_quick_deliver_exception
492    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
493    la   $t9, artDeliverExceptionFromCode
494    jalr $zero, $t9                 # artDeliverExceptionFromCode(Throwable*, Thread*)
495    move $a1, rSELF                 # pass Thread::Current
496END art_quick_deliver_exception
497
498    /*
499     * Called by managed code to create and deliver a NullPointerException
500     */
501    .extern artThrowNullPointerExceptionFromCode
502ENTRY art_quick_throw_null_pointer_exception
503    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
504    la   $t9, artThrowNullPointerExceptionFromCode
505    jalr $zero, $t9                 # artThrowNullPointerExceptionFromCode(Thread*)
506    move $a0, rSELF                 # pass Thread::Current
507END art_quick_throw_null_pointer_exception
508
509    /*
510     * Called by managed code to create and deliver an ArithmeticException
511     */
512    .extern artThrowDivZeroFromCode
513ENTRY art_quick_throw_div_zero
514    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
515    la   $t9, artThrowDivZeroFromCode
516    jalr $zero, $t9                 # artThrowDivZeroFromCode(Thread*)
517    move $a0, rSELF                 # pass Thread::Current
518END art_quick_throw_div_zero
519
520    /*
521     * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
522     */
523    .extern artThrowArrayBoundsFromCode
524ENTRY art_quick_throw_array_bounds
525    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
526    la   $t9, artThrowArrayBoundsFromCode
527    jalr $zero, $t9                 # artThrowArrayBoundsFromCode(index, limit, Thread*)
528    move $a2, rSELF                 # pass Thread::Current
529END art_quick_throw_array_bounds
530
531    /*
532     * Called by managed code to create and deliver a StackOverflowError.
533     */
534    .extern artThrowStackOverflowFromCode
535ENTRY art_quick_throw_stack_overflow
536    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
537    la   $t9, artThrowStackOverflowFromCode
538    jalr $zero, $t9                 # artThrowStackOverflowFromCode(Thread*)
539    move $a0, rSELF                 # pass Thread::Current
540END art_quick_throw_stack_overflow
541
542    /*
543     * Called by managed code to create and deliver a NoSuchMethodError.
544     */
545    .extern artThrowNoSuchMethodFromCode
546ENTRY art_quick_throw_no_such_method
547    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
548    la   $t9, artThrowNoSuchMethodFromCode
549    jalr $zero, $t9                 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
550    move $a1, rSELF                 # pass Thread::Current
551END art_quick_throw_no_such_method
552
553    /*
554     * All generated callsites for interface invokes and invocation slow paths will load arguments
555     * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
556     * the method_idx.  This wrapper will save arg1-arg3, and call the appropriate C helper.
557     * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
558     *
559     * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
560     * of the target Method* in $v0 and method->code_ in $v1.
561     *
562     * If unsuccessful, the helper will return null/null. There will be a pending exception in the
563     * thread and we branch to another stub to deliver it.
564     *
565     * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
566     * pointing back to the original caller.
567     */
568.macro INVOKE_TRAMPOLINE_BODY cxx_name
569    .extern \cxx_name
570    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME  # save callee saves in case allocation triggers GC
571    move  $a2, rSELF                       # pass Thread::Current
572    la    $t9, \cxx_name
573    jalr  $t9                              # (method_idx, this, Thread*, $sp)
574    addiu $a3, $sp, ARG_SLOT_SIZE          # pass $sp (remove arg slots)
575    move  $a0, $v0                         # save target Method*
576    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
577    beqz  $v0, 1f
578    move  $t9, $v1                         # save $v0->code_
579    jalr  $zero, $t9
580    nop
5811:
582    DELIVER_PENDING_EXCEPTION
583.endm
584.macro INVOKE_TRAMPOLINE c_name, cxx_name
585ENTRY \c_name
586    INVOKE_TRAMPOLINE_BODY \cxx_name
587END \c_name
588.endm
589
590INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
591
592INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
593INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
594INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
595INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
596
597.macro LOAD_WORD_TO_REG reg, next_arg, index, label
598    lw    $\reg, -4($\next_arg)   # next_arg points to argument after the current one (offset is 4)
599    b     \label
600    addiu $\index, 1
601.endm
602
603.macro LOAD_LONG_TO_REG reg1, reg2, next_arg, index, label
604    lw    $\reg1, -8($\next_arg)  # next_arg points to argument after the current one (offset is 8)
605    lw    $\reg2, -4($\next_arg)
606    b     \label
607    li    $\index, 4              # long can be loaded only to a2_a3 pair so index will be always 4
608.endm
609
610.macro LOAD_FLOAT_TO_REG reg, next_arg, index, label
611    lwc1  $\reg, -4($\next_arg)   # next_arg points to argument after the current one (offset is 4)
612    b     \label
613    addiu $\index, 1
614.endm
615
616.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index, tmp, label
617    LDu  $\reg1, $\reg2, -8, $\next_arg, $\tmp  # next_arg points to argument after the current one
618                                                # (offset is 8)
619    b     \label
620    addiu $\index, 1
621.endm
622
623#define SPILL_SIZE    32
624
625    /*
626     * Invocation stub for quick code.
627     * On entry:
628     *   a0 = method pointer
629     *   a1 = argument array or null for no argument methods
630     *   a2 = size of argument array in bytes
631     *   a3 = (managed) thread pointer
632     *   [sp + 16] = JValue* result
633     *   [sp + 20] = shorty
634     */
635ENTRY art_quick_invoke_stub
636    sw    $a0, 0($sp)           # save out a0
637    addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
638    .cfi_adjust_cfa_offset SPILL_SIZE
639    sw    $gp, 16($sp)
640    sw    $ra, 12($sp)
641    .cfi_rel_offset 31, 12
642    sw    $fp, 8($sp)
643    .cfi_rel_offset 30, 8
644    sw    $s1, 4($sp)
645    .cfi_rel_offset 17, 4
646    sw    $s0, 0($sp)
647    .cfi_rel_offset 16, 0
648    move  $fp, $sp              # save sp in fp
649    .cfi_def_cfa_register 30
650    move  $s1, $a3              # move managed thread pointer into s1
651    addiu $s0, $zero, SUSPEND_CHECK_INTERVAL  # reset s0 to suspend check interval
652    addiu $t0, $a2, 4           # create space for ArtMethod* in frame.
653    subu  $t0, $sp, $t0         # reserve & align *stack* to 16 bytes:
654    srl   $t0, $t0, 4           #   native calling convention only aligns to 8B,
655    sll   $sp, $t0, 4           #   so we have to ensure ART 16B alignment ourselves.
656    addiu $a0, $sp, 4           # pass stack pointer + ArtMethod* as dest for memcpy
657    la    $t9, memcpy
658    jalr  $t9                   # (dest, src, bytes)
659    addiu $sp, $sp, -16         # make space for argument slots for memcpy
660    addiu $sp, $sp, 16          # restore stack after memcpy
661    lw    $gp, 16($fp)          # restore $gp
662    lw    $a0, SPILL_SIZE($fp)  # restore ArtMethod*
663    lw    $a1, 4($sp)           # a1 = this*
664    addiu $t0, $sp, 8           # t0 = pointer to the current argument (skip ArtMethod* and this*)
665    li    $t3, 2                # t3 = gpr_index = 2 (skip A0 and A1)
666    move  $t4, $zero            # t4 = fp_index = 0
667    lw    $t1, 20 + SPILL_SIZE($fp)  # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
668                                # as the $fp is SPILL_SIZE bytes below the $sp on entry)
669    addiu $t1, 1                # t1 = shorty + 1 (skip 1 for return type)
670loop:
671    lbu   $t2, 0($t1)           # t2 = shorty[i]
672    beqz  $t2, loopEnd          # finish getting args when shorty[i] == '\0'
673    addiu $t1, 1
674
675    li    $t9, 'J'              # put char 'J' into t9
676    beq   $t9, $t2, isLong      # branch if result type char == 'J'
677    li    $t9, 'D'              # put char 'D' into t9
678    beq   $t9, $t2, isDouble    # branch if result type char == 'D'
679    li    $t9, 'F'              # put char 'F' into t9
680    beq   $t9, $t2, isSingle    # branch if result type char == 'F'
681    addiu $t0, 4                # next_arg = curr_arg + 4 (in branch delay slot,
682                                # for both, int and single)
683
684    li    $t5, 2                                   # skip a0 and a1 (ArtMethod* and this*)
685    bne   $t5, $t3, 1f                             # if (gpr_index == 2)
686    addiu $t5, 1
687    LOAD_WORD_TO_REG a2, t0, t3, loop              #   a2 = current argument, gpr_index++
6881:  bne   $t5, $t3, loop                           # else if (gpr_index == 3)
689    nop
690    LOAD_WORD_TO_REG a3, t0, t3, loop              #   a3 = current argument, gpr_index++
691
692isLong:
693    addiu $t0, 8                                   # next_arg = curr_arg + 8
694    slti  $t5, $t3, 3
695    beqz  $t5, 2f                                  # if (gpr_index < 3)
696    nop
697    LOAD_LONG_TO_REG a2, a3, t0, t3, loop          #   a2_a3 = curr_arg, gpr_index = 4
6982:  b     loop                                     # else
699    li    $t3, 4                                   #   gpr_index = 4
700
701isDouble:
702    addiu $t0, 8                                   # next_arg = curr_arg + 8
703    li    $t5, 0
704    bne   $t5, $t4, 3f                             # if (fp_index == 0)
705    addiu $t5, 1
706    LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loop  #   f12_f13 = curr_arg, fp_index++
7073:  bne   $t5, $t4, loop                           # else if (fp_index == 1)
708    nop
709    LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loop  #   f14_f15 = curr_arg, fp_index++
710
711isSingle:
712    li    $t5, 0
713    bne   $t5, $t4, 4f                             # if (fp_index == 0)
714    addiu $t5, 1
715    LOAD_FLOAT_TO_REG f12, t0, t4, loop            #   f12 = curr_arg, fp_index++
7164:  bne   $t5, $t4, loop                           # else if (fp_index == 1)
717    nop
718    LOAD_FLOAT_TO_REG f14, t0, t4, loop            #   f14 = curr_arg, fp_index++
719
720loopEnd:
721    lw    $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)  # get pointer to the code
722    jalr  $t9                   # call the method
723    sw    $zero, 0($sp)         # store null for ArtMethod* at bottom of frame
724    move  $sp, $fp              # restore the stack
725    lw    $s0, 0($sp)
726    .cfi_restore 16
727    lw    $s1, 4($sp)
728    .cfi_restore 17
729    lw    $fp, 8($sp)
730    .cfi_restore 30
731    lw    $ra, 12($sp)
732    .cfi_restore 31
733    addiu $sp, $sp, SPILL_SIZE
734    .cfi_adjust_cfa_offset -SPILL_SIZE
735    lw    $t0, 16($sp)          # get result pointer
736    lw    $t1, 20($sp)          # get shorty
737    lb    $t1, 0($t1)           # get result type char
738    li    $t2, 'D'              # put char 'D' into t2
739    beq   $t1, $t2, 5f          # branch if result type char == 'D'
740    li    $t3, 'F'              # put char 'F' into t3
741    beq   $t1, $t3, 5f          # branch if result type char == 'F'
742    sw    $v0, 0($t0)           # store the result
743    jalr  $zero, $ra
744    sw    $v1, 4($t0)           # store the other half of the result
7455:
746    SDu   $f0, $f1, 0, $t0, $t1 # store floating point result
747    jalr  $zero, $ra
748    nop
749END art_quick_invoke_stub
750
751    /*
752     * Invocation static stub for quick code.
753     * On entry:
754     *   a0 = method pointer
755     *   a1 = argument array or null for no argument methods
756     *   a2 = size of argument array in bytes
757     *   a3 = (managed) thread pointer
758     *   [sp + 16] = JValue* result
759     *   [sp + 20] = shorty
760     */
761ENTRY art_quick_invoke_static_stub
762    sw    $a0, 0($sp)           # save out a0
763    addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
764    .cfi_adjust_cfa_offset SPILL_SIZE
765    sw    $gp, 16($sp)
766    sw    $ra, 12($sp)
767    .cfi_rel_offset 31, 12
768    sw    $fp, 8($sp)
769    .cfi_rel_offset 30, 8
770    sw    $s1, 4($sp)
771    .cfi_rel_offset 17, 4
772    sw    $s0, 0($sp)
773    .cfi_rel_offset 16, 0
774    move  $fp, $sp              # save sp in fp
775    .cfi_def_cfa_register 30
776    move  $s1, $a3              # move managed thread pointer into s1
777    addiu $s0, $zero, SUSPEND_CHECK_INTERVAL  # reset s0 to suspend check interval
778    addiu $t0, $a2, 4           # create space for ArtMethod* in frame.
779    subu  $t0, $sp, $t0         # reserve & align *stack* to 16 bytes:
780    srl   $t0, $t0, 4           #   native calling convention only aligns to 8B,
781    sll   $sp, $t0, 4           #   so we have to ensure ART 16B alignment ourselves.
782    addiu $a0, $sp, 4           # pass stack pointer + ArtMethod* as dest for memcpy
783    la    $t9, memcpy
784    jalr  $t9                   # (dest, src, bytes)
785    addiu $sp, $sp, -16         # make space for argument slots for memcpy
786    addiu $sp, $sp, 16          # restore stack after memcpy
787    lw    $gp, 16($fp)          # restore $gp
788    lw    $a0, SPILL_SIZE($fp)  # restore ArtMethod*
789    addiu $t0, $sp, 4           # t0 = pointer to the current argument (skip ArtMethod*)
790    li    $t3, 1                # t3 = gpr_index = 1 (skip A0)
791    move  $t4, $zero            # t4 = fp_index = 0
792    lw    $t1, 20 + SPILL_SIZE($fp)  # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
793                                # as the $fp is SPILL_SIZE bytes below the $sp on entry)
794    addiu $t1, 1                # t1 = shorty + 1 (skip 1 for return type)
795loopS:
796    lbu   $t2, 0($t1)           # t2 = shorty[i]
797    beqz  $t2, loopEndS         # finish getting args when shorty[i] == '\0'
798    addiu $t1, 1
799
800    li    $t9, 'J'              # put char 'J' into t9
801    beq   $t9, $t2, isLongS     # branch if result type char == 'J'
802    li    $t9, 'D'              # put char 'D' into t9
803    beq   $t9, $t2, isDoubleS   # branch if result type char == 'D'
804    li    $t9, 'F'              # put char 'F' into t9
805    beq   $t9, $t2, isSingleS   # branch if result type char == 'F'
806    addiu $t0, 4                # next_arg = curr_arg + 4 (in branch delay slot,
807                                # for both, int and single)
808
809    li    $t5, 1                                    # skip a0 (ArtMethod*)
810    bne   $t5, $t3, 1f                              # if (gpr_index == 1)
811    addiu $t5, 1
812    LOAD_WORD_TO_REG a1, t0, t3, loopS              #   a1 = current argument, gpr_index++
8131:  bne   $t5, $t3, 2f                              # else if (gpr_index == 2)
814    addiu $t5, 1
815    LOAD_WORD_TO_REG a2, t0, t3, loopS              #   a2 = current argument, gpr_index++
8162:  bne   $t5, $t3, loopS                           # else if (gpr_index == 3)
817    nop
818    LOAD_WORD_TO_REG a3, t0, t3, loopS              #   a3 = current argument, gpr_index++
819
820isLongS:
821    addiu $t0, 8                                    # next_arg = curr_arg + 8
822    slti  $t5, $t3, 3
823    beqz  $t5, 3f                                   # if (gpr_index < 3)
824    nop
825    LOAD_LONG_TO_REG a2, a3, t0, t3, loopS          #   a2_a3 = curr_arg, gpr_index = 4
8263:  b     loopS                                     # else
827    li    $t3, 4                                    #   gpr_index = 4
828
829isDoubleS:
830    addiu $t0, 8                                    # next_arg = curr_arg + 8
831    li    $t5, 0
832    bne   $t5, $t4, 4f                              # if (fp_index == 0)
833    addiu $t5, 1
834    LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loopS  #   f12_f13 = curr_arg, fp_index++
8354:  bne   $t5, $t4, loopS                           # else if (fp_index == 1)
836    nop
837    LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loopS  #   f14_f15 = curr_arg, fp_index++
838
839isSingleS:
840    li    $t5, 0
841    bne   $t5, $t4, 5f                              # if (fp_index == 0)
842    addiu $t5, 1
843    LOAD_FLOAT_TO_REG f12, t0, t4, loopS            #   f12 = curr_arg, fp_index++
8445:  bne   $t5, $t4, loopS                           # else if (fp_index == 1)
845    nop
846    LOAD_FLOAT_TO_REG f14, t0, t4, loopS            #   f14 = curr_arg, fp_index++
847
848loopEndS:
849    lw    $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)  # get pointer to the code
850    jalr  $t9                   # call the method
851    sw    $zero, 0($sp)         # store null for ArtMethod* at bottom of frame
852    move  $sp, $fp              # restore the stack
853    lw    $s0, 0($sp)
854    .cfi_restore 16
855    lw    $s1, 4($sp)
856    .cfi_restore 17
857    lw    $fp, 8($sp)
858    .cfi_restore 30
859    lw    $ra, 12($sp)
860    .cfi_restore 31
861    addiu $sp, $sp, SPILL_SIZE
862    .cfi_adjust_cfa_offset -SPILL_SIZE
863    lw    $t0, 16($sp)          # get result pointer
864    lw    $t1, 20($sp)          # get shorty
865    lb    $t1, 0($t1)           # get result type char
866    li    $t2, 'D'              # put char 'D' into t2
867    beq   $t1, $t2, 6f          # branch if result type char == 'D'
868    li    $t3, 'F'              # put char 'F' into t3
869    beq   $t1, $t3, 6f          # branch if result type char == 'F'
870    sw    $v0, 0($t0)           # store the result
871    jalr  $zero, $ra
872    sw    $v1, 4($t0)           # store the other half of the result
8736:
874    SDu   $f0, $f1, 0, $t0, $t1 # store floating point result
875    jalr  $zero, $ra
876    nop
877END art_quick_invoke_static_stub
878
879#undef SPILL_SIZE
880
881    /*
882     * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
883     * failure.
884     */
885    .extern artHandleFillArrayDataFromCode
886ENTRY art_quick_handle_fill_data
887    lw     $a2, 0($sp)                    # pass referrer's Method*
888    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME     # save callee saves in case exception allocation triggers GC
889    la     $t9, artHandleFillArrayDataFromCode
890    jalr   $t9                            # (payload offset, Array*, method, Thread*)
891    move   $a3, rSELF                     # pass Thread::Current
892    RETURN_IF_ZERO
893END art_quick_handle_fill_data
894
895    /*
896     * Entry from managed code that calls artLockObjectFromCode, may block for GC.
897     */
898    .extern artLockObjectFromCode
899ENTRY art_quick_lock_object
900    beqz    $a0, .Lart_quick_throw_null_pointer_exception_gp_set
901    nop
902    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME     # save callee saves in case we block
903    la      $t9, artLockObjectFromCode
904    jalr    $t9                           # (Object* obj, Thread*)
905    move    $a1, rSELF                    # pass Thread::Current
906    RETURN_IF_ZERO
907END art_quick_lock_object
908
909ENTRY art_quick_lock_object_no_inline
910    beqz    $a0, .Lart_quick_throw_null_pointer_exception_gp_set
911    nop
912    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME     # save callee saves in case we block
913    la      $t9, artLockObjectFromCode
914    jalr    $t9                           # (Object* obj, Thread*)
915    move    $a1, rSELF                    # pass Thread::Current
916    RETURN_IF_ZERO
917END art_quick_lock_object_no_inline
918
919    /*
920     * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
921     */
922    .extern artUnlockObjectFromCode
923ENTRY art_quick_unlock_object
924    beqz    $a0, .Lart_quick_throw_null_pointer_exception_gp_set
925    nop
926    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
927    la      $t9, artUnlockObjectFromCode
928    jalr    $t9                       # (Object* obj, Thread*)
929    move    $a1, rSELF                # pass Thread::Current
930    RETURN_IF_ZERO
931END art_quick_unlock_object
932
933ENTRY art_quick_unlock_object_no_inline
934    beqz    $a0, .Lart_quick_throw_null_pointer_exception_gp_set
935    nop
936    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
937    la      $t9, artUnlockObjectFromCode
938    jalr    $t9                       # (Object* obj, Thread*)
939    move    $a1, rSELF                # pass Thread::Current
940    RETURN_IF_ZERO
941END art_quick_unlock_object_no_inline
942
943    /*
944     * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
945     */
946    .extern artThrowClassCastException
947ENTRY art_quick_check_cast
948    addiu  $sp, $sp, -32
949    .cfi_adjust_cfa_offset 32
950    sw     $gp, 16($sp)
951    sw     $ra, 12($sp)
952    .cfi_rel_offset 31, 12
953    sw     $t9, 8($sp)
954    sw     $a1, 4($sp)
955    sw     $a0, 0($sp)
956    la     $t9, artIsAssignableFromCode
957    jalr   $t9
958    addiu  $sp, $sp, -16             # reserve argument slots on the stack
959    addiu  $sp, $sp, 16
960    lw     $gp, 16($sp)
961    beqz   $v0, .Lthrow_class_cast_exception
962    lw     $ra, 12($sp)
963    jalr   $zero, $ra
964    addiu  $sp, $sp, 32
965    .cfi_adjust_cfa_offset -32
966.Lthrow_class_cast_exception:
967    lw     $t9, 8($sp)
968    lw     $a1, 4($sp)
969    lw     $a0, 0($sp)
970    addiu  $sp, $sp, 32
971    .cfi_adjust_cfa_offset -32
972    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
973    la   $t9, artThrowClassCastException
974    jalr $zero, $t9                 # artThrowClassCastException (Class*, Class*, Thread*)
975    move $a2, rSELF                 # pass Thread::Current
976END art_quick_check_cast
977
978    /*
979     * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
980     * nReg is the register number for rReg.
981     */
982.macro POP_REG_NE rReg, nReg, offset, rExclude
983    .ifnc \rReg, \rExclude
984        lw \rReg, \offset($sp)      # restore rReg
985        .cfi_restore \nReg
986    .endif
987.endm
988
989    /*
990     * Macro to insert read barrier, only used in art_quick_aput_obj.
991     * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
992     * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
993     */
994.macro READ_BARRIER rDest, rObj, offset
995#ifdef USE_READ_BARRIER
996    # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
997    addiu  $sp, $sp, -32
998    .cfi_adjust_cfa_offset 32
999    sw     $ra, 28($sp)
1000    .cfi_rel_offset 31, 28
1001    sw     $t9, 24($sp)
1002    .cfi_rel_offset 25, 24
1003    sw     $t1, 20($sp)
1004    .cfi_rel_offset 9, 20
1005    sw     $t0, 16($sp)
1006    .cfi_rel_offset 8, 16
1007    sw     $a2, 8($sp)              # padding slot at offset 12 (padding can be any slot in the 32B)
1008    .cfi_rel_offset 6, 8
1009    sw     $a1, 4($sp)
1010    .cfi_rel_offset 5, 4
1011    sw     $a0, 0($sp)
1012    .cfi_rel_offset 4, 0
1013
1014    # move $a0, \rRef               # pass ref in a0 (no-op for now since parameter ref is unused)
1015    .ifnc \rObj, $a1
1016        move $a1, \rObj             # pass rObj
1017    .endif
1018    addiu  $a2, $zero, \offset      # pass offset
1019    la     $t9, artReadBarrierSlow
1020    jalr   $t9                      # artReadBarrierSlow(ref, rObj, offset)
1021    addiu  $sp, $sp, -16            # Use branch delay slot to reserve argument slots on the stack
1022                                    # before the call to artReadBarrierSlow.
1023    addiu  $sp, $sp, 16             # restore stack after call to artReadBarrierSlow
1024    # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1025    move \rDest, $v0                # save return value in rDest
1026                                    # (rDest cannot be v0 in art_quick_aput_obj)
1027
1028    lw     $a0, 0($sp)              # restore registers except rDest
1029                                    # (rDest can only be t0 or t1 in art_quick_aput_obj)
1030    .cfi_restore 4
1031    lw     $a1, 4($sp)
1032    .cfi_restore 5
1033    lw     $a2, 8($sp)
1034    .cfi_restore 6
1035    POP_REG_NE $t0, 8, 16, \rDest
1036    POP_REG_NE $t1, 9, 20, \rDest
1037    lw     $t9, 24($sp)
1038    .cfi_restore 25
1039    lw     $ra, 28($sp)             # restore $ra
1040    .cfi_restore 31
1041    addiu  $sp, $sp, 32
1042    .cfi_adjust_cfa_offset -32
1043#else
1044    lw     \rDest, \offset(\rObj)
1045    UNPOISON_HEAP_REF \rDest
1046#endif  // USE_READ_BARRIER
1047.endm
1048
1049    /*
1050     * Entry from managed code for array put operations of objects where the value being stored
1051     * needs to be checked for compatibility.
1052     * a0 = array, a1 = index, a2 = value
1053     */
1054ENTRY art_quick_aput_obj_with_null_and_bound_check
1055    bnez    $a0, .Lart_quick_aput_obj_with_bound_check_gp_set
1056    nop
1057    b .Lart_quick_throw_null_pointer_exception_gp_set
1058    nop
1059END art_quick_aput_obj_with_null_and_bound_check
1060
1061ENTRY art_quick_aput_obj_with_bound_check
1062    lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
1063    sltu $t1, $a1, $t0
1064    bnez $t1, .Lart_quick_aput_obj_gp_set
1065    nop
1066    move $a0, $a1
1067    b .Lart_quick_throw_array_bounds_gp_set
1068    move $a1, $t0
1069END art_quick_aput_obj_with_bound_check
1070
1071#ifdef USE_READ_BARRIER
1072    .extern artReadBarrierSlow
1073#endif
1074ENTRY art_quick_aput_obj
1075    beqz $a2, .Ldo_aput_null
1076    nop
1077    READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1078    READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1079    READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
1080    bne $t1, $t0, .Lcheck_assignability  # value's type == array's component type - trivial assignability
1081    nop
1082.Ldo_aput:
1083    sll $a1, $a1, 2
1084    add $t0, $a0, $a1
1085    POISON_HEAP_REF $a2
1086    sw  $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1087    lw  $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1088    srl $t1, $a0, 7
1089    add $t1, $t1, $t0
1090    sb  $t0, ($t1)
1091    jalr $zero, $ra
1092    nop
1093.Ldo_aput_null:
1094    sll $a1, $a1, 2
1095    add $t0, $a0, $a1
1096    sw  $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1097    jalr $zero, $ra
1098    nop
1099.Lcheck_assignability:
1100    addiu  $sp, $sp, -32
1101    .cfi_adjust_cfa_offset 32
1102    sw     $ra, 28($sp)
1103    .cfi_rel_offset 31, 28
1104    sw     $gp, 16($sp)
1105    sw     $t9, 12($sp)
1106    sw     $a2, 8($sp)
1107    sw     $a1, 4($sp)
1108    sw     $a0, 0($sp)
1109    move   $a1, $t1
1110    move   $a0, $t0
1111    la     $t9, artIsAssignableFromCode
1112    jalr   $t9               # (Class*, Class*)
1113    addiu  $sp, $sp, -16     # reserve argument slots on the stack
1114    addiu  $sp, $sp, 16
1115    lw     $ra, 28($sp)
1116    lw     $gp, 16($sp)
1117    lw     $t9, 12($sp)
1118    lw     $a2, 8($sp)
1119    lw     $a1, 4($sp)
1120    lw     $a0, 0($sp)
1121    addiu  $sp, 32
1122    .cfi_adjust_cfa_offset -32
1123    bnez   $v0, .Ldo_aput
1124    nop
1125    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1126    move $a1, $a2
1127    la   $t9, artThrowArrayStoreException
1128    jalr $zero, $t9                 # artThrowArrayStoreException(Class*, Class*, Thread*)
1129    move $a2, rSELF                 # pass Thread::Current
1130END art_quick_aput_obj
1131
1132    /*
1133     * Called by managed code to resolve a static field and load a boolean primitive value.
1134     */
1135    .extern artGetBooleanStaticFromCode
1136ENTRY art_quick_get_boolean_static
1137    lw     $a1, 0($sp)                   # pass referrer's Method*
1138    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1139    la     $t9, artGetBooleanStaticFromCode
1140    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1141    move   $a2, rSELF                    # pass Thread::Current
1142    RETURN_IF_NO_EXCEPTION
1143END art_quick_get_boolean_static
1144    /*
1145     * Called by managed code to resolve a static field and load a byte primitive value.
1146     */
1147    .extern artGetByteStaticFromCode
1148ENTRY art_quick_get_byte_static
1149    lw     $a1, 0($sp)                   # pass referrer's Method*
1150    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1151    la     $t9, artGetByteStaticFromCode
1152    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1153    move   $a2, rSELF                    # pass Thread::Current
1154    RETURN_IF_NO_EXCEPTION
1155END art_quick_get_byte_static
1156
1157    /*
1158     * Called by managed code to resolve a static field and load a char primitive value.
1159     */
1160    .extern artGetCharStaticFromCode
1161ENTRY art_quick_get_char_static
1162    lw     $a1, 0($sp)                   # pass referrer's Method*
1163    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1164    la     $t9, artGetCharStaticFromCode
1165    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1166    move   $a2, rSELF                    # pass Thread::Current
1167    RETURN_IF_NO_EXCEPTION
1168END art_quick_get_char_static
1169    /*
1170     * Called by managed code to resolve a static field and load a short primitive value.
1171     */
1172    .extern artGetShortStaticFromCode
1173ENTRY art_quick_get_short_static
1174    lw     $a1, 0($sp)                   # pass referrer's Method*
1175    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1176    la     $t9, artGetShortStaticFromCode
1177    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1178    move   $a2, rSELF                    # pass Thread::Current
1179    RETURN_IF_NO_EXCEPTION
1180END art_quick_get_short_static
1181
1182    /*
1183     * Called by managed code to resolve a static field and load a 32-bit primitive value.
1184     */
1185    .extern artGet32StaticFromCode
1186ENTRY art_quick_get32_static
1187    lw     $a1, 0($sp)                   # pass referrer's Method*
1188    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1189    la     $t9, artGet32StaticFromCode
1190    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1191    move   $a2, rSELF                    # pass Thread::Current
1192    RETURN_IF_NO_EXCEPTION
1193END art_quick_get32_static
1194
1195    /*
1196     * Called by managed code to resolve a static field and load a 64-bit primitive value.
1197     */
1198    .extern artGet64StaticFromCode
1199ENTRY art_quick_get64_static
1200    lw     $a1, 0($sp)                   # pass referrer's Method*
1201    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1202    la     $t9, artGet64StaticFromCode
1203    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1204    move   $a2, rSELF                    # pass Thread::Current
1205    RETURN_IF_NO_EXCEPTION
1206END art_quick_get64_static
1207
1208    /*
1209     * Called by managed code to resolve a static field and load an object reference.
1210     */
1211    .extern artGetObjStaticFromCode
1212ENTRY art_quick_get_obj_static
1213    lw     $a1, 0($sp)                   # pass referrer's Method*
1214    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1215    la     $t9, artGetObjStaticFromCode
1216    jalr   $t9                           # (uint32_t field_idx, const Method* referrer, Thread*)
1217    move   $a2, rSELF                    # pass Thread::Current
1218    RETURN_IF_NO_EXCEPTION
1219END art_quick_get_obj_static
1220
1221    /*
1222     * Called by managed code to resolve an instance field and load a boolean primitive value.
1223     */
1224    .extern artGetBooleanInstanceFromCode
1225ENTRY art_quick_get_boolean_instance
1226    lw     $a2, 0($sp)                   # pass referrer's Method*
1227    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1228    la     $t9, artGetBooleanInstanceFromCode
1229    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1230    move   $a3, rSELF                    # pass Thread::Current
1231    RETURN_IF_NO_EXCEPTION
1232END art_quick_get_boolean_instance
1233    /*
1234     * Called by managed code to resolve an instance field and load a byte primitive value.
1235     */
1236    .extern artGetByteInstanceFromCode
1237ENTRY art_quick_get_byte_instance
1238    lw     $a2, 0($sp)                   # pass referrer's Method*
1239    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1240    la     $t9, artGetByteInstanceFromCode
1241    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1242    move   $a3, rSELF                    # pass Thread::Current
1243    RETURN_IF_NO_EXCEPTION
1244END art_quick_get_byte_instance
1245
1246    /*
1247     * Called by managed code to resolve an instance field and load a char primitive value.
1248     */
1249    .extern artGetCharInstanceFromCode
1250ENTRY art_quick_get_char_instance
1251    lw     $a2, 0($sp)                   # pass referrer's Method*
1252    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1253    la     $t9, artGetCharInstanceFromCode
1254    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1255    move   $a3, rSELF                    # pass Thread::Current
1256    RETURN_IF_NO_EXCEPTION
1257END art_quick_get_char_instance
1258    /*
1259     * Called by managed code to resolve an instance field and load a short primitive value.
1260     */
1261    .extern artGetShortInstanceFromCode
1262ENTRY art_quick_get_short_instance
1263    lw     $a2, 0($sp)                   # pass referrer's Method*
1264    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1265    la     $t9, artGetShortInstanceFromCode
1266    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1267    move   $a3, rSELF                    # pass Thread::Current
1268    RETURN_IF_NO_EXCEPTION
1269END art_quick_get_short_instance
1270
1271    /*
1272     * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1273     */
1274    .extern artGet32InstanceFromCode
1275ENTRY art_quick_get32_instance
1276    lw     $a2, 0($sp)                   # pass referrer's Method*
1277    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1278    la     $t9, artGet32InstanceFromCode
1279    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1280    move   $a3, rSELF                    # pass Thread::Current
1281    RETURN_IF_NO_EXCEPTION
1282END art_quick_get32_instance
1283
1284    /*
1285     * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1286     */
1287    .extern artGet64InstanceFromCode
1288ENTRY art_quick_get64_instance
1289    lw     $a2, 0($sp)                   # pass referrer's Method*
1290    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1291    la     $t9, artGet64InstanceFromCode
1292    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1293    move   $a3, rSELF                    # pass Thread::Current
1294    RETURN_IF_NO_EXCEPTION
1295END art_quick_get64_instance
1296
1297    /*
1298     * Called by managed code to resolve an instance field and load an object reference.
1299     */
1300    .extern artGetObjInstanceFromCode
1301ENTRY art_quick_get_obj_instance
1302    lw     $a2, 0($sp)                   # pass referrer's Method*
1303    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1304    la     $t9, artGetObjInstanceFromCode
1305    jalr   $t9                           # (field_idx, Object*, referrer, Thread*)
1306    move   $a3, rSELF                    # pass Thread::Current
1307    RETURN_IF_NO_EXCEPTION
1308END art_quick_get_obj_instance
1309
1310    /*
1311     * Called by managed code to resolve a static field and store a 8-bit primitive value.
1312     */
1313    .extern artSet8StaticFromCode
1314ENTRY art_quick_set8_static
1315    lw     $a2, 0($sp)                   # pass referrer's Method*
1316    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1317    la     $t9, artSet8StaticFromCode
1318    jalr   $t9                           # (field_idx, new_val, referrer, Thread*)
1319    move   $a3, rSELF                    # pass Thread::Current
1320    RETURN_IF_ZERO
1321END art_quick_set8_static
1322
1323    /*
1324     * Called by managed code to resolve a static field and store a 16-bit primitive value.
1325     */
1326    .extern artSet16StaticFromCode
1327ENTRY art_quick_set16_static
1328    lw     $a2, 0($sp)                   # pass referrer's Method*
1329    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1330    la     $t9, artSet16StaticFromCode
1331    jalr   $t9                           # (field_idx, new_val, referrer, Thread*, $sp)
1332    move   $a3, rSELF                    # pass Thread::Current
1333    RETURN_IF_ZERO
1334END art_quick_set16_static
1335
1336    /*
1337     * Called by managed code to resolve a static field and store a 32-bit primitive value.
1338     */
1339    .extern artSet32StaticFromCode
1340ENTRY art_quick_set32_static
1341    lw     $a2, 0($sp)                   # pass referrer's Method*
1342    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1343    la     $t9, artSet32StaticFromCode
1344    jalr   $t9                           # (field_idx, new_val, referrer, Thread*)
1345    move   $a3, rSELF                    # pass Thread::Current
1346    RETURN_IF_ZERO
1347END art_quick_set32_static
1348
1349    /*
1350     * Called by managed code to resolve a static field and store a 64-bit primitive value.
1351     */
1352    .extern artSet64StaticFromCode
1353ENTRY art_quick_set64_static
1354    lw     $a1, 0($sp)                   # pass referrer's Method*
1355                                         # 64 bit new_val is in a2:a3 pair
1356    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1357    la     $t9, artSet64StaticFromCode
1358    jalr   $t9                           # (field_idx, referrer, new_val, Thread*)
1359    sw     rSELF, 16($sp)                # pass Thread::Current
1360    RETURN_IF_ZERO
1361END art_quick_set64_static
1362
1363    /*
1364     * Called by managed code to resolve a static field and store an object reference.
1365     */
1366    .extern artSetObjStaticFromCode
1367ENTRY art_quick_set_obj_static
1368    lw     $a2, 0($sp)                   # pass referrer's Method*
1369    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1370    la     $t9, artSetObjStaticFromCode
1371    jalr   $t9                           # (field_idx, new_val, referrer, Thread*)
1372    move   $a3, rSELF                    # pass Thread::Current
1373    RETURN_IF_ZERO
1374END art_quick_set_obj_static
1375
1376    /*
1377     * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1378     */
1379    .extern artSet8InstanceFromCode
1380ENTRY art_quick_set8_instance
1381    lw     $a3, 0($sp)                   # pass referrer's Method*
1382    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1383    la     $t9, artSet8InstanceFromCode
1384    jalr   $t9                           # (field_idx, Object*, new_val, referrer, Thread*)
1385    sw     rSELF, 16($sp)                # pass Thread::Current
1386    RETURN_IF_ZERO
1387END art_quick_set8_instance
1388
1389    /*
1390     * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1391     */
1392    .extern artSet16InstanceFromCode
1393ENTRY art_quick_set16_instance
1394    lw     $a3, 0($sp)                   # pass referrer's Method*
1395    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1396    la     $t9, artSet16InstanceFromCode
1397    jalr   $t9                           # (field_idx, Object*, new_val, referrer, Thread*)
1398    sw     rSELF, 16($sp)                # pass Thread::Current
1399    RETURN_IF_ZERO
1400END art_quick_set16_instance
1401
1402    /*
1403     * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1404     */
1405    .extern artSet32InstanceFromCode
1406ENTRY art_quick_set32_instance
1407    lw     $a3, 0($sp)                   # pass referrer's Method*
1408    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1409    la     $t9, artSet32InstanceFromCode
1410    jalr   $t9                           # (field_idx, Object*, new_val, referrer, Thread*)
1411    sw     rSELF, 16($sp)                # pass Thread::Current
1412    RETURN_IF_ZERO
1413END art_quick_set32_instance
1414
1415    /*
1416     * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1417     */
1418    .extern artSet64InstanceFromCode
1419ENTRY art_quick_set64_instance
1420    lw     $t1, 0($sp)                   # load referrer's Method*
1421                                         # 64 bit new_val is in a2:a3 pair
1422    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1423    sw     rSELF, 20($sp)                # pass Thread::Current
1424    la     $t9, artSet64InstanceFromCode
1425    jalr   $t9                           # (field_idx, Object*, new_val, referrer, Thread*)
1426    sw     $t1, 16($sp)                  # pass referrer's Method*
1427    RETURN_IF_ZERO
1428END art_quick_set64_instance
1429
1430    /*
1431     * Called by managed code to resolve an instance field and store an object reference.
1432     */
1433    .extern artSetObjInstanceFromCode
1434ENTRY art_quick_set_obj_instance
1435    lw     $a3, 0($sp)                   # pass referrer's Method*
1436    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1437    la     $t9, artSetObjInstanceFromCode
1438    jalr   $t9                           # (field_idx, Object*, new_val, referrer, Thread*)
1439    sw     rSELF, 16($sp)                # pass Thread::Current
1440    RETURN_IF_ZERO
1441END art_quick_set_obj_instance
1442
1443// Macro to facilitate adding new allocation entrypoints.
1444.macro ONE_ARG_DOWNCALL name, entrypoint, return
1445    .extern \entrypoint
1446ENTRY \name
1447    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1448    la      $t9, \entrypoint
1449    jalr    $t9
1450    move    $a1, rSELF                # pass Thread::Current
1451    \return
1452END \name
1453.endm
1454
1455.macro TWO_ARG_DOWNCALL name, entrypoint, return
1456    .extern \entrypoint
1457ENTRY \name
1458    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1459    la      $t9, \entrypoint
1460    jalr    $t9
1461    move    $a2, rSELF                # pass Thread::Current
1462    \return
1463END \name
1464.endm
1465
1466.macro THREE_ARG_DOWNCALL name, entrypoint, return
1467    .extern \entrypoint
1468ENTRY \name
1469    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1470    la      $t9, \entrypoint
1471    jalr    $t9
1472    move    $a3, rSELF                # pass Thread::Current
1473    \return
1474END \name
1475.endm
1476
1477.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1478    .extern \entrypoint
1479ENTRY \name
1480    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1481    la      $t9, \entrypoint
1482    jalr    $t9
1483    sw      rSELF, 16($sp)            # pass Thread::Current
1484    \return
1485END \name
1486.endm
1487
1488// Generate the allocation entrypoints for each allocator.
1489GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
1490
1491// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1492ENTRY art_quick_alloc_object_rosalloc
1493
1494    # Fast path rosalloc allocation
1495    # a0: type_idx
1496    # a1: ArtMethod*
1497    # s1: Thread::Current
1498    # -----------------------------
1499    # t0: class
1500    # t1: object size
1501    # t2: rosalloc run
1502    # t3: thread stack top offset
1503    # t4: thread stack bottom offset
1504    # v0: free list head
1505    #
1506    # t5, t6 : temps
1507
1508    lw    $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_32($a1)       # Load dex cache resolved types
1509                                                               # array.
1510
1511    sll   $t5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT            # Shift the value.
1512    addu  $t5, $t0, $t5                                        # Compute the index.
1513    lw    $t0, 0($t5)                                          # Load class (t0).
1514    beqz  $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1515
1516    li    $t6, MIRROR_CLASS_STATUS_INITIALIZED
1517    lw    $t5, MIRROR_CLASS_STATUS_OFFSET($t0)                 # Check class status.
1518    bne   $t5, $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1519
1520    # Add a fake dependence from the following access flag and size loads to the status load. This
1521    # is to prevent those loads from being reordered above the status load and reading wrong values.
1522    xor   $t5, $t5, $t5
1523    addu  $t0, $t0, $t5
1524
1525    lw    $t5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0)           # Check if access flags has
1526    li    $t6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE               # kAccClassIsFinalizable.
1527    and   $t6, $t5, $t6
1528    bnez  $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1529
1530    lw    $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)        # Check if thread local allocation
1531    lw    $t4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1)        # stack has any room left.
1532    bgeu  $t3, $t4, .Lart_quick_alloc_object_rosalloc_slow_path
1533
1534    lw    $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0)            # Load object size (t1).
1535    li    $t5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE          # Check if size is for a thread local
1536                                                               # allocation.
1537    bgtu  $t1, $t5, .Lart_quick_alloc_object_rosalloc_slow_path
1538
1539    # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1540    # quantum size and divide by the quantum size and subtract by 1.
1541
1542    addiu $t1, $t1, -1                                         # Decrease obj size and shift right
1543    srl   $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT        # by quantum.
1544
1545    sll   $t2, $t1, POINTER_SIZE_SHIFT
1546    addu  $t2, $t2, $s1
1547    lw    $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2)                # Load rosalloc run (t2).
1548
1549    # Load the free list head (v0).
1550    # NOTE: this will be the return val.
1551
1552    lw    $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1553    beqz  $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1554    nop
1555
1556    # Load the next pointer of the head and update the list head with the next pointer.
1557
1558    lw    $t5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1559    sw    $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1560
1561    # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1562    # asserted to match.
1563
1564#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1565#error "Class pointer needs to overwrite next pointer."
1566#endif
1567
1568    POISON_HEAP_REF $t0
1569    sw    $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1570
1571    # Push the new object onto the thread local allocation stack and increment the thread local
1572    # allocation stack top.
1573
1574    sw    $v0, 0($t3)
1575    addiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1576    sw    $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1577
1578    # Decrement the size of the free list.
1579
1580    lw    $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1581    addiu $t5, $t5, -1
1582    sw    $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1583
1584    sync                                                          # Fence.
1585
1586    jalr  $zero, $ra
1587    nop
1588
1589  .Lart_quick_alloc_object_rosalloc_slow_path:
1590
1591    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1592    la    $t9, artAllocObjectFromCodeRosAlloc
1593    jalr  $t9
1594    move  $a2, $s1                                                # Pass self as argument.
1595    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1596
1597END art_quick_alloc_object_rosalloc
1598
1599GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1600GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1601
1602    /*
1603     * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1604     * exception on error. On success the String is returned. A0 holds the string index. The fast
1605     * path check for hit in strings cache has already been performed.
1606     */
1607ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1608
1609    /*
1610     * Entry from managed code when uninitialized static storage, this stub will run the class
1611     * initializer and deliver the exception on error. On success the static storage base is
1612     * returned.
1613     */
1614ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1615
1616    /*
1617     * Entry from managed code when dex cache misses for a type_idx.
1618     */
1619ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1620
1621    /*
1622     * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1623     * miss.
1624     */
1625ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1626
1627    /*
1628     * Called by managed code when the value in rSUSPEND has been decremented to 0.
1629     */
1630    .extern artTestSuspendFromCode
1631ENTRY art_quick_test_suspend
1632    lh     $a0, THREAD_FLAGS_OFFSET(rSELF)
1633    bnez   $a0, 1f
1634    addiu  rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL   # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1635    jalr   $zero, $ra
1636    nop
16371:
1638    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME          # save callee saves for stack crawl
1639    la     $t9, artTestSuspendFromCode
1640    jalr   $t9                                 # (Thread*)
1641    move   $a0, rSELF
1642    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
1643END art_quick_test_suspend
1644
1645    /*
1646     * Called by managed code that is attempting to call a method on a proxy class. On entry
1647     * a0 holds the proxy method; a1, a2 and a3 may contain arguments.
1648     */
1649    .extern artQuickProxyInvokeHandler
1650ENTRY art_quick_proxy_invoke_handler
1651    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1652    move    $a2, rSELF                  # pass Thread::Current
1653    la      $t9, artQuickProxyInvokeHandler
1654    jalr    $t9                         # (Method* proxy method, receiver, Thread*, SP)
1655    addiu   $a3, $sp, ARG_SLOT_SIZE     # pass $sp (remove arg slots)
1656    lw      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1657    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1658    bnez    $t0, 1f
1659    # don't care if $v0 and/or $v1 are modified, when exception branch taken
1660    MTD     $v0, $v1, $f0, $f1          # move float value to return value
1661    jalr    $zero, $ra
1662    nop
16631:
1664    DELIVER_PENDING_EXCEPTION
1665END art_quick_proxy_invoke_handler
1666
1667    /*
1668     * Called to resolve an imt conflict.
1669     * a0 is the conflict ArtMethod.
1670     * t0 is a hidden argument that holds the target interface method's dex method index.
1671     *
1672     * Note that this stub writes to a0, t0 and t1.
1673     */
1674ENTRY art_quick_imt_conflict_trampoline
1675    lw      $t1, 0($sp)                                      # Load referrer.
1676    lw      $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_32($t1) # Load dex cache methods array.
1677    sll     $t0, $t0, POINTER_SIZE_SHIFT                     # Calculate offset.
1678    addu    $t0, $t1, $t0                                    # Add offset to base.
1679    lw      $t0, 0($t0)                                      # Load interface method.
1680    lw      $a0, ART_METHOD_JNI_OFFSET_32($a0)               # Load ImtConflictTable.
1681
1682.Limt_table_iterate:
1683    lw      $t1, 0($a0)                                      # Load next entry in ImtConflictTable.
1684    # Branch if found.
1685    beq     $t1, $t0, .Limt_table_found
1686    nop
1687    # If the entry is null, the interface method is not in the ImtConflictTable.
1688    beqz    $t1, .Lconflict_trampoline
1689    nop
1690    # Iterate over the entries of the ImtConflictTable.
1691    b       .Limt_table_iterate
1692    addiu   $a0, $a0, 2 * __SIZEOF_POINTER__                 # Iterate to the next entry.
1693
1694.Limt_table_found:
1695    # We successfully hit an entry in the table. Load the target method and jump to it.
1696    lw      $a0, __SIZEOF_POINTER__($a0)
1697    lw      $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)
1698    jr      $t9
1699    nop
1700
1701.Lconflict_trampoline:
1702    # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
1703    INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
1704END art_quick_imt_conflict_trampoline
1705
1706    .extern artQuickResolutionTrampoline
1707ENTRY art_quick_resolution_trampoline
1708    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1709    move    $a2, rSELF                    # pass Thread::Current
1710    la      $t9, artQuickResolutionTrampoline
1711    jalr    $t9                           # (Method* called, receiver, Thread*, SP)
1712    addiu   $a3, $sp, ARG_SLOT_SIZE       # pass $sp (remove arg slots)
1713    beqz    $v0, 1f
1714    lw      $a0, ARG_SLOT_SIZE($sp)       # load resolved method to $a0
1715    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1716    move    $t9, $v0               # code pointer must be in $t9 to generate the global pointer
1717    jalr    $zero, $t9             # tail call to method
1718    nop
17191:
1720    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1721    DELIVER_PENDING_EXCEPTION
1722END art_quick_resolution_trampoline
1723
1724    .extern artQuickGenericJniTrampoline
1725    .extern artQuickGenericJniEndTrampoline
1726ENTRY art_quick_generic_jni_trampoline
1727    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1728    move    $s8, $sp               # save $sp to $s8
1729    move    $s3, $gp               # save $gp to $s3
1730
1731    # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1732    move    $a0, rSELF                     # pass Thread::Current
1733    addiu   $a1, $sp, ARG_SLOT_SIZE        # save $sp (remove arg slots)
1734    la      $t9, artQuickGenericJniTrampoline
1735    jalr    $t9                            # (Thread*, SP)
1736    addiu   $sp, $sp, -5120                # reserve space on the stack
1737
1738    # The C call will have registered the complete save-frame on success.
1739    # The result of the call is:
1740    # v0: ptr to native code, 0 on error.
1741    # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1742    beq     $v0, $zero, 1f         # check entry error
1743    move    $t9, $v0               # save the code ptr
1744    move    $sp, $v1               # release part of the alloca
1745
1746    # Load parameters from stack into registers
1747    lw      $a0,   0($sp)
1748    lw      $a1,   4($sp)
1749    lw      $a2,   8($sp)
1750
1751    # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1752    jalr    $t9                    # native call
1753    lw      $a3,  12($sp)
1754    addiu   $sp, $sp, 16           # remove arg slots
1755
1756    move    $gp, $s3               # restore $gp from $s3
1757
1758    # result sign extension is handled in C code
1759    # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1760    move    $a0, rSELF             # pass Thread::Current
1761    move    $a2, $v0               # pass result
1762    move    $a3, $v1
1763    addiu   $sp, $sp, -24          # reserve arg slots
1764    la      $t9, artQuickGenericJniEndTrampoline
1765    jalr    $t9
1766    s.d     $f0, 16($sp)           # pass result_f
1767
1768    lw      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1769    bne     $t0, $zero, 1f         # check for pending exceptions
1770
1771    move    $sp, $s8               # tear down the alloca
1772
1773    # tear dpown the callee-save frame
1774    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1775
1776    MTD     $v0, $v1, $f0, $f1     # move float value to return value
1777    jalr    $zero, $ra
1778    nop
1779
17801:
1781    lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
1782    # This will create a new save-all frame, required by the runtime.
1783    DELIVER_PENDING_EXCEPTION
1784END art_quick_generic_jni_trampoline
1785
1786    .extern artQuickToInterpreterBridge
1787ENTRY art_quick_to_interpreter_bridge
1788    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1789    move    $a1, rSELF                          # pass Thread::Current
1790    la      $t9, artQuickToInterpreterBridge
1791    jalr    $t9                                 # (Method* method, Thread*, SP)
1792    addiu   $a2, $sp, ARG_SLOT_SIZE             # pass $sp (remove arg slots)
1793    lw      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1794    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1795    bnez    $t0, 1f
1796    # don't care if $v0 and/or $v1 are modified, when exception branch taken
1797    MTD     $v0, $v1, $f0, $f1                  # move float value to return value
1798    jalr    $zero, $ra
1799    nop
18001:
1801    DELIVER_PENDING_EXCEPTION
1802END art_quick_to_interpreter_bridge
1803
1804    /*
1805     * Routine that intercepts method calls and returns.
1806     */
1807    .extern artInstrumentationMethodEntryFromCode
1808    .extern artInstrumentationMethodExitFromCode
1809ENTRY art_quick_instrumentation_entry
1810    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1811    sw       $a0, 28($sp)   # save arg0 in free arg slot
1812    move     $a3, $ra       # pass $ra
1813    la       $t9, artInstrumentationMethodEntryFromCode
1814    jalr     $t9            # (Method*, Object*, Thread*, LR)
1815    move     $a2, rSELF     # pass Thread::Current
1816    move     $t9, $v0       # $t9 holds reference to code
1817    lw       $a0, 28($sp)   # restore arg0 from free arg slot
1818    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1819    jalr     $t9            # call method
1820    nop
1821END art_quick_instrumentation_entry
1822    /* intentional fallthrough */
1823    .global art_quick_instrumentation_exit
1824art_quick_instrumentation_exit:
1825    .cfi_startproc
1826    addiu    $t9, $ra, 4    # put current address into $t9 to rebuild $gp
1827    .cpload  $t9
1828    move     $ra, $zero     # link register is to here, so clobber with 0 for later checks
1829
1830    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1831    addiu    $sp, $sp, -16  # allocate temp storage on the stack
1832    .cfi_adjust_cfa_offset 16
1833    sw       $v0, ARG_SLOT_SIZE+12($sp)
1834    .cfi_rel_offset 2, ARG_SLOT_SIZE+12
1835    sw       $v1, ARG_SLOT_SIZE+8($sp)
1836    .cfi_rel_offset 3, ARG_SLOT_SIZE+8
1837    s.d      $f0, ARG_SLOT_SIZE($sp)
1838    s.d      $f0, 16($sp)   # pass fpr result
1839    move     $a2, $v0       # pass gpr result
1840    move     $a3, $v1
1841    addiu    $a1, $sp, ARG_SLOT_SIZE+16   # pass $sp (remove arg slots and temp storage)
1842    la       $t9, artInstrumentationMethodExitFromCode
1843    jalr     $t9            # (Thread*, SP, gpr_res, fpr_res)
1844    move     $a0, rSELF     # pass Thread::Current
1845    move     $t9, $v0       # set aside returned link register
1846    move     $ra, $v1       # set link register for deoptimization
1847    lw       $v0, ARG_SLOT_SIZE+12($sp)   # restore return values
1848    lw       $v1, ARG_SLOT_SIZE+8($sp)
1849    l.d      $f0, ARG_SLOT_SIZE($sp)
1850    jalr     $zero, $t9     # return
1851    addiu    $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16  # restore stack
1852    .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16)
1853END art_quick_instrumentation_exit
1854
1855    /*
1856     * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1857     * will long jump to the upcall with a special exception of -1.
1858     */
1859    .extern artDeoptimize
1860ENTRY art_quick_deoptimize
1861    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1862    la       $t9, artDeoptimize
1863    jalr     $t9            # artDeoptimize(Thread*)
1864                            # Returns caller method's frame size.
1865    move     $a0, rSELF     # pass Thread::current
1866END art_quick_deoptimize
1867
1868    /*
1869     * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
1870     * will long jump to the upcall with a special exception of -1.
1871     */
1872    .extern artDeoptimizeFromCompiledCode
1873ENTRY art_quick_deoptimize_from_compiled_code
1874    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1875    la       $t9, artDeoptimizeFromCompiledCode
1876    jalr     $t9                            # artDeoptimizeFromCompiledCode(Thread*)
1877                                            # Returns caller method's frame size.
1878    move     $a0, rSELF                     # pass Thread::current
1879END art_quick_deoptimize_from_compiled_code
1880
1881    /*
1882     * Long integer shift.  This is different from the generic 32/64-bit
1883     * binary operations because vAA/vBB are 64-bit but vCC (the shift
1884     * distance) is 32-bit.  Also, Dalvik requires us to ignore all but the low
1885     * 6 bits.
1886     * On entry:
1887     *   $a0: low word
1888     *   $a1: high word
1889     *   $a2: shift count
1890     */
1891ENTRY_NO_GP art_quick_shl_long
1892    /* shl-long vAA, vBB, vCC */
1893    sll     $v0, $a0, $a2                    #  rlo<- alo << (shift&31)
1894    not     $v1, $a2                         #  rhi<- 31-shift  (shift is 5b)
1895    srl     $a0, 1
1896    srl     $a0, $v1                         #  alo<- alo >> (32-(shift&31))
1897    sll     $v1, $a1, $a2                    #  rhi<- ahi << (shift&31)
1898    andi    $a2, 0x20                        #  shift< shift & 0x20
1899    beqz    $a2, 1f
1900    or      $v1, $a0                         #  rhi<- rhi | alo
1901
1902    move    $v1, $v0                         #  rhi<- rlo (if shift&0x20)
1903    move    $v0, $zero                       #  rlo<- 0 (if shift&0x20)
1904
19051:  jalr    $zero, $ra
1906    nop
1907END art_quick_shl_long
1908
1909    /*
1910     * Long integer shift.  This is different from the generic 32/64-bit
1911     * binary operations because vAA/vBB are 64-bit but vCC (the shift
1912     * distance) is 32-bit.  Also, Dalvik requires us to ignore all but the low
1913     * 6 bits.
1914     * On entry:
1915     *   $a0: low word
1916     *   $a1: high word
1917     *   $a2: shift count
1918     */
1919ENTRY_NO_GP art_quick_shr_long
1920    sra     $v1, $a1, $a2                    #  rhi<- ahi >> (shift&31)
1921    srl     $v0, $a0, $a2                    #  rlo<- alo >> (shift&31)
1922    sra     $a3, $a1, 31                     #  $a3<- sign(ah)
1923    not     $a0, $a2                         #  alo<- 31-shift (shift is 5b)
1924    sll     $a1, 1
1925    sll     $a1, $a0                         #  ahi<- ahi << (32-(shift&31))
1926    andi    $a2, 0x20                        #  shift & 0x20
1927    beqz    $a2, 1f
1928    or      $v0, $a1                         #  rlo<- rlo | ahi
1929
1930    move    $v0, $v1                         #  rlo<- rhi (if shift&0x20)
1931    move    $v1, $a3                         #  rhi<- sign(ahi) (if shift&0x20)
1932
19331:  jalr    $zero, $ra
1934    nop
1935END art_quick_shr_long
1936
1937    /*
1938     * Long integer shift.  This is different from the generic 32/64-bit
1939     * binary operations because vAA/vBB are 64-bit but vCC (the shift
1940     * distance) is 32-bit.  Also, Dalvik requires us to ignore all but the low
1941     * 6 bits.
1942     * On entry:
1943     *   $a0: low word
1944     *   $a1: high word
1945     *   $a2: shift count
1946     */
1947    /* ushr-long vAA, vBB, vCC */
1948ENTRY_NO_GP art_quick_ushr_long
1949    srl     $v1, $a1, $a2                    #  rhi<- ahi >> (shift&31)
1950    srl     $v0, $a0, $a2                    #  rlo<- alo >> (shift&31)
1951    not     $a0, $a2                         #  alo<- 31-shift (shift is 5b)
1952    sll     $a1, 1
1953    sll     $a1, $a0                         #  ahi<- ahi << (32-(shift&31))
1954    andi    $a2, 0x20                        #  shift & 0x20
1955    beqz    $a2, 1f
1956    or      $v0, $a1                         #  rlo<- rlo | ahi
1957
1958    move    $v0, $v1                         #  rlo<- rhi (if shift&0x20)
1959    move    $v1, $zero                       #  rhi<- 0 (if shift&0x20)
1960
19611:  jalr    $zero, $ra
1962    nop
1963END art_quick_ushr_long
1964
1965/* java.lang.String.indexOf(int ch, int fromIndex=0) */
1966ENTRY_NO_GP art_quick_indexof
1967/* $a0 holds address of "this" */
1968/* $a1 holds "ch" */
1969/* $a2 holds "fromIndex" */
1970  lw    $t0, MIRROR_STRING_COUNT_OFFSET($a0)    # this.length()
1971  slt   $t1, $a2, $zero # if fromIndex < 0
1972#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
1973  seleqz $a2, $a2, $t1  #     fromIndex = 0;
1974#else
1975  movn   $a2, $zero, $t1 #    fromIndex = 0;
1976#endif
1977  subu  $t0, $t0, $a2   # this.length() - fromIndex
1978  blez  $t0, 6f         # if this.length()-fromIndex <= 0
1979  li    $v0, -1         #     return -1;
1980
1981  sll   $v0, $a2, 1     # $a0 += $a2 * 2
1982  addu  $a0, $a0, $v0   #  "  "   "  " "
1983  move  $v0, $a2        # Set i to fromIndex.
1984
19851:
1986  lhu   $t3, MIRROR_STRING_VALUE_OFFSET($a0)    # if this.charAt(i) == ch
1987  beq   $t3, $a1, 6f                            #     return i;
1988  addu  $a0, $a0, 2     # i++
1989  subu  $t0, $t0, 1     # this.length() - i
1990  bnez  $t0, 1b         # while this.length() - i > 0
1991  addu  $v0, $v0, 1     # i++
1992
1993  li    $v0, -1         # if this.length() - i <= 0
1994                        #     return -1;
1995
19966:
1997  j     $ra
1998  nop
1999END art_quick_indexof
2000
2001/* java.lang.String.compareTo(String anotherString) */
2002ENTRY_NO_GP art_quick_string_compareto
2003/* $a0 holds address of "this" */
2004/* $a1 holds address of "anotherString" */
2005  beq    $a0, $a1, 9f   # this and anotherString are the same object
2006  move   $v0, $zero
2007
2008  lw     $a2, MIRROR_STRING_COUNT_OFFSET($a0)   # this.length()
2009  lw     $a3, MIRROR_STRING_COUNT_OFFSET($a1)   # anotherString.length()
2010  MINu   $t2, $a2, $a3
2011# $t2 now holds min(this.length(),anotherString.length())
2012
2013  beqz   $t2, 9f        # while min(this.length(),anotherString.length())-i != 0
2014  subu   $v0, $a2, $a3  # if $t2==0 return
2015                        #     (this.length() - anotherString.length())
20161:
2017  lhu    $t0, MIRROR_STRING_VALUE_OFFSET($a0)   # while this.charAt(i) == anotherString.charAt(i)
2018  lhu    $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2019  bne    $t0, $t1, 9f   # if this.charAt(i) != anotherString.charAt(i)
2020  subu   $v0, $t0, $t1  #     return (this.charAt(i) - anotherString.charAt(i))
2021  addiu  $a0, $a0, 2    # point at this.charAt(i++)
2022  subu   $t2, $t2, 1    # new value of
2023                        # min(this.length(),anotherString.length())-i
2024  bnez   $t2, 1b
2025  addiu  $a1, $a1, 2    # point at anotherString.charAt(i++)
2026  subu   $v0, $a2, $a3
2027
20289:
2029  j      $ra
2030  nop
2031END art_quick_string_compareto
2032