quick_entrypoints_arm64.S revision e401d146407d61eeb99f8d6176b2ac13c4df1e33
1/* 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_arm64.S" 18 19#include "arch/quick_alloc_entrypoints.S" 20 21 22 /* 23 * Macro that sets up the callee save frame to conform with 24 * Runtime::CreateCalleeSaveMethod(kSaveAll) 25 */ 26.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 27 adrp xIP0, :got:_ZN3art7Runtime9instance_E 28 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 29 30 // Our registers aren't intermixed - just spill in order. 31 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 32 33 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . 34 THIS_LOAD_REQUIRES_READ_BARRIER 35 36 // Loads appropriate callee-save-method. 37 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ] 38 39 sub sp, sp, #176 40 .cfi_adjust_cfa_offset 176 41 42 // Ugly compile-time check, but we only have the preprocessor. 43#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176) 44#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected." 45#endif 46 47 // Stack alignment filler [sp, #8]. 48 // FP callee-saves. 49 stp d8, d9, [sp, #16] 50 stp d10, d11, [sp, #32] 51 stp d12, d13, [sp, #48] 52 stp d14, d15, [sp, #64] 53 54 // GP callee-saves 55 stp x19, x20, [sp, #80] 56 .cfi_rel_offset x19, 80 57 .cfi_rel_offset x20, 88 58 59 stp x21, x22, [sp, #96] 60 .cfi_rel_offset x21, 96 61 .cfi_rel_offset x22, 104 62 63 stp x23, x24, [sp, #112] 64 .cfi_rel_offset x23, 112 65 .cfi_rel_offset x24, 120 66 67 stp x25, x26, [sp, #128] 68 .cfi_rel_offset x25, 128 69 .cfi_rel_offset x26, 136 70 71 stp x27, x28, [sp, #144] 72 .cfi_rel_offset x27, 144 73 .cfi_rel_offset x28, 152 74 75 stp x29, xLR, [sp, #160] 76 .cfi_rel_offset x29, 160 77 .cfi_rel_offset x30, 168 78 79 // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]. 80 str xIP0, [sp] 81 // Place sp in Thread::Current()->top_quick_frame. 82 mov xIP0, sp 83 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 84.endm 85 86 /* 87 * Macro that sets up the callee save frame to conform with 88 * Runtime::CreateCalleeSaveMethod(kRefsOnly). 89 */ 90.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 91 adrp xIP0, :got:_ZN3art7Runtime9instance_E 92 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 93 94 // Our registers aren't intermixed - just spill in order. 95 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 96 97 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefOnly] . 98 THIS_LOAD_REQUIRES_READ_BARRIER 99 100 // Loads appropriate callee-save-method. 101 ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ] 102 103 sub sp, sp, #96 104 .cfi_adjust_cfa_offset 96 105 106 // Ugly compile-time check, but we only have the preprocessor. 107#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96) 108#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected." 109#endif 110 111 // GP callee-saves. 112 // x20 paired with ArtMethod* - see below. 113 stp x21, x22, [sp, #16] 114 .cfi_rel_offset x21, 16 115 .cfi_rel_offset x22, 24 116 117 stp x23, x24, [sp, #32] 118 .cfi_rel_offset x23, 32 119 .cfi_rel_offset x24, 40 120 121 stp x25, x26, [sp, #48] 122 .cfi_rel_offset x25, 48 123 .cfi_rel_offset x26, 56 124 125 stp x27, x28, [sp, #64] 126 .cfi_rel_offset x27, 64 127 .cfi_rel_offset x28, 72 128 129 stp x29, xLR, [sp, #80] 130 .cfi_rel_offset x29, 80 131 .cfi_rel_offset x30, 88 132 133 // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly]. 134 stp xIP0, x20, [sp] 135 .cfi_rel_offset x20, 8 136 137 // Place sp in Thread::Current()->top_quick_frame. 138 mov xIP0, sp 139 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 140.endm 141 142// TODO: Probably no need to restore registers preserved by aapcs64. 143.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 144 // Callee-saves. 145 ldr x20, [sp, #8] 146 .cfi_restore x20 147 148 ldp x21, x22, [sp, #16] 149 .cfi_restore x21 150 .cfi_restore x22 151 152 ldp x23, x24, [sp, #32] 153 .cfi_restore x23 154 .cfi_restore x24 155 156 ldp x25, x26, [sp, #48] 157 .cfi_restore x25 158 .cfi_restore x26 159 160 ldp x27, x28, [sp, #64] 161 .cfi_restore x27 162 .cfi_restore x28 163 164 ldp x29, xLR, [sp, #80] 165 .cfi_restore x29 166 .cfi_restore x30 167 168 add sp, sp, #96 169 .cfi_adjust_cfa_offset -96 170.endm 171 172.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME 173 add sp, sp, #96 174 .cfi_adjust_cfa_offset - 96 175.endm 176 177.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 178 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 179 ret 180.endm 181 182 183.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 184 sub sp, sp, #224 185 .cfi_adjust_cfa_offset 224 186 187 // Ugly compile-time check, but we only have the preprocessor. 188#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224) 189#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected." 190#endif 191 192 // Stack alignment filler [sp, #8]. 193 // FP args. 194 stp d0, d1, [sp, #16] 195 stp d2, d3, [sp, #32] 196 stp d4, d5, [sp, #48] 197 stp d6, d7, [sp, #64] 198 199 // Core args. 200 stp x1, x2, [sp, #80] 201 .cfi_rel_offset x1, 80 202 .cfi_rel_offset x2, 88 203 204 stp x3, x4, [sp, #96] 205 .cfi_rel_offset x3, 96 206 .cfi_rel_offset x4, 104 207 208 stp x5, x6, [sp, #112] 209 .cfi_rel_offset x5, 112 210 .cfi_rel_offset x6, 120 211 212 // x7, Callee-saves. 213 stp x7, x20, [sp, #128] 214 .cfi_rel_offset x7, 128 215 .cfi_rel_offset x20, 136 216 217 stp x21, x22, [sp, #144] 218 .cfi_rel_offset x21, 144 219 .cfi_rel_offset x22, 152 220 221 stp x23, x24, [sp, #160] 222 .cfi_rel_offset x23, 160 223 .cfi_rel_offset x24, 168 224 225 stp x25, x26, [sp, #176] 226 .cfi_rel_offset x25, 176 227 .cfi_rel_offset x26, 184 228 229 stp x27, x28, [sp, #192] 230 .cfi_rel_offset x27, 192 231 .cfi_rel_offset x28, 200 232 233 // x29(callee-save) and LR. 234 stp x29, xLR, [sp, #208] 235 .cfi_rel_offset x29, 208 236 .cfi_rel_offset x30, 216 237 238.endm 239 240 /* 241 * Macro that sets up the callee save frame to conform with 242 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). 243 * 244 * TODO This is probably too conservative - saving FP & LR. 245 */ 246.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 247 adrp xIP0, :got:_ZN3art7Runtime9instance_E 248 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 249 250 // Our registers aren't intermixed - just spill in order. 251 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 252 253 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . 254 THIS_LOAD_REQUIRES_READ_BARRIER 255 ldr xIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ] 256 257 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 258 259 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] 260 // Place sp in Thread::Current()->top_quick_frame. 261 mov xIP0, sp 262 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 263.endm 264 265.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 266 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 267 str x0, [sp, #0] // Store ArtMethod* to bottom of stack. 268 // Place sp in Thread::Current()->top_quick_frame. 269 mov xIP0, sp 270 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 271.endm 272 273// TODO: Probably no need to restore registers preserved by aapcs64. 274.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 275 // FP args. 276 ldp d0, d1, [sp, #16] 277 ldp d2, d3, [sp, #32] 278 ldp d4, d5, [sp, #48] 279 ldp d6, d7, [sp, #64] 280 281 // Core args. 282 ldp x1, x2, [sp, #80] 283 .cfi_restore x1 284 .cfi_restore x2 285 286 ldp x3, x4, [sp, #96] 287 .cfi_restore x3 288 .cfi_restore x4 289 290 ldp x5, x6, [sp, #112] 291 .cfi_restore x5 292 .cfi_restore x6 293 294 // x7, Callee-saves. 295 ldp x7, x20, [sp, #128] 296 .cfi_restore x7 297 .cfi_restore x20 298 299 ldp x21, x22, [sp, #144] 300 .cfi_restore x21 301 .cfi_restore x22 302 303 ldp x23, x24, [sp, #160] 304 .cfi_restore x23 305 .cfi_restore x24 306 307 ldp x25, x26, [sp, #176] 308 .cfi_restore x25 309 .cfi_restore x26 310 311 ldp x27, x28, [sp, #192] 312 .cfi_restore x27 313 .cfi_restore x28 314 315 // x29(callee-save) and LR. 316 ldp x29, xLR, [sp, #208] 317 .cfi_restore x29 318 .cfi_restore x30 319 320 add sp, sp, #224 321 .cfi_adjust_cfa_offset -224 322.endm 323 324.macro RETURN_IF_RESULT_IS_ZERO 325 cbnz x0, 1f // result non-zero branch over 326 ret // return 3271: 328.endm 329 330.macro RETURN_IF_RESULT_IS_NON_ZERO 331 cbz x0, 1f // result zero branch over 332 ret // return 3331: 334.endm 335 336 /* 337 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending 338 * exception is Thread::Current()->exception_ 339 */ 340.macro DELIVER_PENDING_EXCEPTION 341 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 342 mov x0, xSELF 343 344 // Point of no return. 345 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*) 346 brk 0 // Unreached 347.endm 348 349.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg 350 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field. 351 cbnz \reg, 1f 352 ret 3531: 354 DELIVER_PENDING_EXCEPTION 355.endm 356 357.macro RETURN_OR_DELIVER_PENDING_EXCEPTION 358 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0 359.endm 360 361// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register. 362.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 363 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1 364.endm 365 366.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER 367 cbnz w0, 1f // result non-zero branch over 368 ret // return 3691: 370 DELIVER_PENDING_EXCEPTION 371.endm 372 373.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 374 .extern \cxx_name 375ENTRY \c_name 376 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 377 mov x0, xSELF // pass Thread::Current 378 b \cxx_name // \cxx_name(Thread*) 379END \c_name 380.endm 381 382.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name 383 .extern \cxx_name 384ENTRY \c_name 385 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context. 386 mov x1, xSELF // pass Thread::Current. 387 b \cxx_name // \cxx_name(arg, Thread*). 388 brk 0 389END \c_name 390.endm 391 392.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 393 .extern \cxx_name 394ENTRY \c_name 395 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 396 mov x2, xSELF // pass Thread::Current 397 b \cxx_name // \cxx_name(arg1, arg2, Thread*) 398 brk 0 399END \c_name 400.endm 401 402 /* 403 * Called by managed code, saves callee saves and then calls artThrowException 404 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. 405 */ 406ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode 407 408 /* 409 * Called by managed code to create and deliver a NullPointerException. 410 */ 411NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode 412 413 /* 414 * Called by managed code to create and deliver an ArithmeticException. 415 */ 416NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode 417 418 /* 419 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds 420 * index, arg2 holds limit. 421 */ 422TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode 423 424 /* 425 * Called by managed code to create and deliver a StackOverflowError. 426 */ 427NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode 428 429 /* 430 * Called by managed code to create and deliver a NoSuchMethodError. 431 */ 432ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode 433 434 /* 435 * All generated callsites for interface invokes and invocation slow paths will load arguments 436 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain 437 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper. 438 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1. 439 * 440 * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting 441 * of the target Method* in x0 and method->code_ in x1. 442 * 443 * If unsuccessful, the helper will return null/????. There will be a pending exception in the 444 * thread and we branch to another stub to deliver it. 445 * 446 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr 447 * pointing back to the original caller. 448 * 449 * Adapted from ARM32 code. 450 * 451 * Clobbers xIP0. 452 */ 453.macro INVOKE_TRAMPOLINE c_name, cxx_name 454 .extern \cxx_name 455ENTRY \c_name 456 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC 457 // Helper signature is always 458 // (method_idx, *this_object, *caller_method, *self, sp) 459 460 mov x2, xSELF // pass Thread::Current 461 mov x3, sp 462 bl \cxx_name // (method_idx, this, Thread*, SP) 463 mov xIP0, x1 // save Method*->code_ 464 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 465 cbz x0, 1f // did we find the target? if not go to exception delivery 466 br xIP0 // tail call to target 4671: 468 DELIVER_PENDING_EXCEPTION 469END \c_name 470.endm 471 472INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline 473INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck 474 475INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck 476INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck 477INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck 478INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck 479 480 481.macro INVOKE_STUB_CREATE_FRAME 482 483SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved. 484SAVE_SIZE_AND_METHOD=SAVE_SIZE+8 485 486 487 mov x9, sp // Save stack pointer. 488 .cfi_register sp,x9 489 490 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame. 491 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args 492 and x10, x10, # ~0xf // Enforce 16 byte stack alignment. 493 mov sp, x10 // Set new SP. 494 495 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP 496 .cfi_def_cfa_register x10 // before this. 497 .cfi_adjust_cfa_offset SAVE_SIZE 498 499 str x28, [x10, #112] 500 .cfi_rel_offset x28, 112 501 502 stp x26, x27, [x10, #96] 503 .cfi_rel_offset x26, 96 504 .cfi_rel_offset x27, 104 505 506 stp x24, x25, [x10, #80] 507 .cfi_rel_offset x24, 80 508 .cfi_rel_offset x25, 88 509 510 stp x22, x23, [x10, #64] 511 .cfi_rel_offset x22, 64 512 .cfi_rel_offset x23, 72 513 514 stp x20, x21, [x10, #48] 515 .cfi_rel_offset x20, 48 516 .cfi_rel_offset x21, 56 517 518 stp x9, x19, [x10, #32] // Save old stack pointer and x19. 519 .cfi_rel_offset sp, 32 520 .cfi_rel_offset x19, 40 521 522 stp x4, x5, [x10, #16] // Save result and shorty addresses. 523 .cfi_rel_offset x4, 16 524 .cfi_rel_offset x5, 24 525 526 stp xFP, xLR, [x10] // Store LR & FP. 527 .cfi_rel_offset x29, 0 528 .cfi_rel_offset x30, 8 529 530 mov xFP, x10 // Use xFP now, as it's callee-saved. 531 .cfi_def_cfa_register x29 532 mov xSELF, x3 // Move thread pointer into SELF register. 533 534 // Copy arguments into stack frame. 535 // Use simple copy routine for now. 536 // 4 bytes per slot. 537 // X1 - source address 538 // W2 - args length 539 // X9 - destination address. 540 // W10 - temporary 541 add x9, sp, #8 // Destination address is bottom of stack + null. 542 543 // Use \@ to differentiate between macro invocations. 544.LcopyParams\@: 545 cmp w2, #0 546 beq .LendCopyParams\@ 547 sub w2, w2, #4 // Need 65536 bytes of range. 548 ldr w10, [x1, x2] 549 str w10, [x9, x2] 550 551 b .LcopyParams\@ 552 553.LendCopyParams\@: 554 555 // Store null into ArtMethod* at bottom of frame. 556 str xzr, [sp] 557.endm 558 559.macro INVOKE_STUB_CALL_AND_RETURN 560 561 // load method-> METHOD_QUICK_CODE_OFFSET 562 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64] 563 // Branch to method. 564 blr x9 565 566 // Restore return value address and shorty address. 567 ldp x4,x5, [xFP, #16] 568 .cfi_restore x4 569 .cfi_restore x5 570 571 ldr x28, [xFP, #112] 572 .cfi_restore x28 573 574 ldp x26, x27, [xFP, #96] 575 .cfi_restore x26 576 .cfi_restore x27 577 578 ldp x24, x25, [xFP, #80] 579 .cfi_restore x24 580 .cfi_restore x25 581 582 ldp x22, x23, [xFP, #64] 583 .cfi_restore x22 584 .cfi_restore x23 585 586 ldp x20, x21, [xFP, #48] 587 .cfi_restore x20 588 .cfi_restore x21 589 590 // Store result (w0/x0/s0/d0) appropriately, depending on resultType. 591 ldrb w10, [x5] 592 593 // Don't set anything for a void type. 594 cmp w10, #'V' 595 beq .Lexit_art_quick_invoke_stub\@ 596 597 cmp w10, #'D' 598 bne .Lreturn_is_float\@ 599 str d0, [x4] 600 b .Lexit_art_quick_invoke_stub\@ 601 602.Lreturn_is_float\@: 603 cmp w10, #'F' 604 bne .Lreturn_is_int\@ 605 str s0, [x4] 606 b .Lexit_art_quick_invoke_stub\@ 607 608 // Just store x0. Doesn't matter if it is 64 or 32 bits. 609.Lreturn_is_int\@: 610 str x0, [x4] 611 612.Lexit_art_quick_invoke_stub\@: 613 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19. 614 .cfi_restore x19 615 mov sp, x2 616 .cfi_restore sp 617 618 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register. 619 .cfi_restore x29 620 .cfi_restore x30 621 622 ret 623 624.endm 625 626 627/* 628 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0 629 * uint32_t *args, x1 630 * uint32_t argsize, w2 631 * Thread *self, x3 632 * JValue *result, x4 633 * char *shorty); x5 634 * +----------------------+ 635 * | | 636 * | C/C++ frame | 637 * | LR'' | 638 * | FP'' | <- SP' 639 * +----------------------+ 640 * +----------------------+ 641 * | x28 | <- TODO: Remove callee-saves. 642 * | : | 643 * | x19 | 644 * | SP' | 645 * | X5 | 646 * | X4 | Saved registers 647 * | LR' | 648 * | FP' | <- FP 649 * +----------------------+ 650 * | uint32_t out[n-1] | 651 * | : : | Outs 652 * | uint32_t out[0] | 653 * | ArtMethod* | <- SP value=null 654 * +----------------------+ 655 * 656 * Outgoing registers: 657 * x0 - Method* 658 * x1-x7 - integer parameters. 659 * d0-d7 - Floating point parameters. 660 * xSELF = self 661 * SP = & of ArtMethod* 662 * x1 = "this" pointer. 663 * 664 */ 665ENTRY art_quick_invoke_stub 666 // Spill registers as per AACPS64 calling convention. 667 INVOKE_STUB_CREATE_FRAME 668 669 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 670 // Parse the passed shorty to determine which register to load. 671 // Load addresses for routines that load WXSD registers. 672 adr x11, .LstoreW2 673 adr x12, .LstoreX2 674 adr x13, .LstoreS0 675 adr x14, .LstoreD0 676 677 // Initialize routine offsets to 0 for integers and floats. 678 // x8 for integers, x15 for floating point. 679 mov x8, #0 680 mov x15, #0 681 682 add x10, x5, #1 // Load shorty address, plus one to skip return value. 683 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer. 684 685 // Loop to fill registers. 686.LfillRegisters: 687 ldrb w17, [x10], #1 // Load next character in signature, and increment. 688 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated. 689 690 cmp w17, #'F' // is this a float? 691 bne .LisDouble 692 693 cmp x15, # 8*12 // Skip this load if all registers full. 694 beq .Ladvance4 695 696 add x17, x13, x15 // Calculate subroutine to jump to. 697 br x17 698 699.LisDouble: 700 cmp w17, #'D' // is this a double? 701 bne .LisLong 702 703 cmp x15, # 8*12 // Skip this load if all registers full. 704 beq .Ladvance8 705 706 add x17, x14, x15 // Calculate subroutine to jump to. 707 br x17 708 709.LisLong: 710 cmp w17, #'J' // is this a long? 711 bne .LisOther 712 713 cmp x8, # 6*12 // Skip this load if all registers full. 714 beq .Ladvance8 715 716 add x17, x12, x8 // Calculate subroutine to jump to. 717 br x17 718 719.LisOther: // Everything else takes one vReg. 720 cmp x8, # 6*12 // Skip this load if all registers full. 721 beq .Ladvance4 722 723 add x17, x11, x8 // Calculate subroutine to jump to. 724 br x17 725 726.Ladvance4: 727 add x9, x9, #4 728 b .LfillRegisters 729 730.Ladvance8: 731 add x9, x9, #8 732 b .LfillRegisters 733 734// Macro for loading a parameter into a register. 735// counter - the register with offset into these tables 736// size - the size of the register - 4 or 8 bytes. 737// register - the name of the register to be loaded. 738.macro LOADREG counter size register return 739 ldr \register , [x9], #\size 740 add \counter, \counter, 12 741 b \return 742.endm 743 744// Store ints. 745.LstoreW2: 746 LOADREG x8 4 w2 .LfillRegisters 747 LOADREG x8 4 w3 .LfillRegisters 748 LOADREG x8 4 w4 .LfillRegisters 749 LOADREG x8 4 w5 .LfillRegisters 750 LOADREG x8 4 w6 .LfillRegisters 751 LOADREG x8 4 w7 .LfillRegisters 752 753// Store longs. 754.LstoreX2: 755 LOADREG x8 8 x2 .LfillRegisters 756 LOADREG x8 8 x3 .LfillRegisters 757 LOADREG x8 8 x4 .LfillRegisters 758 LOADREG x8 8 x5 .LfillRegisters 759 LOADREG x8 8 x6 .LfillRegisters 760 LOADREG x8 8 x7 .LfillRegisters 761 762// Store singles. 763.LstoreS0: 764 LOADREG x15 4 s0 .LfillRegisters 765 LOADREG x15 4 s1 .LfillRegisters 766 LOADREG x15 4 s2 .LfillRegisters 767 LOADREG x15 4 s3 .LfillRegisters 768 LOADREG x15 4 s4 .LfillRegisters 769 LOADREG x15 4 s5 .LfillRegisters 770 LOADREG x15 4 s6 .LfillRegisters 771 LOADREG x15 4 s7 .LfillRegisters 772 773// Store doubles. 774.LstoreD0: 775 LOADREG x15 8 d0 .LfillRegisters 776 LOADREG x15 8 d1 .LfillRegisters 777 LOADREG x15 8 d2 .LfillRegisters 778 LOADREG x15 8 d3 .LfillRegisters 779 LOADREG x15 8 d4 .LfillRegisters 780 LOADREG x15 8 d5 .LfillRegisters 781 LOADREG x15 8 d6 .LfillRegisters 782 LOADREG x15 8 d7 .LfillRegisters 783 784 785.LcallFunction: 786 787 INVOKE_STUB_CALL_AND_RETURN 788 789END art_quick_invoke_stub 790 791/* extern"C" 792 * void art_quick_invoke_static_stub(ArtMethod *method, x0 793 * uint32_t *args, x1 794 * uint32_t argsize, w2 795 * Thread *self, x3 796 * JValue *result, x4 797 * char *shorty); x5 798 */ 799ENTRY art_quick_invoke_static_stub 800 // Spill registers as per AACPS64 calling convention. 801 INVOKE_STUB_CREATE_FRAME 802 803 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 804 // Parse the passed shorty to determine which register to load. 805 // Load addresses for routines that load WXSD registers. 806 adr x11, .LstoreW1_2 807 adr x12, .LstoreX1_2 808 adr x13, .LstoreS0_2 809 adr x14, .LstoreD0_2 810 811 // Initialize routine offsets to 0 for integers and floats. 812 // x8 for integers, x15 for floating point. 813 mov x8, #0 814 mov x15, #0 815 816 add x10, x5, #1 // Load shorty address, plus one to skip return value. 817 818 // Loop to fill registers. 819.LfillRegisters2: 820 ldrb w17, [x10], #1 // Load next character in signature, and increment. 821 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated. 822 823 cmp w17, #'F' // is this a float? 824 bne .LisDouble2 825 826 cmp x15, # 8*12 // Skip this load if all registers full. 827 beq .Ladvance4_2 828 829 add x17, x13, x15 // Calculate subroutine to jump to. 830 br x17 831 832.LisDouble2: 833 cmp w17, #'D' // is this a double? 834 bne .LisLong2 835 836 cmp x15, # 8*12 // Skip this load if all registers full. 837 beq .Ladvance8_2 838 839 add x17, x14, x15 // Calculate subroutine to jump to. 840 br x17 841 842.LisLong2: 843 cmp w17, #'J' // is this a long? 844 bne .LisOther2 845 846 cmp x8, # 7*12 // Skip this load if all registers full. 847 beq .Ladvance8_2 848 849 add x17, x12, x8 // Calculate subroutine to jump to. 850 br x17 851 852.LisOther2: // Everything else takes one vReg. 853 cmp x8, # 7*12 // Skip this load if all registers full. 854 beq .Ladvance4_2 855 856 add x17, x11, x8 // Calculate subroutine to jump to. 857 br x17 858 859.Ladvance4_2: 860 add x9, x9, #4 861 b .LfillRegisters2 862 863.Ladvance8_2: 864 add x9, x9, #8 865 b .LfillRegisters2 866 867// Store ints. 868.LstoreW1_2: 869 LOADREG x8 4 w1 .LfillRegisters2 870 LOADREG x8 4 w2 .LfillRegisters2 871 LOADREG x8 4 w3 .LfillRegisters2 872 LOADREG x8 4 w4 .LfillRegisters2 873 LOADREG x8 4 w5 .LfillRegisters2 874 LOADREG x8 4 w6 .LfillRegisters2 875 LOADREG x8 4 w7 .LfillRegisters2 876 877// Store longs. 878.LstoreX1_2: 879 LOADREG x8 8 x1 .LfillRegisters2 880 LOADREG x8 8 x2 .LfillRegisters2 881 LOADREG x8 8 x3 .LfillRegisters2 882 LOADREG x8 8 x4 .LfillRegisters2 883 LOADREG x8 8 x5 .LfillRegisters2 884 LOADREG x8 8 x6 .LfillRegisters2 885 LOADREG x8 8 x7 .LfillRegisters2 886 887// Store singles. 888.LstoreS0_2: 889 LOADREG x15 4 s0 .LfillRegisters2 890 LOADREG x15 4 s1 .LfillRegisters2 891 LOADREG x15 4 s2 .LfillRegisters2 892 LOADREG x15 4 s3 .LfillRegisters2 893 LOADREG x15 4 s4 .LfillRegisters2 894 LOADREG x15 4 s5 .LfillRegisters2 895 LOADREG x15 4 s6 .LfillRegisters2 896 LOADREG x15 4 s7 .LfillRegisters2 897 898// Store doubles. 899.LstoreD0_2: 900 LOADREG x15 8 d0 .LfillRegisters2 901 LOADREG x15 8 d1 .LfillRegisters2 902 LOADREG x15 8 d2 .LfillRegisters2 903 LOADREG x15 8 d3 .LfillRegisters2 904 LOADREG x15 8 d4 .LfillRegisters2 905 LOADREG x15 8 d5 .LfillRegisters2 906 LOADREG x15 8 d6 .LfillRegisters2 907 LOADREG x15 8 d7 .LfillRegisters2 908 909 910.LcallFunction2: 911 912 INVOKE_STUB_CALL_AND_RETURN 913 914END art_quick_invoke_static_stub 915 916 917 918 /* 919 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_ 920 */ 921 922ENTRY art_quick_do_long_jump 923 // Load FPRs 924 ldp d0, d1, [x1], #16 925 ldp d2, d3, [x1], #16 926 ldp d4, d5, [x1], #16 927 ldp d6, d7, [x1], #16 928 ldp d8, d9, [x1], #16 929 ldp d10, d11, [x1], #16 930 ldp d12, d13, [x1], #16 931 ldp d14, d15, [x1], #16 932 ldp d16, d17, [x1], #16 933 ldp d18, d19, [x1], #16 934 ldp d20, d21, [x1], #16 935 ldp d22, d23, [x1], #16 936 ldp d24, d25, [x1], #16 937 ldp d26, d27, [x1], #16 938 ldp d28, d29, [x1], #16 939 ldp d30, d31, [x1] 940 941 // Load GPRs 942 // TODO: lots of those are smashed, could optimize. 943 add x0, x0, #30*8 944 ldp x30, x1, [x0], #-16 945 ldp x28, x29, [x0], #-16 946 ldp x26, x27, [x0], #-16 947 ldp x24, x25, [x0], #-16 948 ldp x22, x23, [x0], #-16 949 ldp x20, x21, [x0], #-16 950 ldp x18, x19, [x0], #-16 951 ldp x16, x17, [x0], #-16 952 ldp x14, x15, [x0], #-16 953 ldp x12, x13, [x0], #-16 954 ldp x10, x11, [x0], #-16 955 ldp x8, x9, [x0], #-16 956 ldp x6, x7, [x0], #-16 957 ldp x4, x5, [x0], #-16 958 ldp x2, x3, [x0], #-16 959 mov sp, x1 960 961 // TODO: Is it really OK to use LR for the target PC? 962 mov x0, #0 963 mov x1, #0 964 br xLR 965END art_quick_do_long_jump 966 967 /* 968 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the 969 * possibly null object to lock. 970 * 971 * Derived from arm32 code. 972 */ 973 .extern artLockObjectFromCode 974ENTRY art_quick_lock_object 975 cbz w0, .Lslow_lock 976 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore 977.Lretry_lock: 978 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop? 979 ldxr w1, [x4] 980 mov x3, x1 981 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 982 cbnz w3, .Lnot_unlocked // already thin locked 983 // unlocked case - x1: original lock word that's zero except for the read barrier bits. 984 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits 985 stxr w3, w2, [x4] 986 cbnz w3, .Llock_stxr_fail // store failed, retry 987 dmb ishld // full (LoadLoad|LoadStore) memory barrier 988 ret 989.Lnot_unlocked: // x1: original lock word 990 lsr w3, w1, LOCK_WORD_STATE_SHIFT 991 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path 992 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() 993 uxth w2, w2 // zero top 16 bits 994 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock 995 // else contention, go to slow path 996 mov x3, x1 // copy the lock word to check count overflow. 997 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits. 998 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow 999 lsr w3, w2, LOCK_WORD_READ_BARRIER_STATE_SHIFT // if either of the upper two bits (28-29) are set, we overflowed. 1000 cbnz w3, .Lslow_lock // if we overflow the count go slow path 1001 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real 1002 stxr w3, w2, [x4] 1003 cbnz w3, .Llock_stxr_fail // store failed, retry 1004 ret 1005.Llock_stxr_fail: 1006 b .Lretry_lock // retry 1007.Lslow_lock: 1008 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block 1009 mov x1, xSELF // pass Thread::Current 1010 bl artLockObjectFromCode // (Object* obj, Thread*) 1011 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1012 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1013END art_quick_lock_object 1014 1015 /* 1016 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. 1017 * x0 holds the possibly null object to lock. 1018 * 1019 * Derived from arm32 code. 1020 */ 1021 .extern artUnlockObjectFromCode 1022ENTRY art_quick_unlock_object 1023 cbz x0, .Lslow_unlock 1024 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore 1025.Lretry_unlock: 1026#ifndef USE_READ_BARRIER 1027 ldr w1, [x4] 1028#else 1029 ldxr w1, [x4] // Need to use atomic instructions for read barrier 1030#endif 1031 lsr w2, w1, LOCK_WORD_STATE_SHIFT 1032 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path 1033 ldr w2, [xSELF, #THREAD_ID_OFFSET] 1034 mov x3, x1 // copy lock word to check thread id equality 1035 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 1036 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId() 1037 uxth w3, w3 // zero top 16 bits 1038 cbnz w3, .Lslow_unlock // do lock word and self thread id's match? 1039 mov x3, x1 // copy lock word to detect transition to unlocked 1040 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 1041 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE 1042 bpl .Lrecursive_thin_unlock 1043 // transition to unlocked 1044 mov x3, x1 1045 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK // w3: zero except for the preserved read barrier bits 1046 dmb ish // full (LoadStore|StoreStore) memory barrier 1047#ifndef USE_READ_BARRIER 1048 str w3, [x4] 1049#else 1050 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier 1051 cbnz w2, .Lunlock_stxr_fail // store failed, retry 1052#endif 1053 ret 1054.Lrecursive_thin_unlock: // w1: original lock word 1055 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count 1056#ifndef USE_READ_BARRIER 1057 str w1, [x4] 1058#else 1059 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier 1060 cbnz w2, .Lunlock_stxr_fail // store failed, retry 1061#endif 1062 ret 1063.Lunlock_stxr_fail: 1064 b .Lretry_unlock // retry 1065.Lslow_unlock: 1066 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC 1067 mov x1, xSELF // pass Thread::Current 1068 bl artUnlockObjectFromCode // (Object* obj, Thread*) 1069 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1070 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1071END art_quick_unlock_object 1072 1073 /* 1074 * Entry from managed code that calls artIsAssignableFromCode and on failure calls 1075 * artThrowClassCastException. 1076 */ 1077 .extern artThrowClassCastException 1078ENTRY art_quick_check_cast 1079 // Store arguments and link register 1080 // Stack needs to be 16B aligned on calls. 1081 stp x0, x1, [sp,#-32]! 1082 .cfi_adjust_cfa_offset 32 1083 .cfi_rel_offset x0, 0 1084 .cfi_rel_offset x1, 8 1085 str xLR, [sp, #24] 1086 .cfi_rel_offset x30, 24 1087 1088 // Call runtime code 1089 bl artIsAssignableFromCode 1090 1091 // Check for exception 1092 cbz x0, .Lthrow_class_cast_exception 1093 1094 // Restore and return 1095 ldr xLR, [sp, #24] 1096 .cfi_restore x30 1097 ldp x0, x1, [sp], #32 1098 .cfi_restore x0 1099 .cfi_restore x1 1100 .cfi_adjust_cfa_offset -32 1101 ret 1102 1103.Lthrow_class_cast_exception: 1104 // Restore 1105 ldr xLR, [sp, #24] 1106 .cfi_restore x30 1107 ldp x0, x1, [sp], #32 1108 .cfi_restore x0 1109 .cfi_restore x1 1110 .cfi_adjust_cfa_offset -32 1111 1112 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 1113 mov x2, xSELF // pass Thread::Current 1114 b artThrowClassCastException // (Class*, Class*, Thread*) 1115 brk 0 // We should not return here... 1116END art_quick_check_cast 1117 1118 /* 1119 * Entry from managed code for array put operations of objects where the value being stored 1120 * needs to be checked for compatibility. 1121 * x0 = array, x1 = index, x2 = value 1122 * 1123 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We 1124 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by 1125 * using index-zero-extension in load/stores. 1126 * 1127 * Temporaries: x3, x4 1128 * TODO: x4 OK? ip seems wrong here. 1129 */ 1130ENTRY art_quick_aput_obj_with_null_and_bound_check 1131 tst x0, x0 1132 bne art_quick_aput_obj_with_bound_check 1133 b art_quick_throw_null_pointer_exception 1134END art_quick_aput_obj_with_null_and_bound_check 1135 1136ENTRY art_quick_aput_obj_with_bound_check 1137 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] 1138 cmp w3, w1 1139 bhi art_quick_aput_obj 1140 mov x0, x1 1141 mov x1, x3 1142 b art_quick_throw_array_bounds 1143END art_quick_aput_obj_with_bound_check 1144 1145ENTRY art_quick_aput_obj 1146 cbz x2, .Ldo_aput_null 1147 ldr w3, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b 1148 // This also zero-extends to x3 1149 ldr w4, [x2, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b 1150 // This also zero-extends to x4 1151 ldr w3, [x3, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b 1152 // This also zero-extends to x3 1153 cmp w3, w4 // value's type == array's component type - trivial assignability 1154 bne .Lcheck_assignability 1155.Ldo_aput: 1156 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1157 // "Compress" = do nothing 1158 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1159 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1160 lsr x0, x0, #7 1161 strb w3, [x3, x0] 1162 ret 1163.Ldo_aput_null: 1164 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1165 // "Compress" = do nothing 1166 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1167 ret 1168.Lcheck_assignability: 1169 // Store arguments and link register 1170 stp x0, x1, [sp,#-32]! 1171 .cfi_adjust_cfa_offset 32 1172 .cfi_rel_offset x0, 0 1173 .cfi_rel_offset x1, 8 1174 stp x2, xLR, [sp, #16] 1175 .cfi_rel_offset x2, 16 1176 .cfi_rel_offset x30, 24 1177 1178 // Call runtime code 1179 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1180 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1181 bl artIsAssignableFromCode 1182 1183 // Check for exception 1184 cbz x0, .Lthrow_array_store_exception 1185 1186 // Restore 1187 ldp x2, x30, [sp, #16] 1188 .cfi_restore x2 1189 .cfi_restore x30 1190 ldp x0, x1, [sp], #32 1191 .cfi_restore x0 1192 .cfi_restore x1 1193 .cfi_adjust_cfa_offset -32 1194 1195 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1196 // "Compress" = do nothing 1197 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1198 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1199 lsr x0, x0, #7 1200 strb w3, [x3, x0] 1201 ret 1202.Lthrow_array_store_exception: 1203 ldp x2, x30, [sp, #16] 1204 .cfi_restore x2 1205 .cfi_restore x30 1206 ldp x0, x1, [sp], #32 1207 .cfi_restore x0 1208 .cfi_restore x1 1209 .cfi_adjust_cfa_offset -32 1210 1211 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1212 mov x1, x2 // Pass value. 1213 mov x2, xSELF // Pass Thread::Current. 1214 b artThrowArrayStoreException // (Object*, Object*, Thread*). 1215 brk 0 // Unreached. 1216END art_quick_aput_obj 1217 1218// Macro to facilitate adding new allocation entrypoints. 1219.macro ONE_ARG_DOWNCALL name, entrypoint, return 1220 .extern \entrypoint 1221ENTRY \name 1222 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1223 mov x1, xSELF // pass Thread::Current 1224 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) 1225 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1226 \return 1227END \name 1228.endm 1229 1230// Macro to facilitate adding new allocation entrypoints. 1231.macro TWO_ARG_DOWNCALL name, entrypoint, return 1232 .extern \entrypoint 1233ENTRY \name 1234 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1235 mov x2, xSELF // pass Thread::Current 1236 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) 1237 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1238 \return 1239END \name 1240.endm 1241 1242// Macro to facilitate adding new allocation entrypoints. 1243.macro THREE_ARG_DOWNCALL name, entrypoint, return 1244 .extern \entrypoint 1245ENTRY \name 1246 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1247 mov x3, xSELF // pass Thread::Current 1248 bl \entrypoint 1249 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1250 \return 1251END \name 1252.endm 1253 1254// Macro to facilitate adding new allocation entrypoints. 1255.macro FOUR_ARG_DOWNCALL name, entrypoint, return 1256 .extern \entrypoint 1257ENTRY \name 1258 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1259 mov x4, xSELF // pass Thread::Current 1260 bl \entrypoint // 1261 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1262 \return 1263 DELIVER_PENDING_EXCEPTION 1264END \name 1265.endm 1266 1267// Macros taking opportunity of code similarities for downcalls with referrer. 1268.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return 1269 .extern \entrypoint 1270ENTRY \name 1271 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1272 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1273 mov x2, xSELF // pass Thread::Current 1274 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) 1275 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1276 \return 1277END \name 1278.endm 1279 1280.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return 1281 .extern \entrypoint 1282ENTRY \name 1283 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1284 ldr x2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1285 mov x3, xSELF // pass Thread::Current 1286 bl \entrypoint 1287 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1288 \return 1289END \name 1290.endm 1291 1292.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return 1293 .extern \entrypoint 1294ENTRY \name 1295 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1296 ldr x3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1297 mov x4, xSELF // pass Thread::Current 1298 bl \entrypoint 1299 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1300 \return 1301END \name 1302.endm 1303 1304.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1305 cbz w0, 1f // result zero branch over 1306 ret // return 13071: 1308 DELIVER_PENDING_EXCEPTION 1309.endm 1310 1311 /* 1312 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on 1313 * failure. 1314 */ 1315TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1316 1317 /* 1318 * Entry from managed code when uninitialized static storage, this stub will run the class 1319 * initializer and deliver the exception on error. On success the static storage base is 1320 * returned. 1321 */ 1322ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1323 1324ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1325ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1326 1327ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1328ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1329ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1330ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1331ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1332ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1333ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1334 1335TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1336TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1337TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1338TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1339TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1340TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1341TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1342 1343TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1344TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1345TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1346TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1347 1348THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1349THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1350THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1351THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1352THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1353 1354// This is separated out as the argument order is different. 1355 .extern artSet64StaticFromCode 1356ENTRY art_quick_set64_static 1357 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1358 mov x3, x1 // Store value 1359 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1360 mov x2, x3 // Put value param 1361 mov x3, xSELF // pass Thread::Current 1362 bl artSet64StaticFromCode 1363 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1364 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1365END art_quick_set64_static 1366 1367 /* 1368 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an 1369 * exception on error. On success the String is returned. w0 holds the string index. The fast 1370 * path check for hit in strings cache has already been performed. 1371 */ 1372ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1373 1374// Generate the allocation entrypoints for each allocator. 1375GENERATE_ALL_ALLOC_ENTRYPOINTS 1376 1377 /* 1378 * Called by managed code when the thread has been asked to suspend. 1379 */ 1380 .extern artTestSuspendFromCode 1381ENTRY art_quick_test_suspend 1382 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags 1383 cbnz w0, .Lneed_suspend // check flags == 0 1384 ret // return if flags == 0 1385.Lneed_suspend: 1386 mov x0, xSELF 1387 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl 1388 bl artTestSuspendFromCode // (Thread*) 1389 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1390END art_quick_test_suspend 1391 1392ENTRY art_quick_implicit_suspend 1393 mov x0, xSELF 1394 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl 1395 bl artTestSuspendFromCode // (Thread*) 1396 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1397END art_quick_implicit_suspend 1398 1399 /* 1400 * Called by managed code that is attempting to call a method on a proxy class. On entry 1401 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy 1402 * method agrees with a ref and args callee save frame. 1403 */ 1404 .extern artQuickProxyInvokeHandler 1405ENTRY art_quick_proxy_invoke_handler 1406 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 1407 mov x2, xSELF // pass Thread::Current 1408 mov x3, sp // pass SP 1409 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP) 1410 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] 1411 cbnz x2, .Lexception_in_proxy // success if no exception is pending 1412 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame 1413 fmov d0, x0 // Store result in d0 in case it was float or double 1414 ret // return on success 1415.Lexception_in_proxy: 1416 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1417 DELIVER_PENDING_EXCEPTION 1418END art_quick_proxy_invoke_handler 1419 1420 /* 1421 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's 1422 * dex method index. 1423 */ 1424ENTRY art_quick_imt_conflict_trampoline 1425 mov x0, xIP1 1426 b art_quick_invoke_interface_trampoline 1427END art_quick_imt_conflict_trampoline 1428 1429ENTRY art_quick_resolution_trampoline 1430 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1431 mov x2, xSELF 1432 mov x3, sp 1433 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP) 1434 cbz x0, 1f 1435 mov xIP0, x0 // Remember returned code pointer in xIP0. 1436 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP. 1437 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1438 br xIP0 14391: 1440 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1441 DELIVER_PENDING_EXCEPTION 1442END art_quick_resolution_trampoline 1443 1444/* 1445 * Generic JNI frame layout: 1446 * 1447 * #-------------------# 1448 * | | 1449 * | caller method... | 1450 * #-------------------# <--- SP on entry 1451 * | Return X30/LR | 1452 * | X29/FP | callee save 1453 * | X28 | callee save 1454 * | X27 | callee save 1455 * | X26 | callee save 1456 * | X25 | callee save 1457 * | X24 | callee save 1458 * | X23 | callee save 1459 * | X22 | callee save 1460 * | X21 | callee save 1461 * | X20 | callee save 1462 * | X19 | callee save 1463 * | X7 | arg7 1464 * | X6 | arg6 1465 * | X5 | arg5 1466 * | X4 | arg4 1467 * | X3 | arg3 1468 * | X2 | arg2 1469 * | X1 | arg1 1470 * | D7 | float arg 8 1471 * | D6 | float arg 7 1472 * | D5 | float arg 6 1473 * | D4 | float arg 5 1474 * | D3 | float arg 4 1475 * | D2 | float arg 3 1476 * | D1 | float arg 2 1477 * | D0 | float arg 1 1478 * | Method* | <- X0 1479 * #-------------------# 1480 * | local ref cookie | // 4B 1481 * | handle scope size | // 4B 1482 * #-------------------# 1483 * | JNI Call Stack | 1484 * #-------------------# <--- SP on native call 1485 * | | 1486 * | Stack for Regs | The trampoline assembly will pop these values 1487 * | | into registers for native call 1488 * #-------------------# 1489 * | Native code ptr | 1490 * #-------------------# 1491 * | Free scratch | 1492 * #-------------------# 1493 * | Ptr to (1) | <--- SP 1494 * #-------------------# 1495 */ 1496 /* 1497 * Called to do a generic JNI down-call 1498 */ 1499ENTRY art_quick_generic_jni_trampoline 1500 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 1501 1502 // Save SP , so we can have static CFI info. 1503 mov x28, sp 1504 .cfi_def_cfa_register x28 1505 1506 // This looks the same, but is different: this will be updated to point to the bottom 1507 // of the frame when the handle scope is inserted. 1508 mov xFP, sp 1509 1510 mov xIP0, #5120 1511 sub sp, sp, xIP0 1512 1513 // prepare for artQuickGenericJniTrampoline call 1514 // (Thread*, SP) 1515 // x0 x1 <= C calling convention 1516 // xSELF xFP <= where they are 1517 1518 mov x0, xSELF // Thread* 1519 mov x1, xFP 1520 bl artQuickGenericJniTrampoline // (Thread*, sp) 1521 1522 // The C call will have registered the complete save-frame on success. 1523 // The result of the call is: 1524 // x0: pointer to native code, 0 on error. 1525 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there. 1526 1527 // Check for error = 0. 1528 cbz x0, .Lexception_in_native 1529 1530 // Release part of the alloca. 1531 mov sp, x1 1532 1533 // Save the code pointer 1534 mov xIP0, x0 1535 1536 // Load parameters from frame into registers. 1537 // TODO Check with artQuickGenericJniTrampoline. 1538 // Also, check again APPCS64 - the stack arguments are interleaved. 1539 ldp x0, x1, [sp] 1540 ldp x2, x3, [sp, #16] 1541 ldp x4, x5, [sp, #32] 1542 ldp x6, x7, [sp, #48] 1543 1544 ldp d0, d1, [sp, #64] 1545 ldp d2, d3, [sp, #80] 1546 ldp d4, d5, [sp, #96] 1547 ldp d6, d7, [sp, #112] 1548 1549 add sp, sp, #128 1550 1551 blr xIP0 // native call. 1552 1553 // result sign extension is handled in C code 1554 // prepare for artQuickGenericJniEndTrampoline call 1555 // (Thread*, result, result_f) 1556 // x0 x1 x2 <= C calling convention 1557 mov x1, x0 // Result (from saved). 1558 mov x0, xSELF // Thread register. 1559 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2 1560 1561 bl artQuickGenericJniEndTrampoline 1562 1563 // Pending exceptions possible. 1564 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] 1565 cbnz x2, .Lexception_in_native 1566 1567 // Tear down the alloca. 1568 mov sp, x28 1569 .cfi_def_cfa_register sp 1570 1571 // Tear down the callee-save frame. 1572 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1573 1574 // store into fpr, for when it's a fpr return... 1575 fmov d0, x0 1576 ret 1577 1578.Lexception_in_native: 1579 // Move to x1 then sp to please assembler. 1580 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 1581 mov sp, x1 1582 .cfi_def_cfa_register sp 1583 # This will create a new save-all frame, required by the runtime. 1584 DELIVER_PENDING_EXCEPTION 1585END art_quick_generic_jni_trampoline 1586 1587/* 1588 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those 1589 * of a quick call: 1590 * x0 = method being called/to bridge to. 1591 * x1..x7, d0..d7 = arguments to that method. 1592 */ 1593ENTRY art_quick_to_interpreter_bridge 1594 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments. 1595 1596 // x0 will contain mirror::ArtMethod* method. 1597 mov x1, xSELF // How to get Thread::Current() ??? 1598 mov x2, sp 1599 1600 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self, 1601 // mirror::ArtMethod** sp) 1602 bl artQuickToInterpreterBridge 1603 1604 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case. 1605 1606 fmov d0, x0 1607 1608 RETURN_OR_DELIVER_PENDING_EXCEPTION 1609END art_quick_to_interpreter_bridge 1610 1611 1612// 1613// Instrumentation-related stubs 1614// 1615 .extern artInstrumentationMethodEntryFromCode 1616ENTRY art_quick_instrumentation_entry 1617 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1618 1619 mov x20, x0 // Preserve method reference in a callee-save. 1620 1621 mov x2, xSELF 1622 mov x3, xLR 1623 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR) 1624 1625 mov xIP0, x0 // x0 = result of call. 1626 mov x0, x20 // Reload method reference. 1627 1628 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF 1629 adr xLR, art_quick_instrumentation_exit 1630 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit. 1631END art_quick_instrumentation_entry 1632 1633 .extern artInstrumentationMethodExitFromCode 1634ENTRY art_quick_instrumentation_exit 1635 mov xLR, #0 // Clobber LR for later checks. 1636 1637 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 1638 1639 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then 1640 // we would need to fully restore it. As there are a lot of callee-save registers, it seems 1641 // easier to have an extra small stack area. 1642 1643 str x0, [sp, #-16]! // Save integer result. 1644 .cfi_adjust_cfa_offset 16 1645 str d0, [sp, #8] // Save floating-point result. 1646 1647 add x1, sp, #16 // Pass SP. 1648 mov x2, x0 // Pass integer result. 1649 fmov x3, d0 // Pass floating-point result. 1650 mov x0, xSELF // Pass Thread. 1651 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res) 1652 1653 mov xIP0, x0 // Return address from instrumentation call. 1654 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize 1655 1656 ldr d0, [sp, #8] // Restore floating-point result. 1657 ldr x0, [sp], 16 // Restore integer result, and drop stack area. 1658 .cfi_adjust_cfa_offset 16 1659 1660 POP_REFS_ONLY_CALLEE_SAVE_FRAME 1661 1662 br xIP0 // Tail-call out. 1663END art_quick_instrumentation_exit 1664 1665 /* 1666 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization 1667 * will long jump to the upcall with a special exception of -1. 1668 */ 1669 .extern artDeoptimize 1670ENTRY art_quick_deoptimize 1671 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1672 mov x0, xSELF // Pass thread. 1673 bl artDeoptimize // artDeoptimize(Thread*) 1674 brk 0 1675END art_quick_deoptimize 1676 1677 1678 /* 1679 * String's indexOf. 1680 * 1681 * TODO: Not very optimized. 1682 * On entry: 1683 * x0: string object (known non-null) 1684 * w1: char to match (known <= 0xFFFF) 1685 * w2: Starting offset in string data 1686 */ 1687ENTRY art_quick_indexof 1688 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET] 1689 add x0, x0, #MIRROR_STRING_VALUE_OFFSET 1690 1691 /* Clamp start to [0..count] */ 1692 cmp w2, #0 1693 csel w2, wzr, w2, lt 1694 cmp w2, w3 1695 csel w2, w3, w2, gt 1696 1697 /* Save a copy to compute result */ 1698 mov x5, x0 1699 1700 /* Build pointer to start of data to compare and pre-bias */ 1701 add x0, x0, x2, lsl #1 1702 sub x0, x0, #2 1703 1704 /* Compute iteration count */ 1705 sub w2, w3, w2 1706 1707 /* 1708 * At this point we have: 1709 * x0: start of the data to test 1710 * w1: char to compare 1711 * w2: iteration count 1712 * x5: original start of string data 1713 */ 1714 1715 subs w2, w2, #4 1716 b.lt .Lindexof_remainder 1717 1718.Lindexof_loop4: 1719 ldrh w6, [x0, #2]! 1720 ldrh w7, [x0, #2]! 1721 ldrh wIP0, [x0, #2]! 1722 ldrh wIP1, [x0, #2]! 1723 cmp w6, w1 1724 b.eq .Lmatch_0 1725 cmp w7, w1 1726 b.eq .Lmatch_1 1727 cmp wIP0, w1 1728 b.eq .Lmatch_2 1729 cmp wIP1, w1 1730 b.eq .Lmatch_3 1731 subs w2, w2, #4 1732 b.ge .Lindexof_loop4 1733 1734.Lindexof_remainder: 1735 adds w2, w2, #4 1736 b.eq .Lindexof_nomatch 1737 1738.Lindexof_loop1: 1739 ldrh w6, [x0, #2]! 1740 cmp w6, w1 1741 b.eq .Lmatch_3 1742 subs w2, w2, #1 1743 b.ne .Lindexof_loop1 1744 1745.Lindexof_nomatch: 1746 mov x0, #-1 1747 ret 1748 1749.Lmatch_0: 1750 sub x0, x0, #6 1751 sub x0, x0, x5 1752 asr x0, x0, #1 1753 ret 1754.Lmatch_1: 1755 sub x0, x0, #4 1756 sub x0, x0, x5 1757 asr x0, x0, #1 1758 ret 1759.Lmatch_2: 1760 sub x0, x0, #2 1761 sub x0, x0, x5 1762 asr x0, x0, #1 1763 ret 1764.Lmatch_3: 1765 sub x0, x0, x5 1766 asr x0, x0, #1 1767 ret 1768END art_quick_indexof 1769 1770 /* 1771 * String's compareTo. 1772 * 1773 * TODO: Not very optimized. 1774 * 1775 * On entry: 1776 * x0: this object pointer 1777 * x1: comp object pointer 1778 * 1779 */ 1780 .extern __memcmp16 1781ENTRY art_quick_string_compareto 1782 mov x2, x0 // x0 is return, use x2 for first input. 1783 sub x0, x2, x1 // Same string object? 1784 cbnz x0,1f 1785 ret 17861: // Different string objects. 1787 1788 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET] 1789 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET] 1790 add x2, x2, #MIRROR_STRING_VALUE_OFFSET 1791 add x1, x1, #MIRROR_STRING_VALUE_OFFSET 1792 1793 /* 1794 * Now: Data* Count 1795 * first arg x2 w4 1796 * second arg x1 w3 1797 */ 1798 1799 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4. 1800 subs x0, x4, x3 1801 // Min(count1, count2) into w3. 1802 csel x3, x3, x4, ge 1803 1804 // TODO: Tune this value. 1805 // Check for long string, do memcmp16 for them. 1806 cmp w3, #28 // Constant from arm32. 1807 bgt .Ldo_memcmp16 1808 1809 /* 1810 * Now: 1811 * x2: *first string data 1812 * x1: *second string data 1813 * w3: iteration count 1814 * x0: return value if comparison equal 1815 * x4, x5, x6, x7: free 1816 */ 1817 1818 // Do a simple unrolled loop. 1819.Lloop: 1820 // At least two more elements? 1821 subs w3, w3, #2 1822 b.lt .Lremainder_or_done 1823 1824 ldrh w4, [x2], #2 1825 ldrh w5, [x1], #2 1826 1827 ldrh w6, [x2], #2 1828 ldrh w7, [x1], #2 1829 1830 subs w4, w4, w5 1831 b.ne .Lw4_result 1832 1833 subs w6, w6, w7 1834 b.ne .Lw6_result 1835 1836 b .Lloop 1837 1838.Lremainder_or_done: 1839 adds w3, w3, #1 1840 b.eq .Lremainder 1841 ret 1842 1843.Lremainder: 1844 ldrh w4, [x2], #2 1845 ldrh w5, [x1], #2 1846 subs w4, w4, w5 1847 b.ne .Lw4_result 1848 ret 1849 1850// Result is in w4 1851.Lw4_result: 1852 sxtw x0, w4 1853 ret 1854 1855// Result is in w6 1856.Lw6_result: 1857 sxtw x0, w6 1858 ret 1859 1860.Ldo_memcmp16: 1861 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps. 1862 mov x15, xLR // TODO: Codify and check that? 1863 1864 mov x0, x2 1865 uxtw x2, w3 1866 bl __memcmp16 1867 1868 mov xLR, x15 // Restore LR. 1869 1870 cmp x0, #0 // Check the memcmp difference. 1871 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1. 1872 ret 1873END art_quick_string_compareto 1874