blob: 62a8b7019523fba8221967909455d50dec69ef54 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
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
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_x86.S"
Elliott Hughes5e284222012-04-04 13:38:03 -070018
Dave Allisonbbb32c22013-11-05 18:25:18 -080019// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
20
Ian Rogers57b86d42012-03-27 16:05:41 -070021 /*
22 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070023 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070024 */
Elliott Hughes787ec202012-03-29 17:14:15 -070025MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080026 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080027 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080028 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080029 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080030 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080031 .cfi_rel_offset ebp, -16
Elliott Hughesea944212012-04-05 13:11:53 -070032 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080033 .cfi_adjust_cfa_offset 16
Elliott Hughes787ec202012-03-29 17:14:15 -070034END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070035
Ian Rogers7caad772012-03-30 01:07:54 -070036 /*
37 * Macro that sets up the callee save frame to conform with
38 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
39 */
40MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080041 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080042 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080043 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080044 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080045 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080046 .cfi_rel_offset ebp, -16
Elliott Hughesea944212012-04-05 13:11:53 -070047 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080048 .cfi_adjust_cfa_offset 16
Ian Rogers7caad772012-03-30 01:07:54 -070049END_MACRO
50
51MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070052 addl MACRO_LITERAL(16), %esp // Unwind stack up to return address
53 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080054 .cfi_restore ebp
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070055 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080056 .cfi_restore esi
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070057 POP edi
Dave Allisonbbb32c22013-11-05 18:25:18 -080058 .cfi_restore edi
Ian Rogersaeeada42013-02-13 11:28:34 -080059 .cfi_adjust_cfa_offset -28
Elliott Hughes787ec202012-03-29 17:14:15 -070060END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070061
62 /*
63 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070064 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070065 */
jeffhao9dbb23e2012-05-18 17:03:57 -070066MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080067 PUSH edi // Save callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080068 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080069 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080070 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080071 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080072 .cfi_rel_offset ebp, -16
Ian Rogersaeeada42013-02-13 11:28:34 -080073 PUSH ebx // Save args
Dave Allisonbbb32c22013-11-05 18:25:18 -080074 .cfi_rel_offset ebx, -20
Ian Rogersaeeada42013-02-13 11:28:34 -080075 PUSH edx
Dave Allisonbbb32c22013-11-05 18:25:18 -080076 .cfi_rel_offset edx, -24
Ian Rogersaeeada42013-02-13 11:28:34 -080077 PUSH ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -080078 .cfi_rel_offset ecx, -28
Ian Rogersaeeada42013-02-13 11:28:34 -080079 PUSH eax // Align stack, eax will be clobbered by Method*
Dave Allisonbbb32c22013-11-05 18:25:18 -080080 .cfi_rel_offset eax, -28
Elliott Hughes787ec202012-03-29 17:14:15 -070081END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070082
jeffhao9dbb23e2012-05-18 17:03:57 -070083MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070084 addl MACRO_LITERAL(4), %esp // Remove padding
Ian Rogersaeeada42013-02-13 11:28:34 -080085 .cfi_adjust_cfa_offset -4
86 POP ecx // Restore args except eax
Dave Allisonbbb32c22013-11-05 18:25:18 -080087 .cfi_restore ecx
Ian Rogersaeeada42013-02-13 11:28:34 -080088 POP edx
Dave Allisonbbb32c22013-11-05 18:25:18 -080089 .cfi_restore edx
Ian Rogersaeeada42013-02-13 11:28:34 -080090 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -080091 .cfi_restore ebx
Ian Rogersaeeada42013-02-13 11:28:34 -080092 POP ebp // Restore callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080093 .cfi_restore ebp
Ian Rogersaeeada42013-02-13 11:28:34 -080094 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080095 .cfi_restore esi
Ian Rogersaeeada42013-02-13 11:28:34 -080096 POP edi
Dave Allisonbbb32c22013-11-05 18:25:18 -080097 .cfi_restore edi
Elliott Hughes787ec202012-03-29 17:14:15 -070098END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070099
100 /*
101 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
102 * exception is Thread::Current()->exception_.
103 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700104MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700105 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
106 mov %esp, %ecx
107 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700108 subl MACRO_LITERAL(8), %esp // Alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800109 .cfi_adjust_cfa_offset 8
110 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700111 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800112 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700113 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
114 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
Elliott Hughes787ec202012-03-29 17:14:15 -0700117MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800118 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700119 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
120 mov %esp, %ecx
121 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700122 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800123 .cfi_adjust_cfa_offset 8
124 PUSH ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700125 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800126 .cfi_adjust_cfa_offset 4
Elliott Hughes787ec202012-03-29 17:14:15 -0700127 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700128 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800129 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700130END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700131
Elliott Hughes787ec202012-03-29 17:14:15 -0700132MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800133 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700134 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
135 mov %esp, %ecx
136 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800137 PUSH eax // alignment padding
138 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700139 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800140 .cfi_adjust_cfa_offset 4
141 PUSH eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700142 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700143 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800144 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700145END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700146
Elliott Hughes787ec202012-03-29 17:14:15 -0700147MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800148 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700149 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
150 mov %esp, %edx
151 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800152 PUSH edx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700153 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800154 .cfi_adjust_cfa_offset 4
155 PUSH ecx // pass arg2
156 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700157 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700158 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800159 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700160END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700161
162 /*
163 * Called by managed code to create and deliver a NullPointerException.
164 */
Ian Rogers468532e2013-08-05 10:56:33 -0700165NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
167 /*
168 * Called by managed code to create and deliver an ArithmeticException.
169 */
Ian Rogers468532e2013-08-05 10:56:33 -0700170NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700171
172 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700173 * Called by managed code to create and deliver a StackOverflowError.
174 */
Ian Rogers468532e2013-08-05 10:56:33 -0700175NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700176
177 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700178 * Called by managed code, saves callee saves and then calls artThrowException
179 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
180 */
Ian Rogers468532e2013-08-05 10:56:33 -0700181ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700182
183 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700184 * Called by managed code to create and deliver a NoSuchMethodError.
185 */
Ian Rogers468532e2013-08-05 10:56:33 -0700186ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700187
188 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700189 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
190 * index, arg2 holds limit.
191 */
Ian Rogers468532e2013-08-05 10:56:33 -0700192TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700193
194 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700195 * All generated callsites for interface invokes and invocation slow paths will load arguments
196 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
197 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
198 * stack and call the appropriate C helper.
199 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
200 *
201 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
202 * of the target Method* in r0 and method->code_ in r1.
203 *
204 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
205 * thread and we branch to another stub to deliver it.
206 *
207 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
208 * pointing back to the original caller.
209 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700210MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800211 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700212 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
213 // return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800214 PUSH edi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800215 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -0800216 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800217 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -0800218 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800219 .cfi_rel_offset ebp, -16
220 PUSH ebx // Save args
221 .cfi_rel_offset ebx, -20
Ian Rogersaeeada42013-02-13 11:28:34 -0800222 PUSH edx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800223 .cfi_rel_offset edx, -24
Ian Rogersaeeada42013-02-13 11:28:34 -0800224 PUSH ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800225 .cfi_rel_offset ecx, -28
226 PUSH eax // <-- callee save Method* to go here
227 .cfi_rel_offset eax, -32
Ian Rogers7caad772012-03-30 01:07:54 -0700228 movl %esp, %edx // remember SP
229 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700230 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800231 .cfi_adjust_cfa_offset 12
232 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700233 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800234 .cfi_adjust_cfa_offset 4
Ian Rogers7caad772012-03-30 01:07:54 -0700235 pushl 32(%edx) // pass caller Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800236 .cfi_adjust_cfa_offset 4
237 PUSH ecx // pass arg2
238 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700239 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
240 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700241 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800242 .cfi_adjust_cfa_offset -36
Dave Allisonbbb32c22013-11-05 18:25:18 -0800243 POP ecx // Restore args except eax
244 .cfi_restore ecx
Ian Rogersaeeada42013-02-13 11:28:34 -0800245 POP edx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800246 .cfi_restore edx
Ian Rogersaeeada42013-02-13 11:28:34 -0800247 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800248 .cfi_restore ebx
249 POP ebp // Restore callee saves
250 .cfi_restore ebp
Ian Rogersaeeada42013-02-13 11:28:34 -0800251 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800252 .cfi_restore esi
Ian Rogers7caad772012-03-30 01:07:54 -0700253 // Swap EDI callee save with code pointer.
254 xchgl %edi, (%esp)
255 testl %eax, %eax // Branch forward if exception pending.
256 jz 1f
257 // Tail call to intended method.
258 ret
2591:
jeffhao20b5c6c2012-05-21 14:15:18 -0700260 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers5793fea2013-02-14 13:33:34 -0800261 .cfi_adjust_cfa_offset -4
Ian Rogers7caad772012-03-30 01:07:54 -0700262 DELIVER_PENDING_EXCEPTION
Ian Rogersaeeada42013-02-13 11:28:34 -0800263 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700264END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700265
Logan Chien8dbb7082013-01-25 20:31:17 +0800266INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
267INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700268
Logan Chien8dbb7082013-01-25 20:31:17 +0800269INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
270INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
271INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
272INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700273
Jeff Hao5d917302013-02-27 17:57:33 -0800274 /*
Jeff Hao6474d192013-03-26 14:08:09 -0700275 * Quick invocation stub.
276 * On entry:
277 * [sp] = return address
278 * [sp + 4] = method pointer
279 * [sp + 8] = argument array or NULL for no argument methods
280 * [sp + 12] = size of argument array in bytes
281 * [sp + 16] = (managed) thread pointer
282 * [sp + 20] = JValue* result
283 * [sp + 24] = result type char
Jeff Hao5d917302013-02-27 17:57:33 -0800284 */
285DEFINE_FUNCTION art_quick_invoke_stub
286 PUSH ebp // save ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800287 .cfi_rel_offset ebp, -8
Jeff Hao5d917302013-02-27 17:57:33 -0800288 PUSH ebx // save ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800289 .cfi_rel_offset ebx, -12
Jeff Hao5d917302013-02-27 17:57:33 -0800290 mov %esp, %ebp // copy value of stack pointer into base pointer
291 .cfi_def_cfa_register ebp
292 mov 20(%ebp), %ebx // get arg array size
293 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
Jeff Hao6474d192013-03-26 14:08:09 -0700294 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes
Jeff Hao5d917302013-02-27 17:57:33 -0800295 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
296 subl %ebx, %esp // reserve stack space for argument array
297 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
298 pushl 20(%ebp) // push size of region to memcpy
299 pushl 16(%ebp) // push arg array as source of memcpy
300 pushl %eax // push stack pointer as destination of memcpy
301 call SYMBOL(memcpy) // (void*, const void*, size_t)
302 addl LITERAL(12), %esp // pop arguments to memcpy
303 movl LITERAL(0), (%esp) // store NULL for method*
304 mov 12(%ebp), %eax // move method pointer into eax
305 mov 4(%esp), %ecx // copy arg1 into ecx
306 mov 8(%esp), %edx // copy arg2 into edx
307 mov 12(%esp), %ebx // copy arg3 into ebx
Ian Rogers225ade22013-03-18 17:45:44 -0700308 call *METHOD_CODE_OFFSET(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800309 mov %ebp, %esp // restore stack pointer
Dave Allisonbbb32c22013-11-05 18:25:18 -0800310 .cfi_def_cfa_register esp
Jeff Hao5d917302013-02-27 17:57:33 -0800311 POP ebx // pop ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800312 .cfi_restore ebx
Jeff Hao5d917302013-02-27 17:57:33 -0800313 POP ebp // pop ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800314 .cfi_restore ebp
Jeff Hao5d917302013-02-27 17:57:33 -0800315 mov 20(%esp), %ecx // get result pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700316 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D'
317 je return_double_quick
318 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F'
319 je return_float_quick
Jeff Hao5d917302013-02-27 17:57:33 -0800320 mov %eax, (%ecx) // store the result
321 mov %edx, 4(%ecx) // store the other half of the result
Jeff Hao6474d192013-03-26 14:08:09 -0700322 ret
323return_double_quick:
324return_float_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800325 movsd %xmm0, (%ecx) // store the floating point result
326 ret
327END_FUNCTION art_quick_invoke_stub
328
Ian Rogersd36c52e2012-04-09 16:29:25 -0700329MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800330 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700331 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
332 mov %esp, %edx // remember SP
333 // Outgoing argument set up
334 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800335 .cfi_adjust_cfa_offset 8
336 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700337 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800338 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700339 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
340 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800341 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700342 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700343 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800344 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700345END_MACRO
346
347MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800348 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700349 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
350 mov %esp, %edx // remember SP
351 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800352 PUSH eax // push padding
353 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700354 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800355 .cfi_adjust_cfa_offset 4
356 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700357 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
358 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800359 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700360 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700361 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800362 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700363END_MACRO
364
365MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800366 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700367 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
368 mov %esp, %edx // remember SP
369 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800370 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700371 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800372 .cfi_adjust_cfa_offset 4
373 PUSH ecx // pass arg2
374 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700375 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700376 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800377 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700378 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700379 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800380 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700381END_MACRO
382
Ian Rogersd36c52e2012-04-09 16:29:25 -0700383MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800384 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700385 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
386 mov %esp, %ebx // remember SP
387 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700388 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800389 .cfi_adjust_cfa_offset 12
390 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700391 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800392 .cfi_adjust_cfa_offset 4
393 PUSH edx // pass arg3
394 PUSH ecx // pass arg2
395 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700396 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700397 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800398 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700399 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700400 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800401 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700402END_MACRO
403
Mathieu Chartier590fee92013-09-13 13:46:47 -0700404MACRO0(RETURN_IF_RESULT_IS_NON_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700405 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700406 jz 1f // if eax == 0 goto 1
407 ret // return
4081: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700409 DELIVER_PENDING_EXCEPTION
410END_MACRO
411
Ian Rogersd36c52e2012-04-09 16:29:25 -0700412MACRO0(RETURN_IF_EAX_ZERO)
413 testl %eax, %eax // eax == 0 ?
414 jnz 1f // if eax != 0 goto 1
415 ret // return
4161: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700417 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700418END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700419
jeffhaod66a8752012-05-22 15:30:16 -0700420MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
421 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
422 testl %ebx, %ebx // ebx == 0 ?
423 jnz 1f // if ebx != 0 goto 1
424 ret // return
4251: // deliver exception on current thread
426 DELIVER_PENDING_EXCEPTION
427END_MACRO
428
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800429#include "arch/quick_alloc_entrypoints.S"
Ian Rogersd36c52e2012-04-09 16:29:25 -0700430
Mathieu Chartier590fee92013-09-13 13:46:47 -0700431TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO
432TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO
433TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO
434TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700435
Ian Rogers468532e2013-08-05 10:56:33 -0700436TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700437
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700438DEFINE_FUNCTION art_quick_lock_object
439 testl %eax, %eax // null check object/eax
440 jz slow_lock
441retry_lock:
442 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700443 test LITERAL(0xC0000000), %ecx // test the 2 high bits.
444 jne slow_lock // slow path if either of the two high bits are set.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700445 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
446 test %ecx, %ecx
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700447 jnz already_thin // lock word contains a thin lock
448 // unlocked case - %edx holds thread id with count of 0
449 movl %eax, %ecx // remember object in case of retry
450 xor %eax, %eax // eax == 0 for comparison with lock word in cmpxchg
451 lock cmpxchg %edx, LOCK_WORD_OFFSET(%ecx)
452 jnz cmpxchg_fail // cmpxchg failed retry
453 ret
454cmpxchg_fail:
455 movl %ecx, %eax // restore eax
456 jmp retry_lock
457already_thin:
458 cmpw %ax, %dx // do we hold the lock already?
459 jne slow_lock
460 addl LITERAL(65536), %eax // increment recursion count
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700461 test LITERAL(0xC0000000), %eax // overflowed if either of top two bits are set
462 jne slow_lock // count overflowed so go slow
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700463 movl %eax, LOCK_WORD_OFFSET(%ecx) // update lockword, cmpxchg not necessary as we hold lock
464 ret
465slow_lock:
466 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
467 mov %esp, %edx // remember SP
468 // Outgoing argument set up
469 PUSH eax // push padding
470 PUSH edx // pass SP
471 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
472 .cfi_adjust_cfa_offset 4
473 PUSH eax // pass object
474 call artLockObjectFromCode // artLockObjectFromCode(object, Thread*, SP)
475 addl MACRO_LITERAL(16), %esp // pop arguments
476 .cfi_adjust_cfa_offset -16
477 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
478 RETURN_IF_EAX_ZERO
479END_FUNCTION art_quick_lock_object
480
481DEFINE_FUNCTION art_quick_unlock_object
482 testl %eax, %eax // null check object/eax
483 jz slow_unlock
484 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
485 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
486 test %ecx, %ecx
487 jb slow_unlock // lock word contains a monitor
488 cmpw %cx, %dx // does the thread id match?
489 jne slow_unlock
490 cmpl LITERAL(65536), %ecx
491 jae recursive_thin_unlock
492 movl LITERAL(0), LOCK_WORD_OFFSET(%eax)
493 ret
494recursive_thin_unlock:
495 subl LITERAL(65536), %ecx
496 mov %ecx, LOCK_WORD_OFFSET(%eax)
497 ret
498slow_unlock:
499 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
500 mov %esp, %edx // remember SP
501 // Outgoing argument set up
502 PUSH eax // push padding
503 PUSH edx // pass SP
504 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
505 .cfi_adjust_cfa_offset 4
506 PUSH eax // pass object
507 call artUnlockObjectFromCode // artUnlockObjectFromCode(object, Thread*, SP)
508 addl MACRO_LITERAL(16), %esp // pop arguments
509 .cfi_adjust_cfa_offset -16
510 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
511 RETURN_IF_EAX_ZERO
512END_FUNCTION art_quick_unlock_object
513
Ian Rogers468532e2013-08-05 10:56:33 -0700514DEFINE_FUNCTION art_quick_is_assignable
Ian Rogersaeeada42013-02-13 11:28:34 -0800515 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -0700516 PUSH ecx // pass arg2 - obj->klass
517 PUSH eax // pass arg1 - checked class
518 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700519 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800520 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700521 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700522END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -0700523
Ian Rogersa9a82542013-10-04 11:17:26 -0700524DEFINE_FUNCTION art_quick_check_cast
525 PUSH eax // alignment padding
526 PUSH ecx // pass arg2 - obj->klass
Dave Allisonbbb32c22013-11-05 18:25:18 -0800527 .cfi_rel_offset ecx, -12
Ian Rogersa9a82542013-10-04 11:17:26 -0700528 PUSH eax // pass arg1 - checked class
Dave Allisonbbb32c22013-11-05 18:25:18 -0800529 .cfi_rel_offset eax, -16
Ian Rogersa9a82542013-10-04 11:17:26 -0700530 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
531 testl %eax, %eax
532 jz 1f // jump forward if not assignable
533 addl LITERAL(12), %esp // pop arguments
534 .cfi_adjust_cfa_offset -12
535 ret
5361:
537 POP eax // pop arguments
Dave Allisonbbb32c22013-11-05 18:25:18 -0800538 .cfi_restore eax
Ian Rogersa9a82542013-10-04 11:17:26 -0700539 POP ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800540 .cfi_restore ecx
Ian Rogersa9a82542013-10-04 11:17:26 -0700541 addl LITERAL(4), %esp
542 .cfi_adjust_cfa_offset -12
543 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
544 mov %esp, %edx
545 // Outgoing argument set up
546 PUSH edx // pass SP
547 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
548 .cfi_adjust_cfa_offset 4
549 PUSH ecx // pass arg2
550 PUSH eax // pass arg1
551 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*, SP)
552 int3 // unreached
553END_FUNCTION art_quick_check_cast
554
555 /*
556 * Entry from managed code for array put operations of objects where the value being stored
557 * needs to be checked for compatibility.
558 * eax = array, ecx = index, edx = value
559 */
560DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
561 testl %eax, %eax
562 jnz art_quick_aput_obj_with_bound_check
563 jmp art_quick_throw_null_pointer_exception
564END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
565
566DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
567 movl ARRAY_LENGTH_OFFSET(%eax), %ebx
568 cmpl %ebx, %ecx
569 jb art_quick_aput_obj
570 mov %ecx, %eax
571 mov %ebx, %ecx
572 jmp art_quick_throw_array_bounds
573END_FUNCTION art_quick_aput_obj_with_bound_check
574
575DEFINE_FUNCTION art_quick_aput_obj
576 test %edx, %edx // store of null
577 jz do_aput_null
578 movl CLASS_OFFSET(%eax), %ebx
579 movl CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx
580 cmpl CLASS_OFFSET(%edx), %ebx // value's type == array's component type - trivial assignability
581 jne check_assignability
582do_aput:
583 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
584 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
585 shrl LITERAL(7), %eax
586 movb %dl, (%edx, %eax)
587 ret
588do_aput_null:
589 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
590 ret
591check_assignability:
592 PUSH eax // save arguments
593 PUSH ecx
594 PUSH edx
595 subl LITERAL(8), %esp // alignment padding
596 .cfi_adjust_cfa_offset 8
597 pushl CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
598 .cfi_adjust_cfa_offset 4
599 PUSH ebx // pass arg1 - component type of the array
600 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
601 addl LITERAL(16), %esp // pop arguments
602 .cfi_adjust_cfa_offset -16
603 testl %eax, %eax
604 jz throw_array_store_exception
605 POP edx
606 POP ecx
607 POP eax
608 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
609 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
610 shrl LITERAL(7), %eax
611 movb %dl, (%edx, %eax)
612 ret
613throw_array_store_exception:
614 POP edx
615 POP ecx
616 POP eax
617 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
618 mov %esp, %ecx
619 // Outgoing argument set up
620 PUSH ecx // pass SP
621 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
622 .cfi_adjust_cfa_offset 4
623 PUSH edx // pass arg2 - value
624 PUSH eax // pass arg1 - array
625 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*, SP)
626 int3 // unreached
627END_FUNCTION art_quick_aput_obj
628
Logan Chien8dbb7082013-01-25 20:31:17 +0800629DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800630 PUSH edx // pass arg3
631 PUSH ecx // pass arg2
632 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700633 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700634 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800635 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700636 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800637END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700638
Logan Chien8dbb7082013-01-25 20:31:17 +0800639NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700640
Ian Rogers468532e2013-08-05 10:56:33 -0700641DEFINE_FUNCTION art_quick_fmod
jeffhao1395b1e2012-06-13 18:05:13 -0700642 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800643 .cfi_adjust_cfa_offset 12
644 PUSH ebx // pass arg4 b.hi
645 PUSH edx // pass arg3 b.lo
646 PUSH ecx // pass arg2 a.hi
647 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700648 call SYMBOL(fmod) // (jdouble a, jdouble b)
649 fstpl (%esp) // pop return value off fp stack
650 movsd (%esp), %xmm0 // place into %xmm0
651 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800652 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700653 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700654END_FUNCTION art_quick_fmod
jeffhao292188d2012-05-17 15:45:04 -0700655
Ian Rogers468532e2013-08-05 10:56:33 -0700656DEFINE_FUNCTION art_quick_fmodf
Ian Rogersaeeada42013-02-13 11:28:34 -0800657 PUSH eax // alignment padding
658 PUSH ecx // pass arg2 b
659 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700660 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700661 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700662 movss (%esp), %xmm0 // place into %xmm0
663 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800664 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700665 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700666END_FUNCTION art_quick_fmodf
jeffhao292188d2012-05-17 15:45:04 -0700667
Ian Rogers468532e2013-08-05 10:56:33 -0700668DEFINE_FUNCTION art_quick_l2d
Ian Rogers5793fea2013-02-14 13:33:34 -0800669 PUSH ecx // push arg2 a.hi
670 PUSH eax // push arg1 a.lo
671 fildll (%esp) // load as integer and push into st0
672 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700673 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800674 addl LITERAL(8), %esp // pop arguments
675 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700676 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700677END_FUNCTION art_quick_l2d
jeffhao41005dd2012-05-09 17:58:52 -0700678
Ian Rogers468532e2013-08-05 10:56:33 -0700679DEFINE_FUNCTION art_quick_l2f
Ian Rogers5793fea2013-02-14 13:33:34 -0800680 PUSH ecx // push arg2 a.hi
681 PUSH eax // push arg1 a.lo
682 fildll (%esp) // load as integer and push into st0
683 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700684 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800685 addl LITERAL(8), %esp // pop argument
686 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700687 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700688END_FUNCTION art_quick_l2f
jeffhao41005dd2012-05-09 17:58:52 -0700689
Ian Rogers468532e2013-08-05 10:56:33 -0700690DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800691 PUSH eax // alignment padding
692 PUSH ecx // pass arg2 a.hi
693 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700694 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700695 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800696 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700697 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700698END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700699
Ian Rogers468532e2013-08-05 10:56:33 -0700700DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700701 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800702 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800703 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700704 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700705 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800706 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700707 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700708END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700709
Ian Rogers468532e2013-08-05 10:56:33 -0700710DEFINE_FUNCTION art_quick_idivmod
jeffhao174651d2012-04-19 15:27:22 -0700711 cmpl LITERAL(0x80000000), %eax
712 je check_arg2 // special case
713args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700714 cdq // edx:eax = sign extend eax
715 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700716 ret
jeffhao174651d2012-04-19 15:27:22 -0700717check_arg2:
718 cmpl LITERAL(-1), %ecx
719 jne args_ok
720 xorl %edx, %edx
721 ret // eax already holds min int
Ian Rogers468532e2013-08-05 10:56:33 -0700722END_FUNCTION art_quick_idivmod
Ian Rogers7caad772012-03-30 01:07:54 -0700723
Ian Rogers468532e2013-08-05 10:56:33 -0700724DEFINE_FUNCTION art_quick_ldiv
Ian Rogersa9a82542013-10-04 11:17:26 -0700725 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800726 .cfi_adjust_cfa_offset 12
727 PUSH ebx // pass arg4 b.hi
728 PUSH edx // pass arg3 b.lo
729 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700730 PUSH eax // pass arg1 a.lo
731 call SYMBOL(artLdiv) // (jlong a, jlong b)
732 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800733 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700734 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700735END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700736
Ian Rogersa9a82542013-10-04 11:17:26 -0700737DEFINE_FUNCTION art_quick_lmod
738 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800739 .cfi_adjust_cfa_offset 12
740 PUSH ebx // pass arg4 b.hi
741 PUSH edx // pass arg3 b.lo
742 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700743 PUSH eax // pass arg1 a.lo
744 call SYMBOL(artLmod) // (jlong a, jlong b)
745 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800746 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700747 ret
Ian Rogersa9a82542013-10-04 11:17:26 -0700748END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700749
Ian Rogers468532e2013-08-05 10:56:33 -0700750DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800751 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
752 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
753 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
754 add %ebx, %ecx
755 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700756 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700757END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700758
Ian Rogers468532e2013-08-05 10:56:33 -0700759DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700760 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700761 xchg %edx, %ecx
762 shld %cl,%eax,%edx
763 shl %cl,%eax
764 test LITERAL(32), %cl
765 jz 1f
766 mov %eax, %edx
767 xor %eax, %eax
7681:
769 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700770END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700771
Ian Rogers468532e2013-08-05 10:56:33 -0700772DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700773 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700774 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700775 shrd %cl,%edx,%eax
776 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700777 test LITERAL(32),%cl
778 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700779 mov %edx, %eax
780 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07007811:
782 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700783END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700784
Ian Rogers468532e2013-08-05 10:56:33 -0700785DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700786 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700787 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700788 shrd %cl,%edx,%eax
789 shr %cl,%edx
790 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700791 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700792 mov %edx, %eax
793 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07007941:
795 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700796END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700797
Ian Rogers468532e2013-08-05 10:56:33 -0700798DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700799 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
800 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700801 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800802 .cfi_adjust_cfa_offset 8
803 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700804 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800805 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700806 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800807 PUSH ebx // pass referrer
808 PUSH edx // pass new_val
809 PUSH ecx // pass object
810 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700811 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700812 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800813 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700814 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
815 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700816END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700817
Ian Rogers468532e2013-08-05 10:56:33 -0700818DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800819 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700820 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800821 .cfi_adjust_cfa_offset 8
822 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700823 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700824 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800825 .cfi_adjust_cfa_offset 4
826 PUSH ebx // pass high half of new_val
827 PUSH edx // pass low half of new_val
828 PUSH ecx // pass object
829 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700830 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700831 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800832 .cfi_adjust_cfa_offset -32
833 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700834 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700835END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700836
Ian Rogers468532e2013-08-05 10:56:33 -0700837DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800838 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700839 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700840 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800841 .cfi_adjust_cfa_offset 8
842 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700843 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800844 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700845 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800846 PUSH ebx // pass referrer
847 PUSH edx // pass new_val
848 PUSH ecx // pass object
849 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700850 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700851 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800852 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700853 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
854 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700855END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700856
Ian Rogers468532e2013-08-05 10:56:33 -0700857DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800858 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700859 mov %esp, %ebx // remember SP
860 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700861 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800862 .cfi_adjust_cfa_offset 12
863 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700864 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800865 .cfi_adjust_cfa_offset 4
866 PUSH edx // pass referrer
867 PUSH ecx // pass object
868 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700869 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700870 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800871 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700872 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700873 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700874END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700875
Ian Rogers468532e2013-08-05 10:56:33 -0700876DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700877 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
878 mov %esp, %ebx // remember SP
879 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700880 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800881 .cfi_adjust_cfa_offset 12
882 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700883 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800884 .cfi_adjust_cfa_offset 4
885 PUSH edx // pass referrer
886 PUSH ecx // pass object
887 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700888 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700889 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800890 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700891 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700892 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700893END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700894
Ian Rogers468532e2013-08-05 10:56:33 -0700895DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700896 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
897 mov %esp, %ebx // remember SP
898 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700899 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800900 .cfi_adjust_cfa_offset 12
901 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700902 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800903 .cfi_adjust_cfa_offset 4
904 PUSH edx // pass referrer
905 PUSH ecx // pass object
906 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700907 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700908 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800909 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700910 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700911 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700912END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700913
Ian Rogers468532e2013-08-05 10:56:33 -0700914DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700915 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
916 mov %esp, %ebx // remember SP
917 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700918 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800919 .cfi_adjust_cfa_offset 12
920 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700921 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800922 .cfi_adjust_cfa_offset 4
923 PUSH edx // pass referrer
924 PUSH ecx // pass new_val
925 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700926 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700927 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800928 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700929 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
930 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700931END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700932
Ian Rogers468532e2013-08-05 10:56:33 -0700933DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800934 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700935 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700936 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800937 .cfi_adjust_cfa_offset 8
938 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700939 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800940 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700941 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800942 PUSH edx // pass high half of new_val
943 PUSH ecx // pass low half of new_val
944 PUSH ebx // pass referrer
945 PUSH eax // pass field_idx
946 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700947 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800948 .cfi_adjust_cfa_offset -32
949 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700950 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700951END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700952
Ian Rogers468532e2013-08-05 10:56:33 -0700953DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800954 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700955 mov %esp, %ebx // remember SP
956 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700957 subl LITERAL(12), %esp // alignment padding
Ian Rogers62d6c772013-02-27 08:32:07 -0800958 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800959 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700960 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800961 .cfi_adjust_cfa_offset 4
962 PUSH edx // pass referrer
963 PUSH ecx // pass new_val
964 PUSH eax // pass field_idx
965 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700966 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800967 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700968 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700969END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700970
Ian Rogers468532e2013-08-05 10:56:33 -0700971DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700972 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
973 mov %esp, %edx // remember SP
974 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800975 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700976 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800977 .cfi_adjust_cfa_offset 4
978 PUSH ecx // pass referrer
979 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700980 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700981 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800982 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700983 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700984 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700985END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700986
Ian Rogers468532e2013-08-05 10:56:33 -0700987DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800988 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700989 mov %esp, %edx // remember SP
990 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800991 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700992 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800993 .cfi_adjust_cfa_offset 4
994 PUSH ecx // pass referrer
995 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700996 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700997 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800998 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700999 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001000 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001001END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001002
Ian Rogers468532e2013-08-05 10:56:33 -07001003DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001004 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
1005 mov %esp, %edx // remember SP
1006 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001007 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -07001008 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001009 .cfi_adjust_cfa_offset 4
1010 PUSH ecx // pass referrer
1011 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -07001012 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001013 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001014 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -07001015 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001016 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001017END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -07001018
Logan Chien8dbb7082013-01-25 20:31:17 +08001019DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -08001020 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -08001021 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001022 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001023 .cfi_adjust_cfa_offset 4
1024 PUSH ecx // pass receiver
1025 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -07001026 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001027 movd %eax, %xmm0 // place return value also into floating point return value
1028 movd %edx, %xmm1
1029 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -07001030 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001031 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -07001032 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001033END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001034
Jeff Hao88474b42013-10-23 16:24:40 -07001035 /*
1036 * Called to resolve an imt conflict. xmm0 is a hidden argument that holds the target method's
1037 * dex method index.
1038 */
1039DEFINE_FUNCTION art_quick_imt_conflict_trampoline
1040 PUSH ecx
1041 movl 8(%esp), %eax // load caller Method*
1042 movl METHOD_DEX_CACHE_METHODS_OFFSET(%eax), %eax // load dex_cache_resolved_methods
1043 movd %xmm0, %ecx // get target method index stored in xmm0
1044 movl OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4), %eax // load the target method
1045 POP ecx
1046 jmp art_quick_invoke_interface_trampoline
1047END_FUNCTION art_quick_imt_conflict_trampoline
1048
Ian Rogers468532e2013-08-05 10:56:33 -07001049DEFINE_FUNCTION art_quick_resolution_trampoline
1050 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1051 PUSH esp // pass SP
1052 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1053 .cfi_adjust_cfa_offset 4
1054 PUSH ecx // pass receiver
1055 PUSH eax // pass method
1056 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
1057 movl %eax, %edi // remember code pointer in EDI
1058 addl LITERAL(16), %esp // pop arguments
1059 test %eax, %eax // if code pointer is NULL goto deliver pending exception
1060 jz 1f
1061 POP eax // called method
1062 POP ecx // restore args
1063 POP edx
1064 POP ebx
1065 POP ebp // restore callee saves except EDI
1066 POP esi
1067 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
1068 ret // tail call into method
10691:
1070 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1071 DELIVER_PENDING_EXCEPTION
1072END_FUNCTION art_quick_resolution_trampoline
1073
1074DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -08001075 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001076 mov %esp, %edx // remember SP
1077 PUSH eax // alignment padding
1078 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001079 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001080 .cfi_adjust_cfa_offset 4
1081 PUSH eax // pass method
Ian Rogers468532e2013-08-05 10:56:33 -07001082 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -08001083 movd %eax, %xmm0 // place return value also into floating point return value
1084 movd %edx, %xmm1
1085 punpckldq %xmm1, %xmm0
Mathieu Chartier19841522013-10-22 11:29:00 -07001086 addl LITERAL(16), %esp // pop arguments
1087 .cfi_adjust_cfa_offset -16
1088 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08001089 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001090END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001091
jeffhao7e4fcb82013-01-10 18:11:08 -08001092 /*
1093 * Routine that intercepts method calls and returns.
1094 */
Ian Rogers468532e2013-08-05 10:56:33 -07001095DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001096 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1097 movl %esp, %edx // Save SP.
1098 PUSH eax // Save eax which will be clobbered by the callee-save method.
1099 subl LITERAL(8), %esp // Align stack.
1100 .cfi_adjust_cfa_offset 8
1101 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -08001102 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001103 PUSH edx // Pass SP.
1104 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001105 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001106 PUSH ecx // Pass receiver.
1107 PUSH eax // Pass Method*.
1108 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
1109 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
1110 movl 28(%esp), %edi // Restore edi.
1111 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Ian Rogers468532e2013-08-05 10:56:33 -07001112 movl LITERAL(SYMBOL(art_quick_instrumentation_exit)), 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001113 // Place instrumentation exit as return pc.
1114 movl (%esp), %eax // Restore eax.
1115 movl 8(%esp), %ecx // Restore ecx.
1116 movl 12(%esp), %edx // Restore edx.
1117 movl 16(%esp), %ebx // Restore ebx.
1118 movl 20(%esp), %ebp // Restore ebp.
1119 movl 24(%esp), %esi // Restore esi.
1120 addl LITERAL(28), %esp // Wind stack back upto code*.
1121 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001122END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001123
Ian Rogers468532e2013-08-05 10:56:33 -07001124DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001125 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
1126 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1127 mov %esp, %ecx // Remember SP
1128 subl LITERAL(8), %esp // Save float return value.
1129 .cfi_adjust_cfa_offset 8
1130 movd %xmm0, (%esp)
1131 PUSH edx // Save gpr return value.
1132 PUSH eax
1133 subl LITERAL(8), %esp // Align stack
1134 movd %xmm0, (%esp)
1135 subl LITERAL(8), %esp // Pass float return value.
1136 .cfi_adjust_cfa_offset 8
1137 movd %xmm0, (%esp)
1138 PUSH edx // Pass gpr return value.
1139 PUSH eax
1140 PUSH ecx // Pass SP.
1141 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -08001142 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001143 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
1144 mov %eax, %ecx // Move returned link register.
1145 addl LITERAL(32), %esp // Pop arguments.
1146 .cfi_adjust_cfa_offset -32
1147 movl %edx, %ebx // Move returned link register for deopt
1148 // (ebx is pretending to be our LR).
1149 POP eax // Restore gpr return value.
1150 POP edx
1151 movd (%esp), %xmm0 // Restore fpr return value.
1152 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -08001153 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001154 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1155 addl LITERAL(4), %esp // Remove fake return pc.
1156 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001157END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001158
jeffhao7e4fcb82013-01-10 18:11:08 -08001159 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001160 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1161 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001162 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001163DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001164 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001165 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001166 mov %esp, %ecx // Remember SP.
1167 subl LITERAL(8), %esp // Align stack.
1168 .cfi_adjust_cfa_offset 8
1169 PUSH ecx // Pass SP.
1170 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001171 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001172 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
1173 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001174END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001175
jeffhao86e46712012-08-08 17:30:59 -07001176 /*
1177 * String's indexOf.
1178 *
1179 * On entry:
1180 * eax: string object (known non-null)
1181 * ecx: char to match (known <= 0xFFFF)
1182 * edx: Starting offset in string data
1183 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001184DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001185 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001186 mov STRING_COUNT_OFFSET(%eax), %ebx
1187 mov STRING_VALUE_OFFSET(%eax), %edi
1188 mov STRING_OFFSET_OFFSET(%eax), %eax
1189 testl %edx, %edx // check if start < 0
1190 jl clamp_min
1191clamp_done:
1192 cmpl %ebx, %edx // check if start >= count
1193 jge not_found
1194 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1195 mov %edi, %eax // save a copy in eax to later compute result
1196 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1197 subl %edx, %ebx // compute iteration count
1198 /*
1199 * At this point we have:
1200 * eax: original start of string data
1201 * ecx: char to compare
1202 * ebx: length to compare
1203 * edi: start of data to test
1204 */
1205 mov %eax, %edx
1206 mov %ecx, %eax // put char to match in %eax
1207 mov %ebx, %ecx // put length to compare in %ecx
1208 repne scasw // find %ax, starting at [%edi], up to length %ecx
1209 jne not_found
1210 subl %edx, %edi
1211 sar LITERAL(1), %edi
1212 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1213 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001214 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001215 ret
1216 .balign 16
1217not_found:
1218 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001219 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001220 ret
1221clamp_min:
1222 xor %edx, %edx // clamp start to 0
1223 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001224END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001225
1226 /*
1227 * String's compareTo.
1228 *
1229 * On entry:
1230 * eax: this string object (known non-null)
1231 * ecx: comp string object (known non-null)
1232 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001233DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001234 PUSH esi // push callee save reg
1235 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001236 mov STRING_COUNT_OFFSET(%eax), %edx
1237 mov STRING_COUNT_OFFSET(%ecx), %ebx
1238 mov STRING_VALUE_OFFSET(%eax), %esi
1239 mov STRING_VALUE_OFFSET(%ecx), %edi
1240 mov STRING_OFFSET_OFFSET(%eax), %eax
1241 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1242 /* Build pointers to the start of string data */
1243 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1244 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1245 /* Calculate min length and count diff */
1246 mov %edx, %ecx
1247 mov %edx, %eax
1248 subl %ebx, %eax
1249 cmovg %ebx, %ecx
1250 /*
1251 * At this point we have:
1252 * eax: value to return if first part of strings are equal
1253 * ecx: minimum among the lengths of the two strings
1254 * esi: pointer to this string data
1255 * edi: pointer to comp string data
1256 */
1257 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1258 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001259 POP edi // pop callee save reg
1260 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001261 ret
1262 .balign 16
1263not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001264 movzwl -2(%esi), %eax // get last compared char from this string
1265 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001266 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001267 POP edi // pop callee save reg
1268 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001269 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001270END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001271
Elliott Hughes787ec202012-03-29 17:14:15 -07001272 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001273UNIMPLEMENTED art_quick_memcmp16