yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
| 32 | #include "bootstrapper.h" |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 33 | #include "builtins-decls.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 34 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 35 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 36 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 37 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 38 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 39 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 40 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 41 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 42 | |
| 43 | namespace v8 { |
| 44 | namespace internal { |
| 45 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 46 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 47 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 48 | Isolate* isolate, |
| 49 | CodeStubInterfaceDescriptor* descriptor) { |
| 50 | static Register registers[] = { eax, ebx, ecx }; |
| 51 | descriptor->register_param_count_ = 3; |
| 52 | descriptor->register_params_ = registers; |
| 53 | descriptor->stack_parameter_count_ = NULL; |
| 54 | descriptor->deoptimization_handler_ = |
| 55 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 56 | } |
| 57 | |
| 58 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 59 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 60 | Isolate* isolate, |
| 61 | CodeStubInterfaceDescriptor* descriptor) { |
| 62 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 63 | descriptor->register_param_count_ = 4; |
| 64 | descriptor->register_params_ = registers; |
| 65 | descriptor->stack_parameter_count_ = NULL; |
| 66 | descriptor->deoptimization_handler_ = |
| 67 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 68 | } |
| 69 | |
| 70 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 71 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 72 | Isolate* isolate, |
| 73 | CodeStubInterfaceDescriptor* descriptor) { |
| 74 | static Register registers[] = { edx, ecx }; |
| 75 | descriptor->register_param_count_ = 2; |
| 76 | descriptor->register_params_ = registers; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 77 | descriptor->stack_parameter_count_ = NULL; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 78 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 79 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 83 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 84 | Isolate* isolate, |
| 85 | CodeStubInterfaceDescriptor* descriptor) { |
| 86 | static Register registers[] = { edx, ecx, eax }; |
| 87 | descriptor->register_param_count_ = 3; |
| 88 | descriptor->register_params_ = registers; |
| 89 | descriptor->deoptimization_handler_ = |
| 90 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 91 | } |
| 92 | |
| 93 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 94 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 95 | Isolate* isolate, |
| 96 | CodeStubInterfaceDescriptor* descriptor) { |
| 97 | static Register registers[] = { eax, ebx }; |
| 98 | descriptor->register_param_count_ = 2; |
| 99 | descriptor->register_params_ = registers; |
| 100 | descriptor->deoptimization_handler_ = |
| 101 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 102 | } |
| 103 | |
| 104 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 105 | static void InitializeArrayConstructorDescriptor(Isolate* isolate, |
| 106 | CodeStubInterfaceDescriptor* descriptor) { |
| 107 | // register state |
| 108 | // edi -- constructor function |
| 109 | // ebx -- type info cell with elements kind |
| 110 | // eax -- number of arguments to the constructor function |
| 111 | static Register registers[] = { edi, ebx }; |
| 112 | descriptor->register_param_count_ = 2; |
| 113 | // stack param count needs (constructor pointer, and single argument) |
| 114 | descriptor->stack_parameter_count_ = &eax; |
| 115 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 116 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 117 | descriptor->deoptimization_handler_ = |
| 118 | FUNCTION_ADDR(ArrayConstructor_StubFailure); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 123 | Isolate* isolate, |
| 124 | CodeStubInterfaceDescriptor* descriptor) { |
| 125 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 130 | Isolate* isolate, |
| 131 | CodeStubInterfaceDescriptor* descriptor) { |
| 132 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 137 | Isolate* isolate, |
| 138 | CodeStubInterfaceDescriptor* descriptor) { |
| 139 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 140 | } |
| 141 | |
| 142 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 143 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 144 | |
| 145 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 146 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 147 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 148 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 149 | __ ret(0); |
| 150 | |
| 151 | __ bind(&check_heap_number); |
| 152 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 153 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 154 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 155 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 156 | __ ret(0); |
| 157 | |
| 158 | __ bind(&call_builtin); |
| 159 | __ pop(ecx); // Pop return address. |
| 160 | __ push(eax); |
| 161 | __ push(ecx); // Push return address. |
| 162 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 163 | } |
| 164 | |
| 165 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 166 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 167 | // Create a new closure from the given function info in new |
| 168 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 169 | Counters* counters = masm->isolate()->counters(); |
| 170 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 171 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 172 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 173 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 174 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 175 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 176 | // Get the function info from the stack. |
| 177 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 178 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 179 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 180 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 181 | // Compute the function map in the current native context and set that |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 182 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 183 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 184 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 185 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 186 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 187 | |
| 188 | // Initialize the rest of the function. We don't have to update the |
| 189 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 190 | Factory* factory = masm->isolate()->factory(); |
| 191 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 192 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 193 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 194 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 195 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 196 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 197 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 198 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 199 | |
| 200 | // Initialize the code pointer in the function to be the one |
| 201 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 202 | // But first check if there is an optimized version for our context. |
| 203 | Label check_optimized; |
| 204 | Label install_unoptimized; |
| 205 | if (FLAG_cache_optimized_code) { |
| 206 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 207 | __ test(ebx, ebx); |
| 208 | __ j(not_zero, &check_optimized, Label::kNear); |
| 209 | } |
| 210 | __ bind(&install_unoptimized); |
| 211 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 212 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 213 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 214 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 215 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 216 | |
| 217 | // Return and remove the on-stack parameter. |
| 218 | __ ret(1 * kPointerSize); |
| 219 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 220 | __ bind(&check_optimized); |
| 221 | |
| 222 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 223 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 224 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 225 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 226 | // Map must never be empty, so check the first elements. |
| 227 | Label install_optimized; |
| 228 | // Speculatively move code object into edx. |
| 229 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 230 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 231 | __ j(equal, &install_optimized); |
| 232 | |
| 233 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 234 | Label loop; |
| 235 | Label restore; |
| 236 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 237 | __ bind(&loop); |
| 238 | // Do not double check first entry. |
| 239 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 240 | __ j(equal, &restore); |
| 241 | __ sub(edx, Immediate(Smi::FromInt( |
| 242 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 243 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 244 | __ j(not_equal, &loop, Label::kNear); |
| 245 | // Hit: fetch the optimized code. |
| 246 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 247 | |
| 248 | __ bind(&install_optimized); |
| 249 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 250 | |
| 251 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 252 | // map and either unmangle them on marking or do nothing as the whole map is |
| 253 | // discarded on major GC anyway. |
| 254 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 255 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 256 | |
| 257 | // Now link a function into a list of optimized functions. |
| 258 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 259 | |
| 260 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 261 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 262 | |
| 263 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 264 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 265 | // it clobbers all the registers passed. |
| 266 | __ mov(edx, eax); |
| 267 | __ RecordWriteContextSlot( |
| 268 | ecx, |
| 269 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 270 | edx, |
| 271 | ebx, |
| 272 | kDontSaveFPRegs); |
| 273 | |
| 274 | // Return and remove the on-stack parameter. |
| 275 | __ ret(1 * kPointerSize); |
| 276 | |
| 277 | __ bind(&restore); |
| 278 | // Restore SharedFunctionInfo into edx. |
| 279 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 280 | __ jmp(&install_unoptimized); |
| 281 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 282 | // Create a new closure through the slower runtime call. |
| 283 | __ bind(&gc); |
| 284 | __ pop(ecx); // Temporarily remove return address. |
| 285 | __ pop(edx); |
| 286 | __ push(esi); |
| 287 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 288 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 289 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 290 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
| 294 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 295 | // Try to allocate the context in new space. |
| 296 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 297 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 298 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 299 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 300 | |
| 301 | // Get the function from the stack. |
| 302 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 303 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 304 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 305 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 306 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 307 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 308 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 309 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 310 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 311 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 312 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 313 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 314 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 315 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 316 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 317 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 318 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 319 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 320 | |
| 321 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 322 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 323 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 324 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 325 | } |
| 326 | |
| 327 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 328 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 329 | __ ret(1 * kPointerSize); |
| 330 | |
| 331 | // Need to collect. Call into runtime system. |
| 332 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 333 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 337 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 338 | // Stack layout on entry: |
| 339 | // |
| 340 | // [esp + (1 * kPointerSize)]: function |
| 341 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 342 | |
| 343 | // Try to allocate the context in new space. |
| 344 | Label gc; |
| 345 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 346 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 347 | |
| 348 | // Get the function or sentinel from the stack. |
| 349 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 350 | |
| 351 | // Get the serialized scope info from the stack. |
| 352 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 353 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 354 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 355 | Factory* factory = masm->isolate()->factory(); |
| 356 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 357 | factory->block_context_map()); |
| 358 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 359 | Immediate(Smi::FromInt(length))); |
| 360 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 361 | // If this block context is nested in the native context we get a smi |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 362 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 363 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 364 | // we still have to look up. |
| 365 | Label after_sentinel; |
| 366 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 367 | if (FLAG_debug_code) { |
| 368 | const char* message = "Expected 0 as a Smi sentinel"; |
| 369 | __ cmp(ecx, 0); |
| 370 | __ Assert(equal, message); |
| 371 | } |
| 372 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 373 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 374 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 375 | __ bind(&after_sentinel); |
| 376 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 377 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 378 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 379 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 380 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 381 | |
| 382 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 383 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 384 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 385 | |
| 386 | // Initialize the rest of the slots to the hole value. |
| 387 | if (slots_ == 1) { |
| 388 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 389 | factory->the_hole_value()); |
| 390 | } else { |
| 391 | __ mov(ebx, factory->the_hole_value()); |
| 392 | for (int i = 0; i < slots_; i++) { |
| 393 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // Return and remove the on-stack parameters. |
| 398 | __ mov(esi, eax); |
| 399 | __ ret(2 * kPointerSize); |
| 400 | |
| 401 | // Need to collect. Call into runtime system. |
| 402 | __ bind(&gc); |
| 403 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 404 | } |
| 405 | |
| 406 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 407 | // The stub expects its argument on the stack and returns its result in tos_: |
| 408 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 409 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 410 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 411 | // we cannot call anything that could cause a GC from this stub. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 412 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 413 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 414 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 415 | const Register map = edx; |
| 416 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 417 | if (!types_.IsEmpty()) { |
| 418 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 419 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 420 | |
| 421 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 422 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 423 | |
| 424 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 425 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 426 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 427 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 428 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 429 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 430 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 431 | if (types_.Contains(SMI)) { |
| 432 | // Smis: 0 -> false, all other -> true |
| 433 | Label not_smi; |
| 434 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 435 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 436 | if (!tos_.is(argument)) { |
| 437 | __ mov(tos_, argument); |
| 438 | } |
| 439 | __ ret(1 * kPointerSize); |
| 440 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 441 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 442 | // If we need a map later and have a Smi -> patch. |
| 443 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 444 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 445 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 446 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 447 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 448 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 449 | if (types_.CanBeUndetectable()) { |
| 450 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 451 | 1 << Map::kIsUndetectable); |
| 452 | // Undetectable -> false. |
| 453 | Label not_undetectable; |
| 454 | __ j(zero, ¬_undetectable, Label::kNear); |
| 455 | __ Set(tos_, Immediate(0)); |
| 456 | __ ret(1 * kPointerSize); |
| 457 | __ bind(¬_undetectable); |
| 458 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 459 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 460 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 461 | if (types_.Contains(SPEC_OBJECT)) { |
| 462 | // spec object -> true. |
| 463 | Label not_js_object; |
| 464 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 465 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 466 | // argument contains the correct return value already. |
| 467 | if (!tos_.is(argument)) { |
| 468 | __ Set(tos_, Immediate(1)); |
| 469 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 470 | __ ret(1 * kPointerSize); |
| 471 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 472 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 473 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 474 | if (types_.Contains(STRING)) { |
| 475 | // String value -> false iff empty. |
| 476 | Label not_string; |
| 477 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 478 | __ j(above_equal, ¬_string, Label::kNear); |
| 479 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 480 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 481 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 482 | } |
| 483 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 484 | if (types_.Contains(SYMBOL)) { |
| 485 | // Symbol value -> true. |
| 486 | Label not_symbol; |
| 487 | __ CmpInstanceType(map, SYMBOL_TYPE); |
| 488 | __ j(not_equal, ¬_symbol, Label::kNear); |
| 489 | __ bind(¬_symbol); |
| 490 | } |
| 491 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 492 | if (types_.Contains(HEAP_NUMBER)) { |
| 493 | // heap number -> false iff +0, -0, or NaN. |
| 494 | Label not_heap_number, false_result; |
| 495 | __ cmp(map, factory->heap_number_map()); |
| 496 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 497 | __ fldz(); |
| 498 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 499 | __ FCmp(); |
| 500 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 501 | // argument contains the correct return value already. |
| 502 | if (!tos_.is(argument)) { |
| 503 | __ Set(tos_, Immediate(1)); |
| 504 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 505 | __ ret(1 * kPointerSize); |
| 506 | __ bind(&false_result); |
| 507 | __ Set(tos_, Immediate(0)); |
| 508 | __ ret(1 * kPointerSize); |
| 509 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 510 | } |
| 511 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 512 | __ bind(&patch); |
| 513 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 517 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 518 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 519 | // store the registers in any particular way, but we do have to store and |
| 520 | // restore them. |
| 521 | __ pushad(); |
| 522 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 523 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 524 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 525 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 526 | XMMRegister reg = XMMRegister::from_code(i); |
| 527 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 528 | } |
| 529 | } |
| 530 | const int argument_count = 1; |
| 531 | |
| 532 | AllowExternalCallThatCantCauseGC scope(masm); |
| 533 | __ PrepareCallCFunction(argument_count, ecx); |
| 534 | __ mov(Operand(esp, 0 * kPointerSize), |
| 535 | Immediate(ExternalReference::isolate_address())); |
| 536 | __ CallCFunction( |
| 537 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 538 | argument_count); |
| 539 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 540 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 541 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 542 | XMMRegister reg = XMMRegister::from_code(i); |
| 543 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 544 | } |
| 545 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 546 | } |
| 547 | __ popad(); |
| 548 | __ ret(0); |
| 549 | } |
| 550 | |
| 551 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 552 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 553 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 554 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 555 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 556 | const Register argument = eax; |
| 557 | if (types_.Contains(type)) { |
| 558 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 559 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 560 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 561 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 562 | if (!result) { |
| 563 | // If we have to return zero, there is no way around clearing tos_. |
| 564 | __ Set(tos_, Immediate(0)); |
| 565 | } else if (!tos_.is(argument)) { |
| 566 | // If we have to return non-zero, we can re-use the argument if it is the |
| 567 | // same register as the result, because we never see Smi-zero here. |
| 568 | __ Set(tos_, Immediate(1)); |
| 569 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 570 | __ ret(1 * kPointerSize); |
| 571 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | |
| 576 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 577 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 578 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 579 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 580 | __ push(ecx); // Push return address. |
| 581 | // Patch the caller to an appropriate specialized stub and return the |
| 582 | // operation result to the caller of the stub. |
| 583 | __ TailCallExternalReference( |
| 584 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 585 | 3, |
| 586 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 590 | class FloatingPointHelper : public AllStatic { |
| 591 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 592 | enum ArgLocation { |
| 593 | ARGS_ON_STACK, |
| 594 | ARGS_IN_REGISTERS |
| 595 | }; |
| 596 | |
| 597 | // Code pattern for loading a floating point value. Input value must |
| 598 | // be either a smi or a heap number object (fp value). Requirements: |
| 599 | // operand in register number. Returns operand as floating point number |
| 600 | // on FPU stack. |
| 601 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 602 | |
| 603 | // Code pattern for loading floating point values. Input values must |
| 604 | // be either smi or heap number objects (fp values). Requirements: |
| 605 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 606 | // Returns operands as floating point numbers on FPU stack. |
| 607 | static void LoadFloatOperands(MacroAssembler* masm, |
| 608 | Register scratch, |
| 609 | ArgLocation arg_location = ARGS_ON_STACK); |
| 610 | |
| 611 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 612 | // Expects operands in edx, eax. |
| 613 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 614 | |
| 615 | // Test if operands are smi or number objects (fp). Requirements: |
| 616 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 617 | // operands, jumps to the non_float label otherwise. |
| 618 | static void CheckFloatOperands(MacroAssembler* masm, |
| 619 | Label* non_float, |
| 620 | Register scratch); |
| 621 | |
| 622 | // Takes the operands in edx and eax and loads them as integers in eax |
| 623 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 624 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 625 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 626 | BinaryOpIC::TypeInfo left_type, |
| 627 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 628 | Label* operand_conversion_failure); |
| 629 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 630 | // Assumes that operands are smis or heap numbers and loads them |
| 631 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 632 | // Leaves operands unchanged. |
| 633 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 634 | |
| 635 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 636 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 637 | // either operand is not a number. Operands are in edx and eax. |
| 638 | // Leaves operands unchanged. |
| 639 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 640 | |
| 641 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 642 | // Expects operands in edx, eax. |
| 643 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 644 | |
| 645 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 646 | // have int32 values. |
| 647 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 648 | Label* non_int32, |
| 649 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 650 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 651 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 652 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 653 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 654 | Label* non_int32, |
| 655 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 656 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 657 | Register scratch, |
| 658 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 662 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 663 | // is faster than using the built-in instructions on floating point registers. |
| 664 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 665 | // trashed registers. |
| 666 | static void IntegerConvert(MacroAssembler* masm, |
| 667 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 668 | bool use_sse3, |
| 669 | Label* conversion_failure) { |
| 670 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 671 | Label done, right_exponent, normal_exponent; |
| 672 | Register scratch = ebx; |
| 673 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 674 | // Get exponent word. |
| 675 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 676 | // Get exponent alone in scratch2. |
| 677 | __ mov(scratch2, scratch); |
| 678 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 679 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 680 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 681 | // Load ecx with zero. We use this either for the final shift or |
| 682 | // for the answer. |
| 683 | __ xor_(ecx, ecx); |
| 684 | // If the exponent is above 83, the number contains no significant |
| 685 | // bits in the range 0..2^31, so the result is zero. |
| 686 | static const uint32_t kResultIsZeroExponent = 83; |
| 687 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 688 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 689 | if (use_sse3) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 690 | CpuFeatureScope scope(masm, SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 691 | // Check whether the exponent is too big for a 64 bit signed integer. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 692 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 693 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 694 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 695 | // Load x87 register with heap number. |
| 696 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 697 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 698 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 699 | // Do conversion, which cannot fail because we checked the exponent. |
| 700 | __ fisttp_d(Operand(esp, 0)); |
| 701 | __ mov(ecx, Operand(esp, 0)); // Load low word of answer into ecx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 702 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 703 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 704 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 705 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 706 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 707 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 708 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 709 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 710 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 711 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 712 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 713 | // If the exponent is higher than that then go to slow case. This catches |
| 714 | // numbers that don't fit in a signed int32, infinities and NaNs. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 715 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 716 | |
| 717 | { |
| 718 | // Handle a big exponent. The only reason we have this code is that the |
| 719 | // >>> operator has a tendency to generate numbers with an exponent of 31. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 720 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 721 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 722 | __ j(not_equal, conversion_failure); |
| 723 | // We have the big exponent, typically from >>>. This means the number is |
| 724 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 725 | __ mov(scratch2, scratch); |
| 726 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 727 | // Put back the implicit 1. |
| 728 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 729 | // Shift up the mantissa bits to take up the space the exponent used to |
| 730 | // take. We just orred in the implicit bit so that took care of one and |
| 731 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 732 | // shift distance. |
| 733 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 734 | __ shl(scratch2, big_shift_distance); |
| 735 | // Get the second half of the double. |
| 736 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 737 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 738 | // mantissa word. |
| 739 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 740 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 741 | // We have the answer in ecx, but we may need to negate it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 742 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 743 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 744 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 745 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 749 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 750 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 751 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 752 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 753 | |
| 754 | __ bind(&right_exponent); |
| 755 | // Here ecx is the shift, scratch is the exponent word. |
| 756 | // Get the top bits of the mantissa. |
| 757 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 758 | // Put back the implicit 1. |
| 759 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 760 | // Shift up the mantissa bits to take up the space the exponent used to |
| 761 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 762 | // word. Shift them to the top bits. |
| 763 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 764 | __ shl(scratch, shift_distance); |
| 765 | // Get the second half of the double. For some exponents we don't |
| 766 | // actually need this because the bits get shifted out again, but |
| 767 | // it's probably slower to test than just to do it. |
| 768 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 769 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 770 | // mantissa word. |
| 771 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 772 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 773 | // Move down according to the exponent. |
| 774 | __ shr_cl(scratch2); |
| 775 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 776 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 777 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 778 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 779 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 780 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 781 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 782 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 783 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 784 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 785 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 786 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 790 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 791 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 792 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 793 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 794 | Register source, |
| 795 | Label* conversion_failure) { |
| 796 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 797 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 798 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 799 | } |
| 800 | |
| 801 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 802 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 803 | const char* op_name = Token::Name(op_); |
| 804 | const char* overwrite_name = NULL; // Make g++ happy. |
| 805 | switch (mode_) { |
| 806 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 807 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 808 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 809 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 810 | op_name, |
| 811 | overwrite_name, |
| 812 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | |
| 816 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 817 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 818 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 819 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 820 | GenerateTypeTransition(masm); |
| 821 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 822 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 823 | GenerateSmiStub(masm); |
| 824 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 825 | case UnaryOpIC::NUMBER: |
| 826 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 827 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 828 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 829 | GenerateGenericStub(masm); |
| 830 | break; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 835 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 836 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 837 | |
| 838 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 839 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 840 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 841 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 842 | |
| 843 | __ push(ecx); // Push return address. |
| 844 | |
| 845 | // Patch the caller to an appropriate specialized stub and return the |
| 846 | // operation result to the caller of the stub. |
| 847 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 848 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
| 852 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 853 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 854 | switch (op_) { |
| 855 | case Token::SUB: |
| 856 | GenerateSmiStubSub(masm); |
| 857 | break; |
| 858 | case Token::BIT_NOT: |
| 859 | GenerateSmiStubBitNot(masm); |
| 860 | break; |
| 861 | default: |
| 862 | UNREACHABLE(); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 867 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 868 | Label non_smi, undo, slow; |
| 869 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 870 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 871 | __ bind(&undo); |
| 872 | GenerateSmiCodeUndo(masm); |
| 873 | __ bind(&non_smi); |
| 874 | __ bind(&slow); |
| 875 | GenerateTypeTransition(masm); |
| 876 | } |
| 877 | |
| 878 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 879 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 880 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 881 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 882 | __ bind(&non_smi); |
| 883 | GenerateTypeTransition(masm); |
| 884 | } |
| 885 | |
| 886 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 887 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 888 | Label* non_smi, |
| 889 | Label* undo, |
| 890 | Label* slow, |
| 891 | Label::Distance non_smi_near, |
| 892 | Label::Distance undo_near, |
| 893 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 894 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 895 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 896 | |
| 897 | // We can't handle -0 with smis, so use a type transition for that case. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 898 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 899 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 900 | |
| 901 | // Try optimistic subtraction '0 - value', saving operand in eax for undo. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 902 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 903 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 904 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 905 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 906 | __ ret(0); |
| 907 | } |
| 908 | |
| 909 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 910 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 911 | MacroAssembler* masm, |
| 912 | Label* non_smi, |
| 913 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 914 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 915 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 916 | |
| 917 | // Flip bits and revert inverted smi-tag. |
| 918 | __ not_(eax); |
| 919 | __ and_(eax, ~kSmiTagMask); |
| 920 | __ ret(0); |
| 921 | } |
| 922 | |
| 923 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 924 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 925 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | |
| 929 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 930 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 931 | switch (op_) { |
| 932 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 933 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 934 | break; |
| 935 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 936 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 937 | break; |
| 938 | default: |
| 939 | UNREACHABLE(); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 944 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 945 | Label non_smi, undo, slow, call_builtin; |
| 946 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 947 | __ bind(&non_smi); |
| 948 | GenerateHeapNumberCodeSub(masm, &slow); |
| 949 | __ bind(&undo); |
| 950 | GenerateSmiCodeUndo(masm); |
| 951 | __ bind(&slow); |
| 952 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 953 | __ bind(&call_builtin); |
| 954 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 958 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 959 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 960 | Label non_smi, slow; |
| 961 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 962 | __ bind(&non_smi); |
| 963 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 964 | __ bind(&slow); |
| 965 | GenerateTypeTransition(masm); |
| 966 | } |
| 967 | |
| 968 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 969 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 970 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 971 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 972 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 973 | __ j(not_equal, slow); |
| 974 | |
| 975 | if (mode_ == UNARY_OVERWRITE) { |
| 976 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 977 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 978 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 979 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 980 | // edx: operand |
| 981 | |
| 982 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 983 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 984 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 985 | |
| 986 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 987 | { |
| 988 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 989 | __ push(edx); |
| 990 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 991 | __ pop(edx); |
| 992 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 993 | |
| 994 | __ bind(&heapnumber_allocated); |
| 995 | // eax: allocated 'empty' number |
| 996 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 997 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 998 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 999 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1000 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1001 | } |
| 1002 | __ ret(0); |
| 1003 | } |
| 1004 | |
| 1005 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1006 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1007 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1008 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1009 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1010 | __ j(not_equal, slow); |
| 1011 | |
| 1012 | // Convert the heap number in eax to an untagged integer in ecx. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1013 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1014 | |
| 1015 | // Do the bitwise operation and check if the result fits in a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1016 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1017 | __ not_(ecx); |
| 1018 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1019 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1020 | |
| 1021 | // Tag the result as a smi and we're done. |
| 1022 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1023 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1024 | __ ret(0); |
| 1025 | |
| 1026 | // Try to store the result in a heap number. |
| 1027 | __ bind(&try_float); |
| 1028 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1029 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1030 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1031 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1032 | __ jmp(&heapnumber_allocated); |
| 1033 | |
| 1034 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1035 | { |
| 1036 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1037 | // Push the original HeapNumber on the stack. The integer value can't |
| 1038 | // be stored since it's untagged and not in the smi range (so we can't |
| 1039 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1040 | __ push(ebx); |
| 1041 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1042 | // New HeapNumber is in eax. |
| 1043 | __ pop(edx); |
| 1044 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1045 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1046 | // This conversion won't go slow-case. |
| 1047 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1048 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1049 | |
| 1050 | __ bind(&heapnumber_allocated); |
| 1051 | } |
| 1052 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1053 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1054 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1055 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1056 | } else { |
| 1057 | __ push(ecx); |
| 1058 | __ fild_s(Operand(esp, 0)); |
| 1059 | __ pop(ecx); |
| 1060 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1061 | } |
| 1062 | __ ret(0); |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1067 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1068 | switch (op_) { |
| 1069 | case Token::SUB: |
| 1070 | GenerateGenericStubSub(masm); |
| 1071 | break; |
| 1072 | case Token::BIT_NOT: |
| 1073 | GenerateGenericStubBitNot(masm); |
| 1074 | break; |
| 1075 | default: |
| 1076 | UNREACHABLE(); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1081 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1082 | Label non_smi, undo, slow; |
| 1083 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1084 | __ bind(&non_smi); |
| 1085 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1086 | __ bind(&undo); |
| 1087 | GenerateSmiCodeUndo(masm); |
| 1088 | __ bind(&slow); |
| 1089 | GenerateGenericCodeFallback(masm); |
| 1090 | } |
| 1091 | |
| 1092 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1093 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1094 | Label non_smi, slow; |
| 1095 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1096 | __ bind(&non_smi); |
| 1097 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1098 | __ bind(&slow); |
| 1099 | GenerateGenericCodeFallback(masm); |
| 1100 | } |
| 1101 | |
| 1102 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1103 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1104 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1105 | __ pop(ecx); // pop return address. |
| 1106 | __ push(eax); |
| 1107 | __ push(ecx); // push return address |
| 1108 | switch (op_) { |
| 1109 | case Token::SUB: |
| 1110 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1111 | break; |
| 1112 | case Token::BIT_NOT: |
| 1113 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1114 | break; |
| 1115 | default: |
| 1116 | UNREACHABLE(); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1121 | void BinaryOpStub::Initialize() { |
| 1122 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1123 | } |
| 1124 | |
| 1125 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1126 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1127 | __ pop(ecx); // Save return address. |
| 1128 | __ push(edx); |
| 1129 | __ push(eax); |
| 1130 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1131 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1132 | |
| 1133 | __ push(ecx); // Push return address. |
| 1134 | |
| 1135 | // Patch the caller to an appropriate specialized stub and return the |
| 1136 | // operation result to the caller of the stub. |
| 1137 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1138 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1139 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1140 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1141 | 1); |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | // Prepare for a type transition runtime call when the args are already on |
| 1146 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1147 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1148 | __ pop(ecx); // Save return address. |
| 1149 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1150 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1151 | |
| 1152 | __ push(ecx); // Push return address. |
| 1153 | |
| 1154 | // Patch the caller to an appropriate specialized stub and return the |
| 1155 | // operation result to the caller of the stub. |
| 1156 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1157 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1158 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1159 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1160 | 1); |
| 1161 | } |
| 1162 | |
| 1163 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1164 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1165 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1166 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1167 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1168 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1169 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1170 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1171 | Comment load_comment(masm, "-- Load arguments"); |
| 1172 | Register left = edx; |
| 1173 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1174 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1175 | left = eax; |
| 1176 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1177 | __ mov(ebx, eax); |
| 1178 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | // 2. Prepare the smi check of both operands by oring them together. |
| 1183 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1184 | Label not_smis; |
| 1185 | Register combined = ecx; |
| 1186 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1187 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1188 | case Token::BIT_OR: |
| 1189 | // Perform the operation into eax and smi check the result. Preserve |
| 1190 | // eax in case the result is not a smi. |
| 1191 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1192 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1193 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1194 | combined = right; |
| 1195 | break; |
| 1196 | |
| 1197 | case Token::BIT_XOR: |
| 1198 | case Token::BIT_AND: |
| 1199 | case Token::ADD: |
| 1200 | case Token::SUB: |
| 1201 | case Token::MUL: |
| 1202 | case Token::DIV: |
| 1203 | case Token::MOD: |
| 1204 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1205 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | |
| 1208 | case Token::SHL: |
| 1209 | case Token::SAR: |
| 1210 | case Token::SHR: |
| 1211 | // Move the right operand into ecx for the shift operation, use eax |
| 1212 | // for the smi check register. |
| 1213 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1214 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1215 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1216 | combined = right; |
| 1217 | break; |
| 1218 | |
| 1219 | default: |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | // 3. Perform the smi check of the operands. |
| 1224 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1225 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1226 | |
| 1227 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1228 | // eax and check the result if necessary. |
| 1229 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1230 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1231 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1232 | case Token::BIT_OR: |
| 1233 | // Nothing to do. |
| 1234 | break; |
| 1235 | |
| 1236 | case Token::BIT_XOR: |
| 1237 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1238 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case Token::BIT_AND: |
| 1242 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1243 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1244 | break; |
| 1245 | |
| 1246 | case Token::SHL: |
| 1247 | // Remove tags from operands (but keep sign). |
| 1248 | __ SmiUntag(left); |
| 1249 | __ SmiUntag(ecx); |
| 1250 | // Perform the operation. |
| 1251 | __ shl_cl(left); |
| 1252 | // Check that the *signed* result fits in a smi. |
| 1253 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1254 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1255 | // Tag the result and store it in register eax. |
| 1256 | __ SmiTag(left); |
| 1257 | __ mov(eax, left); |
| 1258 | break; |
| 1259 | |
| 1260 | case Token::SAR: |
| 1261 | // Remove tags from operands (but keep sign). |
| 1262 | __ SmiUntag(left); |
| 1263 | __ SmiUntag(ecx); |
| 1264 | // Perform the operation. |
| 1265 | __ sar_cl(left); |
| 1266 | // Tag the result and store it in register eax. |
| 1267 | __ SmiTag(left); |
| 1268 | __ mov(eax, left); |
| 1269 | break; |
| 1270 | |
| 1271 | case Token::SHR: |
| 1272 | // Remove tags from operands (but keep sign). |
| 1273 | __ SmiUntag(left); |
| 1274 | __ SmiUntag(ecx); |
| 1275 | // Perform the operation. |
| 1276 | __ shr_cl(left); |
| 1277 | // Check that the *unsigned* result fits in a smi. |
| 1278 | // Neither of the two high-order bits can be set: |
| 1279 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1280 | // - 0x40000000: this number would convert to negative when |
| 1281 | // Smi tagging these two cases can only happen with shifts |
| 1282 | // by 0 or 1 when handed a valid smi. |
| 1283 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1284 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1285 | // Tag the result and store it in register eax. |
| 1286 | __ SmiTag(left); |
| 1287 | __ mov(eax, left); |
| 1288 | break; |
| 1289 | |
| 1290 | case Token::ADD: |
| 1291 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1292 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1293 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1294 | break; |
| 1295 | |
| 1296 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1297 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1298 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | __ mov(eax, left); |
| 1300 | break; |
| 1301 | |
| 1302 | case Token::MUL: |
| 1303 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1304 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1305 | // We can't revert the multiplication if the result is not a smi |
| 1306 | // so save the right operand. |
| 1307 | __ mov(ebx, right); |
| 1308 | // Remove tag from one of the operands (but keep sign). |
| 1309 | __ SmiUntag(right); |
| 1310 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1311 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1312 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1313 | // Check for negative zero result. Use combined = left | right. |
| 1314 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1315 | break; |
| 1316 | |
| 1317 | case Token::DIV: |
| 1318 | // We can't revert the division if the result is not a smi so |
| 1319 | // save the left operand. |
| 1320 | __ mov(edi, left); |
| 1321 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1322 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1323 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1324 | // Sign extend left into edx:eax. |
| 1325 | ASSERT(left.is(eax)); |
| 1326 | __ cdq(); |
| 1327 | // Divide edx:eax by right. |
| 1328 | __ idiv(right); |
| 1329 | // Check for the corner case of dividing the most negative smi by |
| 1330 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1331 | // instruction. |
| 1332 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1333 | __ cmp(eax, 0x40000000); |
| 1334 | __ j(equal, &use_fp_on_smis); |
| 1335 | // Check for negative zero result. Use combined = left | right. |
| 1336 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1337 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1338 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1339 | __ j(not_zero, &use_fp_on_smis); |
| 1340 | // Tag the result and store it in register eax. |
| 1341 | __ SmiTag(eax); |
| 1342 | break; |
| 1343 | |
| 1344 | case Token::MOD: |
| 1345 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1346 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1347 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Sign extend left into edx:eax. |
| 1350 | ASSERT(left.is(eax)); |
| 1351 | __ cdq(); |
| 1352 | // Divide edx:eax by right. |
| 1353 | __ idiv(right); |
| 1354 | // Check for negative zero result. Use combined = left | right. |
| 1355 | __ NegativeZeroTest(edx, combined, slow); |
| 1356 | // Move remainder to register eax. |
| 1357 | __ mov(eax, edx); |
| 1358 | break; |
| 1359 | |
| 1360 | default: |
| 1361 | UNREACHABLE(); |
| 1362 | } |
| 1363 | |
| 1364 | // 5. Emit return of result in eax. Some operations have registers pushed. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1365 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | case Token::ADD: |
| 1367 | case Token::SUB: |
| 1368 | case Token::MUL: |
| 1369 | case Token::DIV: |
| 1370 | __ ret(0); |
| 1371 | break; |
| 1372 | case Token::MOD: |
| 1373 | case Token::BIT_OR: |
| 1374 | case Token::BIT_AND: |
| 1375 | case Token::BIT_XOR: |
| 1376 | case Token::SAR: |
| 1377 | case Token::SHL: |
| 1378 | case Token::SHR: |
| 1379 | __ ret(2 * kPointerSize); |
| 1380 | break; |
| 1381 | default: |
| 1382 | UNREACHABLE(); |
| 1383 | } |
| 1384 | |
| 1385 | // 6. For some operations emit inline code to perform floating point |
| 1386 | // operations on known smis (e.g., if the result of the operation |
| 1387 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1388 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1389 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1390 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1391 | // Undo the effects of some operations, and some register moves. |
| 1392 | case Token::SHL: |
| 1393 | // The arguments are saved on the stack, and only used from there. |
| 1394 | break; |
| 1395 | case Token::ADD: |
| 1396 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1397 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | case Token::SUB: |
| 1400 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1401 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1402 | break; |
| 1403 | case Token::MUL: |
| 1404 | // Right was clobbered but a copy is in ebx. |
| 1405 | __ mov(right, ebx); |
| 1406 | break; |
| 1407 | case Token::DIV: |
| 1408 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1409 | // division. They should be in eax, ebx for jump to not_smi. |
| 1410 | __ mov(eax, edi); |
| 1411 | break; |
| 1412 | default: |
| 1413 | // No other operators jump to use_fp_on_smis. |
| 1414 | break; |
| 1415 | } |
| 1416 | __ jmp(¬_smis); |
| 1417 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1418 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1419 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1420 | case Token::SHL: |
| 1421 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1422 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1423 | __ bind(&use_fp_on_smis); |
| 1424 | // Result we want is in left == edx, so we can put the allocated heap |
| 1425 | // number in eax. |
| 1426 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1427 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1428 | // It's OK to overwrite the arguments on the stack because we |
| 1429 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1430 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1431 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1432 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1433 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1434 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1435 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1436 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1437 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1438 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1439 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1440 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1441 | } else { |
| 1442 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1443 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1444 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1445 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1446 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1447 | __ ret(2 * kPointerSize); |
| 1448 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | case Token::ADD: |
| 1452 | case Token::SUB: |
| 1453 | case Token::MUL: |
| 1454 | case Token::DIV: { |
| 1455 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1456 | __ bind(&use_fp_on_smis); |
| 1457 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1458 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1459 | case Token::ADD: |
| 1460 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1461 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1462 | break; |
| 1463 | case Token::SUB: |
| 1464 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1465 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1466 | break; |
| 1467 | case Token::MUL: |
| 1468 | // Right was clobbered but a copy is in ebx. |
| 1469 | __ mov(right, ebx); |
| 1470 | break; |
| 1471 | case Token::DIV: |
| 1472 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1473 | // division. |
| 1474 | __ mov(edx, edi); |
| 1475 | __ mov(eax, right); |
| 1476 | break; |
| 1477 | default: UNREACHABLE(); |
| 1478 | break; |
| 1479 | } |
| 1480 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1481 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1482 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1483 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1484 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1485 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1486 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1487 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1488 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1489 | default: UNREACHABLE(); |
| 1490 | } |
| 1491 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1492 | } else { // SSE2 not available, use FPU. |
| 1493 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1494 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1495 | case Token::ADD: __ faddp(1); break; |
| 1496 | case Token::SUB: __ fsubp(1); break; |
| 1497 | case Token::MUL: __ fmulp(1); break; |
| 1498 | case Token::DIV: __ fdivp(1); break; |
| 1499 | default: UNREACHABLE(); |
| 1500 | } |
| 1501 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1502 | } |
| 1503 | __ mov(eax, ecx); |
| 1504 | __ ret(0); |
| 1505 | break; |
| 1506 | } |
| 1507 | |
| 1508 | default: |
| 1509 | break; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1514 | // edx and eax. |
| 1515 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1516 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1517 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1518 | case Token::BIT_OR: |
| 1519 | case Token::SHL: |
| 1520 | case Token::SAR: |
| 1521 | case Token::SHR: |
| 1522 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1523 | // check. |
| 1524 | __ mov(eax, ecx); |
| 1525 | break; |
| 1526 | |
| 1527 | case Token::DIV: |
| 1528 | case Token::MOD: |
| 1529 | // Operands are in eax, ebx at this point. |
| 1530 | __ mov(edx, eax); |
| 1531 | __ mov(eax, ebx); |
| 1532 | break; |
| 1533 | |
| 1534 | default: |
| 1535 | break; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1540 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1541 | Label call_runtime; |
| 1542 | |
| 1543 | switch (op_) { |
| 1544 | case Token::ADD: |
| 1545 | case Token::SUB: |
| 1546 | case Token::MUL: |
| 1547 | case Token::DIV: |
| 1548 | break; |
| 1549 | case Token::MOD: |
| 1550 | case Token::BIT_OR: |
| 1551 | case Token::BIT_AND: |
| 1552 | case Token::BIT_XOR: |
| 1553 | case Token::SAR: |
| 1554 | case Token::SHL: |
| 1555 | case Token::SHR: |
| 1556 | GenerateRegisterArgsPush(masm); |
| 1557 | break; |
| 1558 | default: |
| 1559 | UNREACHABLE(); |
| 1560 | } |
| 1561 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1562 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1563 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1564 | BinaryOpStub_GenerateSmiCode( |
| 1565 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1566 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1567 | BinaryOpStub_GenerateSmiCode( |
| 1568 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1569 | } |
| 1570 | __ bind(&call_runtime); |
| 1571 | switch (op_) { |
| 1572 | case Token::ADD: |
| 1573 | case Token::SUB: |
| 1574 | case Token::MUL: |
| 1575 | case Token::DIV: |
| 1576 | GenerateTypeTransition(masm); |
| 1577 | break; |
| 1578 | case Token::MOD: |
| 1579 | case Token::BIT_OR: |
| 1580 | case Token::BIT_AND: |
| 1581 | case Token::BIT_XOR: |
| 1582 | case Token::SAR: |
| 1583 | case Token::SHL: |
| 1584 | case Token::SHR: |
| 1585 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1586 | break; |
| 1587 | default: |
| 1588 | UNREACHABLE(); |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1593 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1594 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1595 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1596 | ASSERT(op_ == Token::ADD); |
| 1597 | // If both arguments are strings, call the string add stub. |
| 1598 | // Otherwise, do a transition. |
| 1599 | |
| 1600 | // Registers containing left and right operands respectively. |
| 1601 | Register left = edx; |
| 1602 | Register right = eax; |
| 1603 | |
| 1604 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1605 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1606 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1607 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1608 | |
| 1609 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1610 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1611 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1612 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1613 | |
| 1614 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1615 | GenerateRegisterArgsPush(masm); |
| 1616 | __ TailCallStub(&string_add_stub); |
| 1617 | |
| 1618 | __ bind(&call_runtime); |
| 1619 | GenerateTypeTransition(masm); |
| 1620 | } |
| 1621 | |
| 1622 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1623 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1624 | Label* alloc_failure, |
| 1625 | OverwriteMode mode); |
| 1626 | |
| 1627 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1628 | // Input: |
| 1629 | // edx: left operand (tagged) |
| 1630 | // eax: right operand (tagged) |
| 1631 | // Output: |
| 1632 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1633 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1635 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1636 | |
| 1637 | // Floating point case. |
| 1638 | switch (op_) { |
| 1639 | case Token::ADD: |
| 1640 | case Token::SUB: |
| 1641 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1642 | case Token::DIV: |
| 1643 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1644 | Label not_floats; |
| 1645 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1646 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1647 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1648 | // It could be that only SMIs have been seen at either the left |
| 1649 | // or the right operand. For precise type feedback, patch the IC |
| 1650 | // again if this changes. |
| 1651 | // In theory, we would need the same check in the non-SSE2 case, |
| 1652 | // but since we don't support Crankshaft on such hardware we can |
| 1653 | // afford not to care about precise type feedback. |
| 1654 | if (left_type_ == BinaryOpIC::SMI) { |
| 1655 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1656 | } |
| 1657 | if (right_type_ == BinaryOpIC::SMI) { |
| 1658 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1659 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1660 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1661 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1662 | if (op_ == Token::MOD) { |
| 1663 | GenerateRegisterArgsPush(masm); |
| 1664 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1665 | } else { |
| 1666 | switch (op_) { |
| 1667 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1668 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1669 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1670 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1671 | default: UNREACHABLE(); |
| 1672 | } |
| 1673 | // Check result type if it is currently Int32. |
| 1674 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1675 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1676 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1677 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1678 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1679 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1680 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1681 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1682 | } else { // SSE2 not available, use FPU. |
| 1683 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1684 | FloatingPointHelper::LoadFloatOperands( |
| 1685 | masm, |
| 1686 | ecx, |
| 1687 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1688 | if (op_ == Token::MOD) { |
| 1689 | // The operands are now on the FPU stack, but we don't need them. |
| 1690 | __ fstp(0); |
| 1691 | __ fstp(0); |
| 1692 | GenerateRegisterArgsPush(masm); |
| 1693 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1694 | } else { |
| 1695 | switch (op_) { |
| 1696 | case Token::ADD: __ faddp(1); break; |
| 1697 | case Token::SUB: __ fsubp(1); break; |
| 1698 | case Token::MUL: __ fmulp(1); break; |
| 1699 | case Token::DIV: __ fdivp(1); break; |
| 1700 | default: UNREACHABLE(); |
| 1701 | } |
| 1702 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1703 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1704 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1705 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1706 | __ ret(0); |
| 1707 | __ bind(&after_alloc_failure); |
| 1708 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1709 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1710 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | __ bind(¬_floats); |
| 1714 | __ bind(¬_int32); |
| 1715 | GenerateTypeTransition(masm); |
| 1716 | break; |
| 1717 | } |
| 1718 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1719 | case Token::BIT_OR: |
| 1720 | case Token::BIT_AND: |
| 1721 | case Token::BIT_XOR: |
| 1722 | case Token::SAR: |
| 1723 | case Token::SHL: |
| 1724 | case Token::SHR: { |
| 1725 | GenerateRegisterArgsPush(masm); |
| 1726 | Label not_floats; |
| 1727 | Label not_int32; |
| 1728 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1729 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1730 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1731 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1732 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1733 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1734 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1735 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1736 | case Token::SAR: __ sar_cl(eax); break; |
| 1737 | case Token::SHL: __ shl_cl(eax); break; |
| 1738 | case Token::SHR: __ shr_cl(eax); break; |
| 1739 | default: UNREACHABLE(); |
| 1740 | } |
| 1741 | if (op_ == Token::SHR) { |
| 1742 | // Check if result is non-negative and fits in a smi. |
| 1743 | __ test(eax, Immediate(0xc0000000)); |
| 1744 | __ j(not_zero, &call_runtime); |
| 1745 | } else { |
| 1746 | // Check if result fits in a smi. |
| 1747 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1748 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1749 | } |
| 1750 | // Tag smi result and return. |
| 1751 | __ SmiTag(eax); |
| 1752 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1753 | |
| 1754 | // All ops except SHR return a signed int32 that we load in |
| 1755 | // a HeapNumber. |
| 1756 | if (op_ != Token::SHR) { |
| 1757 | __ bind(&non_smi_result); |
| 1758 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1759 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1760 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1761 | switch (mode_) { |
| 1762 | case OVERWRITE_LEFT: |
| 1763 | case OVERWRITE_RIGHT: |
| 1764 | // If the operand was an object, we skip the |
| 1765 | // allocation of a heap number. |
| 1766 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1767 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1768 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | // Fall through! |
| 1770 | case NO_OVERWRITE: |
| 1771 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1772 | __ bind(&skip_allocation); |
| 1773 | break; |
| 1774 | default: UNREACHABLE(); |
| 1775 | } |
| 1776 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1777 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1778 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1779 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1780 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1781 | } else { |
| 1782 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1783 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1784 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1785 | } |
| 1786 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1787 | } |
| 1788 | |
| 1789 | __ bind(¬_floats); |
| 1790 | __ bind(¬_int32); |
| 1791 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1792 | break; |
| 1793 | } |
| 1794 | default: UNREACHABLE(); break; |
| 1795 | } |
| 1796 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1797 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1798 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1799 | __ bind(&call_runtime); |
| 1800 | |
| 1801 | switch (op_) { |
| 1802 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1803 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1804 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1805 | case Token::DIV: |
| 1806 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1809 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1810 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1811 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1812 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1814 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1815 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1816 | break; |
| 1817 | default: |
| 1818 | UNREACHABLE(); |
| 1819 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1820 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1824 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1825 | if (op_ == Token::ADD) { |
| 1826 | // Handle string addition here, because it is the only operation |
| 1827 | // that does not do a ToNumber conversion on the operands. |
| 1828 | GenerateAddStrings(masm); |
| 1829 | } |
| 1830 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1831 | Factory* factory = masm->isolate()->factory(); |
| 1832 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1833 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1834 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1835 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1836 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1837 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1838 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1839 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1840 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1841 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1842 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1843 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1844 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1845 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1846 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1847 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1848 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1849 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1850 | } |
| 1851 | __ bind(&done); |
| 1852 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1853 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1857 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1858 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1859 | |
| 1860 | // Floating point case. |
| 1861 | switch (op_) { |
| 1862 | case Token::ADD: |
| 1863 | case Token::SUB: |
| 1864 | case Token::MUL: |
| 1865 | case Token::DIV: { |
| 1866 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1867 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1868 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1869 | |
| 1870 | // It could be that only SMIs have been seen at either the left |
| 1871 | // or the right operand. For precise type feedback, patch the IC |
| 1872 | // again if this changes. |
| 1873 | // In theory, we would need the same check in the non-SSE2 case, |
| 1874 | // but since we don't support Crankshaft on such hardware we can |
| 1875 | // afford not to care about precise type feedback. |
| 1876 | if (left_type_ == BinaryOpIC::SMI) { |
| 1877 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1878 | } |
| 1879 | if (right_type_ == BinaryOpIC::SMI) { |
| 1880 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1881 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1882 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1883 | if (left_type_ == BinaryOpIC::INT32) { |
| 1884 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1885 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1886 | } |
| 1887 | if (right_type_ == BinaryOpIC::INT32) { |
| 1888 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1889 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1890 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1891 | |
| 1892 | switch (op_) { |
| 1893 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1894 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1895 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1896 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1897 | default: UNREACHABLE(); |
| 1898 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1899 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1901 | __ ret(0); |
| 1902 | } else { // SSE2 not available, use FPU. |
| 1903 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1904 | FloatingPointHelper::LoadFloatOperands( |
| 1905 | masm, |
| 1906 | ecx, |
| 1907 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1908 | switch (op_) { |
| 1909 | case Token::ADD: __ faddp(1); break; |
| 1910 | case Token::SUB: __ fsubp(1); break; |
| 1911 | case Token::MUL: __ fmulp(1); break; |
| 1912 | case Token::DIV: __ fdivp(1); break; |
| 1913 | default: UNREACHABLE(); |
| 1914 | } |
| 1915 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1916 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1917 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1918 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1919 | __ ret(0); |
| 1920 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1921 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1922 | __ jmp(&call_runtime); |
| 1923 | } |
| 1924 | |
| 1925 | __ bind(¬_floats); |
| 1926 | GenerateTypeTransition(masm); |
| 1927 | break; |
| 1928 | } |
| 1929 | |
| 1930 | case Token::MOD: { |
| 1931 | // For MOD we go directly to runtime in the non-smi case. |
| 1932 | break; |
| 1933 | } |
| 1934 | case Token::BIT_OR: |
| 1935 | case Token::BIT_AND: |
| 1936 | case Token::BIT_XOR: |
| 1937 | case Token::SAR: |
| 1938 | case Token::SHL: |
| 1939 | case Token::SHR: { |
| 1940 | GenerateRegisterArgsPush(masm); |
| 1941 | Label not_floats; |
| 1942 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1943 | // We do not check the input arguments here, as any value is |
| 1944 | // unconditionally truncated to an int32 anyway. To get the |
| 1945 | // right optimized code, int32 type feedback is just right. |
| 1946 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1947 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1948 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1949 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1950 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1951 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1952 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1953 | case Token::SAR: __ sar_cl(eax); break; |
| 1954 | case Token::SHL: __ shl_cl(eax); break; |
| 1955 | case Token::SHR: __ shr_cl(eax); break; |
| 1956 | default: UNREACHABLE(); |
| 1957 | } |
| 1958 | if (op_ == Token::SHR) { |
| 1959 | // Check if result is non-negative and fits in a smi. |
| 1960 | __ test(eax, Immediate(0xc0000000)); |
| 1961 | __ j(not_zero, &call_runtime); |
| 1962 | } else { |
| 1963 | // Check if result fits in a smi. |
| 1964 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1965 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1966 | } |
| 1967 | // Tag smi result and return. |
| 1968 | __ SmiTag(eax); |
| 1969 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1970 | |
| 1971 | // All ops except SHR return a signed int32 that we load in |
| 1972 | // a HeapNumber. |
| 1973 | if (op_ != Token::SHR) { |
| 1974 | __ bind(&non_smi_result); |
| 1975 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1976 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1977 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1978 | switch (mode_) { |
| 1979 | case OVERWRITE_LEFT: |
| 1980 | case OVERWRITE_RIGHT: |
| 1981 | // If the operand was an object, we skip the |
| 1982 | // allocation of a heap number. |
| 1983 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1984 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1985 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1986 | // Fall through! |
| 1987 | case NO_OVERWRITE: |
| 1988 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1989 | __ bind(&skip_allocation); |
| 1990 | break; |
| 1991 | default: UNREACHABLE(); |
| 1992 | } |
| 1993 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1994 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1995 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1996 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1997 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1998 | } else { |
| 1999 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2000 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2001 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2002 | } |
| 2003 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2004 | } |
| 2005 | |
| 2006 | __ bind(¬_floats); |
| 2007 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2008 | break; |
| 2009 | } |
| 2010 | default: UNREACHABLE(); break; |
| 2011 | } |
| 2012 | |
| 2013 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2014 | // use the runtime system to get the correct result. |
| 2015 | __ bind(&call_runtime); |
| 2016 | |
| 2017 | switch (op_) { |
| 2018 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2019 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2020 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2021 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2022 | case Token::MOD: |
| 2023 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2024 | break; |
| 2025 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2026 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2027 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2028 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2029 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2030 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | default: |
| 2033 | UNREACHABLE(); |
| 2034 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2035 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2039 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2040 | Label call_runtime; |
| 2041 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2042 | Counters* counters = masm->isolate()->counters(); |
| 2043 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2044 | |
| 2045 | switch (op_) { |
| 2046 | case Token::ADD: |
| 2047 | case Token::SUB: |
| 2048 | case Token::MUL: |
| 2049 | case Token::DIV: |
| 2050 | break; |
| 2051 | case Token::MOD: |
| 2052 | case Token::BIT_OR: |
| 2053 | case Token::BIT_AND: |
| 2054 | case Token::BIT_XOR: |
| 2055 | case Token::SAR: |
| 2056 | case Token::SHL: |
| 2057 | case Token::SHR: |
| 2058 | GenerateRegisterArgsPush(masm); |
| 2059 | break; |
| 2060 | default: |
| 2061 | UNREACHABLE(); |
| 2062 | } |
| 2063 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2064 | BinaryOpStub_GenerateSmiCode( |
| 2065 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2066 | |
| 2067 | // Floating point case. |
| 2068 | switch (op_) { |
| 2069 | case Token::ADD: |
| 2070 | case Token::SUB: |
| 2071 | case Token::MUL: |
| 2072 | case Token::DIV: { |
| 2073 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2074 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2075 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2076 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2077 | |
| 2078 | switch (op_) { |
| 2079 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2080 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2081 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2082 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2083 | default: UNREACHABLE(); |
| 2084 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2085 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2086 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2087 | __ ret(0); |
| 2088 | } else { // SSE2 not available, use FPU. |
| 2089 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2090 | FloatingPointHelper::LoadFloatOperands( |
| 2091 | masm, |
| 2092 | ecx, |
| 2093 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2094 | switch (op_) { |
| 2095 | case Token::ADD: __ faddp(1); break; |
| 2096 | case Token::SUB: __ fsubp(1); break; |
| 2097 | case Token::MUL: __ fmulp(1); break; |
| 2098 | case Token::DIV: __ fdivp(1); break; |
| 2099 | default: UNREACHABLE(); |
| 2100 | } |
| 2101 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2102 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2103 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2104 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2105 | __ ret(0); |
| 2106 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2107 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2108 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2109 | } |
| 2110 | __ bind(¬_floats); |
| 2111 | break; |
| 2112 | } |
| 2113 | case Token::MOD: { |
| 2114 | // For MOD we go directly to runtime in the non-smi case. |
| 2115 | break; |
| 2116 | } |
| 2117 | case Token::BIT_OR: |
| 2118 | case Token::BIT_AND: |
| 2119 | case Token::BIT_XOR: |
| 2120 | case Token::SAR: |
| 2121 | case Token::SHL: |
| 2122 | case Token::SHR: { |
| 2123 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2124 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2125 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2126 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2127 | BinaryOpIC::GENERIC, |
| 2128 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | &call_runtime); |
| 2130 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2131 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2132 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2133 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2134 | case Token::SAR: __ sar_cl(eax); break; |
| 2135 | case Token::SHL: __ shl_cl(eax); break; |
| 2136 | case Token::SHR: __ shr_cl(eax); break; |
| 2137 | default: UNREACHABLE(); |
| 2138 | } |
| 2139 | if (op_ == Token::SHR) { |
| 2140 | // Check if result is non-negative and fits in a smi. |
| 2141 | __ test(eax, Immediate(0xc0000000)); |
| 2142 | __ j(not_zero, &call_runtime); |
| 2143 | } else { |
| 2144 | // Check if result fits in a smi. |
| 2145 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2146 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2147 | } |
| 2148 | // Tag smi result and return. |
| 2149 | __ SmiTag(eax); |
| 2150 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2151 | |
| 2152 | // All ops except SHR return a signed int32 that we load in |
| 2153 | // a HeapNumber. |
| 2154 | if (op_ != Token::SHR) { |
| 2155 | __ bind(&non_smi_result); |
| 2156 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2157 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2158 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | switch (mode_) { |
| 2160 | case OVERWRITE_LEFT: |
| 2161 | case OVERWRITE_RIGHT: |
| 2162 | // If the operand was an object, we skip the |
| 2163 | // allocation of a heap number. |
| 2164 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2165 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2166 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2167 | // Fall through! |
| 2168 | case NO_OVERWRITE: |
| 2169 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2170 | __ bind(&skip_allocation); |
| 2171 | break; |
| 2172 | default: UNREACHABLE(); |
| 2173 | } |
| 2174 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2175 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2176 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2177 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2178 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2179 | } else { |
| 2180 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2181 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2182 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2183 | } |
| 2184 | __ ret(2 * kPointerSize); |
| 2185 | } |
| 2186 | break; |
| 2187 | } |
| 2188 | default: UNREACHABLE(); break; |
| 2189 | } |
| 2190 | |
| 2191 | // If all else fails, use the runtime system to get the correct |
| 2192 | // result. |
| 2193 | __ bind(&call_runtime); |
| 2194 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2195 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2196 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2197 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2198 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2199 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2200 | case Token::DIV: |
| 2201 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2204 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2205 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2206 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2207 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2208 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2209 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | default: |
| 2212 | UNREACHABLE(); |
| 2213 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2214 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2218 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2219 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2220 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2221 | |
| 2222 | // Registers containing left and right operands respectively. |
| 2223 | Register left = edx; |
| 2224 | Register right = eax; |
| 2225 | |
| 2226 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2227 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2228 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2229 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2230 | |
| 2231 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2232 | GenerateRegisterArgsPush(masm); |
| 2233 | __ TailCallStub(&string_add_left_stub); |
| 2234 | |
| 2235 | // Left operand is not a string, test right. |
| 2236 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2237 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2238 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2239 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2240 | |
| 2241 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2242 | GenerateRegisterArgsPush(masm); |
| 2243 | __ TailCallStub(&string_add_right_stub); |
| 2244 | |
| 2245 | // Neither argument is a string. |
| 2246 | __ bind(&call_runtime); |
| 2247 | } |
| 2248 | |
| 2249 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2250 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2251 | Label* alloc_failure, |
| 2252 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2253 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2254 | switch (mode) { |
| 2255 | case OVERWRITE_LEFT: { |
| 2256 | // If the argument in edx is already an object, we skip the |
| 2257 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2258 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2260 | // for the possible runtime call. |
| 2261 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2262 | // Now edx can be overwritten losing one of the arguments as we are |
| 2263 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2264 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2265 | __ bind(&skip_allocation); |
| 2266 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2267 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | } |
| 2270 | case OVERWRITE_RIGHT: |
| 2271 | // If the argument in eax is already an object, we skip the |
| 2272 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2273 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2274 | // Fall through! |
| 2275 | case NO_OVERWRITE: |
| 2276 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2277 | // for the possible runtime call. |
| 2278 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2279 | // Now eax can be overwritten losing one of the arguments as we are |
| 2280 | // now done and will not need it any more. |
| 2281 | __ mov(eax, ebx); |
| 2282 | __ bind(&skip_allocation); |
| 2283 | break; |
| 2284 | default: UNREACHABLE(); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2289 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2290 | __ pop(ecx); |
| 2291 | __ push(edx); |
| 2292 | __ push(eax); |
| 2293 | __ push(ecx); |
| 2294 | } |
| 2295 | |
| 2296 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2297 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2298 | // TAGGED case: |
| 2299 | // Input: |
| 2300 | // esp[4]: tagged number input argument (should be number). |
| 2301 | // esp[0]: return address. |
| 2302 | // Output: |
| 2303 | // eax: tagged double result. |
| 2304 | // UNTAGGED case: |
| 2305 | // Input:: |
| 2306 | // esp[0]: return address. |
| 2307 | // xmm1: untagged double input argument |
| 2308 | // Output: |
| 2309 | // xmm1: untagged double result. |
| 2310 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2311 | Label runtime_call; |
| 2312 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2313 | Label skip_cache; |
| 2314 | const bool tagged = (argument_type_ == TAGGED); |
| 2315 | if (tagged) { |
| 2316 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2317 | Label input_not_smi; |
| 2318 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2319 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2320 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2321 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2322 | // Then load the low and high words of the double into ebx, edx. |
| 2323 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2324 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2325 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2326 | __ mov(Operand(esp, 0), eax); |
| 2327 | __ fild_s(Operand(esp, 0)); |
| 2328 | __ fst_d(Operand(esp, 0)); |
| 2329 | __ pop(edx); |
| 2330 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2331 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2332 | __ bind(&input_not_smi); |
| 2333 | // Check if input is a HeapNumber. |
| 2334 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2335 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2336 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2337 | __ j(not_equal, &runtime_call); |
| 2338 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2339 | // low and high words into ebx, edx. |
| 2340 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2341 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2342 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2343 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2344 | __ bind(&loaded); |
| 2345 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2346 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2347 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2348 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2349 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2350 | } else { |
| 2351 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2352 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2353 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2354 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2358 | // ebx = low 32 bits of double value |
| 2359 | // edx = high 32 bits of double value |
| 2360 | // Compute hash (the shifts are arithmetic): |
| 2361 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2362 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2363 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2364 | __ mov(eax, ecx); |
| 2365 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2366 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2367 | __ mov(eax, ecx); |
| 2368 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2369 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2370 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2371 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2372 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2373 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2374 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2375 | // ebx = low 32 bits of double value. |
| 2376 | // edx = high 32 bits of double value. |
| 2377 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2378 | ExternalReference cache_array = |
| 2379 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2380 | __ mov(eax, Immediate(cache_array)); |
| 2381 | int cache_array_index = |
| 2382 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2383 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2384 | // Eax points to the cache for the type type_. |
| 2385 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2386 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2387 | __ j(zero, &runtime_call_clear_stack); |
| 2388 | #ifdef DEBUG |
| 2389 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2390 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2391 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2392 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2393 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2394 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2395 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2396 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2397 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2398 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2399 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2400 | } |
| 2401 | #endif |
| 2402 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2403 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2404 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2405 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2406 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2407 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2408 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2409 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2410 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2411 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2412 | Counters* counters = masm->isolate()->counters(); |
| 2413 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2414 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2415 | if (tagged) { |
| 2416 | __ fstp(0); |
| 2417 | __ ret(kPointerSize); |
| 2418 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2419 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2420 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2421 | __ Ret(); |
| 2422 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2423 | |
| 2424 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2425 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2426 | // Update cache with new value. |
| 2427 | // We are short on registers, so use no_reg as scratch. |
| 2428 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2429 | if (tagged) { |
| 2430 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2431 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2432 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2433 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2434 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2435 | __ movdbl(Operand(esp, 0), xmm1); |
| 2436 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2437 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2438 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2439 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2440 | __ mov(Operand(ecx, 0), ebx); |
| 2441 | __ mov(Operand(ecx, kIntSize), edx); |
| 2442 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2443 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2444 | if (tagged) { |
| 2445 | __ ret(kPointerSize); |
| 2446 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2447 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2448 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2449 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2450 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2451 | // Skip cache and return answer directly, only in untagged case. |
| 2452 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2453 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2454 | __ movdbl(Operand(esp, 0), xmm1); |
| 2455 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2456 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2457 | __ fstp_d(Operand(esp, 0)); |
| 2458 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2459 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2460 | // We return the value in xmm1 without adding it to the cache, but |
| 2461 | // we cause a scavenging GC so that future allocations will succeed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2462 | { |
| 2463 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2464 | // Allocate an unused object bigger than a HeapNumber. |
| 2465 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2466 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2467 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2468 | __ Ret(); |
| 2469 | } |
| 2470 | |
| 2471 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2472 | if (tagged) { |
| 2473 | __ bind(&runtime_call_clear_stack); |
| 2474 | __ fstp(0); |
| 2475 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2476 | ExternalReference runtime = |
| 2477 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2478 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2479 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2480 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2481 | __ bind(&runtime_call_clear_stack); |
| 2482 | __ bind(&runtime_call); |
| 2483 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2484 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2485 | { |
| 2486 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2487 | __ push(eax); |
| 2488 | __ CallRuntime(RuntimeFunction(), 1); |
| 2489 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2490 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2491 | __ Ret(); |
| 2492 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2497 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2498 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2499 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2500 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2501 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2502 | default: |
| 2503 | UNIMPLEMENTED(); |
| 2504 | return Runtime::kAbort; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2509 | void TranscendentalCacheStub::GenerateOperation( |
| 2510 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2511 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2512 | // Input value is on FP stack, and also in ebx/edx. |
| 2513 | // Input value is possibly in xmm1. |
| 2514 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2515 | if (type == TranscendentalCache::SIN || |
| 2516 | type == TranscendentalCache::COS || |
| 2517 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2518 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2519 | // return NaN for infinities and NaN. They can share all code except |
| 2520 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2521 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2522 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2523 | // work. We must reduce it to the appropriate range. |
| 2524 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2525 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2526 | int supported_exponent_limit = |
| 2527 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2528 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2529 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2530 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2531 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2532 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2533 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2534 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2535 | __ fstp(0); |
| 2536 | // NaN is represented by 0x7ff8000000000000. |
| 2537 | __ push(Immediate(0x7ff80000)); |
| 2538 | __ push(Immediate(0)); |
| 2539 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2540 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2541 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2542 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2543 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2544 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2545 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2546 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2547 | __ fldpi(); |
| 2548 | __ fadd(0); |
| 2549 | __ fld(1); |
| 2550 | // FPU Stack: input, 2*pi, input. |
| 2551 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2552 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2553 | __ fwait(); |
| 2554 | __ fnstsw_ax(); |
| 2555 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2556 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2557 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2558 | __ fnclex(); |
| 2559 | __ bind(&no_exceptions); |
| 2560 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2561 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2562 | // Compute st(0) % st(1) |
| 2563 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2564 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2565 | __ bind(&partial_remainder_loop); |
| 2566 | __ fprem1(); |
| 2567 | __ fwait(); |
| 2568 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2569 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2570 | // If C2 is set, computation only has partial result. Loop to |
| 2571 | // continue computation. |
| 2572 | __ j(not_zero, &partial_remainder_loop); |
| 2573 | } |
| 2574 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2575 | __ fstp(2); |
| 2576 | __ fstp(0); |
| 2577 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2578 | |
| 2579 | // FPU Stack: input % 2*pi |
| 2580 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2581 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2582 | case TranscendentalCache::SIN: |
| 2583 | __ fsin(); |
| 2584 | break; |
| 2585 | case TranscendentalCache::COS: |
| 2586 | __ fcos(); |
| 2587 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2588 | case TranscendentalCache::TAN: |
| 2589 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2590 | // FP register stack. |
| 2591 | __ fptan(); |
| 2592 | __ fstp(0); // Pop FP register stack. |
| 2593 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2594 | default: |
| 2595 | UNREACHABLE(); |
| 2596 | } |
| 2597 | __ bind(&done); |
| 2598 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2599 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2600 | __ fldln2(); |
| 2601 | __ fxch(); |
| 2602 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2603 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2607 | // Input: edx, eax are the left and right objects of a bit op. |
| 2608 | // Output: eax, ecx are left and right integers for a bit op. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2609 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2610 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2611 | MacroAssembler* masm, |
| 2612 | bool use_sse3, |
| 2613 | BinaryOpIC::TypeInfo left_type, |
| 2614 | BinaryOpIC::TypeInfo right_type, |
| 2615 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2616 | // Check float operands. |
| 2617 | Label arg1_is_object, check_undefined_arg1; |
| 2618 | Label arg2_is_object, check_undefined_arg2; |
| 2619 | Label load_arg2, done; |
| 2620 | |
| 2621 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2622 | if (left_type == BinaryOpIC::SMI) { |
| 2623 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2624 | } else { |
| 2625 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2626 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2627 | |
| 2628 | __ SmiUntag(edx); |
| 2629 | __ jmp(&load_arg2); |
| 2630 | |
| 2631 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2632 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2633 | Factory* factory = masm->isolate()->factory(); |
| 2634 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2635 | __ j(not_equal, conversion_failure); |
| 2636 | __ mov(edx, Immediate(0)); |
| 2637 | __ jmp(&load_arg2); |
| 2638 | |
| 2639 | __ bind(&arg1_is_object); |
| 2640 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2641 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2642 | __ j(not_equal, &check_undefined_arg1); |
| 2643 | |
| 2644 | // Get the untagged integer version of the edx heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2645 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2646 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2647 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2648 | } else { |
| 2649 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2650 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2651 | __ mov(edx, ecx); |
| 2652 | |
| 2653 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2654 | __ bind(&load_arg2); |
| 2655 | |
| 2656 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2657 | if (right_type == BinaryOpIC::SMI) { |
| 2658 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2659 | } else { |
| 2660 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2661 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2662 | |
| 2663 | __ SmiUntag(eax); |
| 2664 | __ mov(ecx, eax); |
| 2665 | __ jmp(&done); |
| 2666 | |
| 2667 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2668 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2669 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2670 | __ j(not_equal, conversion_failure); |
| 2671 | __ mov(ecx, Immediate(0)); |
| 2672 | __ jmp(&done); |
| 2673 | |
| 2674 | __ bind(&arg2_is_object); |
| 2675 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2676 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2677 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2678 | // Get the untagged integer version of the eax heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2679 | |
| 2680 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2681 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2682 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2683 | } else { |
| 2684 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2685 | } |
| 2686 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2687 | __ bind(&done); |
| 2688 | __ mov(eax, edx); |
| 2689 | } |
| 2690 | |
| 2691 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2692 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2693 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2694 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2695 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2696 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2697 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2698 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2699 | |
| 2700 | __ bind(&load_smi); |
| 2701 | __ SmiUntag(number); |
| 2702 | __ push(number); |
| 2703 | __ fild_s(Operand(esp, 0)); |
| 2704 | __ pop(number); |
| 2705 | |
| 2706 | __ bind(&done); |
| 2707 | } |
| 2708 | |
| 2709 | |
| 2710 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2711 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2712 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2713 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2714 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2715 | |
| 2716 | __ bind(&load_eax); |
| 2717 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2718 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2719 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2720 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2721 | |
| 2722 | __ bind(&load_smi_edx); |
| 2723 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2724 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2725 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2726 | __ jmp(&load_eax); |
| 2727 | |
| 2728 | __ bind(&load_smi_eax); |
| 2729 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2730 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2731 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2732 | |
| 2733 | __ bind(&done); |
| 2734 | } |
| 2735 | |
| 2736 | |
| 2737 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2738 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2739 | Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2740 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2741 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2742 | Factory* factory = masm->isolate()->factory(); |
| 2743 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2744 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2745 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2746 | __ bind(&load_eax); |
| 2747 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2748 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2749 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2750 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2751 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2752 | __ bind(&load_smi_edx); |
| 2753 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2754 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2755 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2756 | __ jmp(&load_eax); |
| 2757 | __ bind(&load_smi_eax); |
| 2758 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2759 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2760 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2761 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2762 | __ bind(&load_float_eax); |
| 2763 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2764 | __ bind(&done); |
| 2765 | } |
| 2766 | |
| 2767 | |
| 2768 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2769 | Register scratch) { |
| 2770 | const Register left = edx; |
| 2771 | const Register right = eax; |
| 2772 | __ mov(scratch, left); |
| 2773 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2774 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2775 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2776 | |
| 2777 | __ mov(scratch, right); |
| 2778 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2779 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2783 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2784 | Label* non_int32, |
| 2785 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2786 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2787 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | |
| 2791 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2792 | Label* non_int32, |
| 2793 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2794 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2795 | Register scratch, |
| 2796 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2797 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2798 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2799 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2800 | __ movmskps(scratch, xmm_scratch); |
| 2801 | // Two least significant bits should be both set. |
| 2802 | __ not_(scratch); |
| 2803 | __ test(scratch, Immediate(3)); |
| 2804 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2808 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2809 | Register scratch, |
| 2810 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2811 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2812 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2813 | __ mov(scratch, edx); |
| 2814 | } else { |
| 2815 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2816 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2817 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2818 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2819 | __ bind(&done_load_1); |
| 2820 | |
| 2821 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2822 | __ mov(scratch, eax); |
| 2823 | } else { |
| 2824 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2825 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2826 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2827 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2828 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2829 | |
| 2830 | __ bind(&load_smi_1); |
| 2831 | __ SmiUntag(scratch); |
| 2832 | __ push(scratch); |
| 2833 | __ fild_s(Operand(esp, 0)); |
| 2834 | __ pop(scratch); |
| 2835 | __ jmp(&done_load_1); |
| 2836 | |
| 2837 | __ bind(&load_smi_2); |
| 2838 | __ SmiUntag(scratch); |
| 2839 | __ push(scratch); |
| 2840 | __ fild_s(Operand(esp, 0)); |
| 2841 | __ pop(scratch); |
| 2842 | |
| 2843 | __ bind(&done); |
| 2844 | } |
| 2845 | |
| 2846 | |
| 2847 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2848 | Register scratch) { |
| 2849 | const Register left = edx; |
| 2850 | const Register right = eax; |
| 2851 | __ mov(scratch, left); |
| 2852 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2853 | __ SmiUntag(scratch); |
| 2854 | __ push(scratch); |
| 2855 | __ fild_s(Operand(esp, 0)); |
| 2856 | |
| 2857 | __ mov(scratch, right); |
| 2858 | __ SmiUntag(scratch); |
| 2859 | __ mov(Operand(esp, 0), scratch); |
| 2860 | __ fild_s(Operand(esp, 0)); |
| 2861 | __ pop(scratch); |
| 2862 | } |
| 2863 | |
| 2864 | |
| 2865 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2866 | Label* non_float, |
| 2867 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2868 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2869 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2870 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2871 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2872 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2873 | Factory* factory = masm->isolate()->factory(); |
| 2874 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2875 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2876 | |
| 2877 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2878 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2879 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2880 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2881 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2882 | |
| 2883 | // Fall-through: Both operands are numbers. |
| 2884 | __ bind(&done); |
| 2885 | } |
| 2886 | |
| 2887 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2888 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2889 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2890 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2891 | const Register exponent = eax; |
| 2892 | const Register base = edx; |
| 2893 | const Register scratch = ecx; |
| 2894 | const XMMRegister double_result = xmm3; |
| 2895 | const XMMRegister double_base = xmm2; |
| 2896 | const XMMRegister double_exponent = xmm1; |
| 2897 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2898 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2899 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2900 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2901 | // Save 1 in double_result - we need this several times later on. |
| 2902 | __ mov(scratch, Immediate(1)); |
| 2903 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2904 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2905 | if (exponent_type_ == ON_STACK) { |
| 2906 | Label base_is_smi, unpack_exponent; |
| 2907 | // The exponent and base are supplied as arguments on the stack. |
| 2908 | // This can only happen if the stub is called from non-optimized code. |
| 2909 | // Load input parameters from stack. |
| 2910 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2911 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2912 | |
| 2913 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2914 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2915 | factory->heap_number_map()); |
| 2916 | __ j(not_equal, &call_runtime); |
| 2917 | |
| 2918 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2919 | __ jmp(&unpack_exponent, Label::kNear); |
| 2920 | |
| 2921 | __ bind(&base_is_smi); |
| 2922 | __ SmiUntag(base); |
| 2923 | __ cvtsi2sd(double_base, base); |
| 2924 | |
| 2925 | __ bind(&unpack_exponent); |
| 2926 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2927 | __ SmiUntag(exponent); |
| 2928 | __ jmp(&int_exponent); |
| 2929 | |
| 2930 | __ bind(&exponent_not_smi); |
| 2931 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2932 | factory->heap_number_map()); |
| 2933 | __ j(not_equal, &call_runtime); |
| 2934 | __ movdbl(double_exponent, |
| 2935 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2936 | } else if (exponent_type_ == TAGGED) { |
| 2937 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2938 | __ SmiUntag(exponent); |
| 2939 | __ jmp(&int_exponent); |
| 2940 | |
| 2941 | __ bind(&exponent_not_smi); |
| 2942 | __ movdbl(double_exponent, |
| 2943 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2944 | } |
| 2945 | |
| 2946 | if (exponent_type_ != INTEGER) { |
| 2947 | Label fast_power; |
| 2948 | // Detect integer exponents stored as double. |
| 2949 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2950 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2951 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2952 | __ j(equal, &call_runtime); |
| 2953 | __ cvtsi2sd(double_scratch, exponent); |
| 2954 | // Already ruled out NaNs for exponent. |
| 2955 | __ ucomisd(double_exponent, double_scratch); |
| 2956 | __ j(equal, &int_exponent); |
| 2957 | |
| 2958 | if (exponent_type_ == ON_STACK) { |
| 2959 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2960 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2961 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2962 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2963 | // Test for 0.5. |
| 2964 | // Load double_scratch with 0.5. |
| 2965 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2966 | __ movd(double_scratch, scratch); |
| 2967 | __ cvtss2sd(double_scratch, double_scratch); |
| 2968 | // Already ruled out NaNs for exponent. |
| 2969 | __ ucomisd(double_scratch, double_exponent); |
| 2970 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2971 | |
| 2972 | // Calculates square root of base. Check for the special case of |
| 2973 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2974 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2975 | // 9 bits set and the lowest 23 bits cleared. |
| 2976 | __ mov(scratch, 0xFF800000u); |
| 2977 | __ movd(double_scratch, scratch); |
| 2978 | __ cvtss2sd(double_scratch, double_scratch); |
| 2979 | __ ucomisd(double_base, double_scratch); |
| 2980 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2981 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2982 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2983 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2984 | |
| 2985 | // Set result to Infinity in the special case. |
| 2986 | __ xorps(double_result, double_result); |
| 2987 | __ subsd(double_result, double_scratch); |
| 2988 | __ jmp(&done); |
| 2989 | |
| 2990 | __ bind(&continue_sqrt); |
| 2991 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2992 | __ xorps(double_scratch, double_scratch); |
| 2993 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2994 | __ sqrtsd(double_result, double_scratch); |
| 2995 | __ jmp(&done); |
| 2996 | |
| 2997 | // Test for -0.5. |
| 2998 | __ bind(¬_plus_half); |
| 2999 | // Load double_exponent with -0.5 by substracting 1. |
| 3000 | __ subsd(double_scratch, double_result); |
| 3001 | // Already ruled out NaNs for exponent. |
| 3002 | __ ucomisd(double_scratch, double_exponent); |
| 3003 | __ j(not_equal, &fast_power, Label::kNear); |
| 3004 | |
| 3005 | // Calculates reciprocal of square root of base. Check for the special |
| 3006 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3007 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3008 | // 9 bits set and the lowest 23 bits cleared. |
| 3009 | __ mov(scratch, 0xFF800000u); |
| 3010 | __ movd(double_scratch, scratch); |
| 3011 | __ cvtss2sd(double_scratch, double_scratch); |
| 3012 | __ ucomisd(double_base, double_scratch); |
| 3013 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3014 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3015 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3016 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3017 | |
| 3018 | // Set result to 0 in the special case. |
| 3019 | __ xorps(double_result, double_result); |
| 3020 | __ jmp(&done); |
| 3021 | |
| 3022 | __ bind(&continue_rsqrt); |
| 3023 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3024 | __ xorps(double_exponent, double_exponent); |
| 3025 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3026 | __ sqrtsd(double_exponent, double_exponent); |
| 3027 | __ divsd(double_result, double_exponent); |
| 3028 | __ jmp(&done); |
| 3029 | } |
| 3030 | |
| 3031 | // Using FPU instructions to calculate power. |
| 3032 | Label fast_power_failed; |
| 3033 | __ bind(&fast_power); |
| 3034 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3035 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3036 | __ sub(esp, Immediate(kDoubleSize)); |
| 3037 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3038 | __ fld_d(Operand(esp, 0)); // E |
| 3039 | __ movdbl(Operand(esp, 0), double_base); |
| 3040 | __ fld_d(Operand(esp, 0)); // B, E |
| 3041 | |
| 3042 | // Exponent is in st(1) and base is in st(0) |
| 3043 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3044 | // FYL2X calculates st(1) * log2(st(0)) |
| 3045 | __ fyl2x(); // X |
| 3046 | __ fld(0); // X, X |
| 3047 | __ frndint(); // rnd(X), X |
| 3048 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3049 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3050 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3051 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3052 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3053 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3054 | // FSCALE calculates st(0) * 2^st(1) |
| 3055 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3056 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3057 | // Bail out to runtime in case of exceptions in the status word. |
| 3058 | __ fnstsw_ax(); |
| 3059 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3060 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3061 | __ fstp_d(Operand(esp, 0)); |
| 3062 | __ movdbl(double_result, Operand(esp, 0)); |
| 3063 | __ add(esp, Immediate(kDoubleSize)); |
| 3064 | __ jmp(&done); |
| 3065 | |
| 3066 | __ bind(&fast_power_failed); |
| 3067 | __ fninit(); |
| 3068 | __ add(esp, Immediate(kDoubleSize)); |
| 3069 | __ jmp(&call_runtime); |
| 3070 | } |
| 3071 | |
| 3072 | // Calculate power with integer exponent. |
| 3073 | __ bind(&int_exponent); |
| 3074 | const XMMRegister double_scratch2 = double_exponent; |
| 3075 | __ mov(scratch, exponent); // Back up exponent. |
| 3076 | __ movsd(double_scratch, double_base); // Back up base. |
| 3077 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3078 | |
| 3079 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3080 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3081 | __ test(scratch, scratch); |
| 3082 | __ j(positive, &no_neg, Label::kNear); |
| 3083 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3084 | __ bind(&no_neg); |
| 3085 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3086 | __ j(zero, &while_false, Label::kNear); |
| 3087 | __ shr(scratch, 1); |
| 3088 | // Above condition means CF==0 && ZF==0. This means that the |
| 3089 | // bit that has been shifted out is 0 and the result is not 0. |
| 3090 | __ j(above, &while_true, Label::kNear); |
| 3091 | __ movsd(double_result, double_scratch); |
| 3092 | __ j(zero, &while_false, Label::kNear); |
| 3093 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3094 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3095 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3096 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3097 | __ j(above, &while_true, Label::kNear); |
| 3098 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3099 | __ j(not_zero, &while_true); |
| 3100 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3101 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3102 | // scratch has the original value of the exponent - if the exponent is |
| 3103 | // negative, return 1/result. |
| 3104 | __ test(exponent, exponent); |
| 3105 | __ j(positive, &done); |
| 3106 | __ divsd(double_scratch2, double_result); |
| 3107 | __ movsd(double_result, double_scratch2); |
| 3108 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3109 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3110 | __ xorps(double_scratch2, double_scratch2); |
| 3111 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3112 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3113 | // and may not have contained the exponent value in the first place when the |
| 3114 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3115 | __ j(not_equal, &done); |
| 3116 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3117 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3118 | // Returning or bailing out. |
| 3119 | Counters* counters = masm->isolate()->counters(); |
| 3120 | if (exponent_type_ == ON_STACK) { |
| 3121 | // The arguments are still on the stack. |
| 3122 | __ bind(&call_runtime); |
| 3123 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3124 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3125 | // The stub is called from non-optimized code, which expects the result |
| 3126 | // as heap number in exponent. |
| 3127 | __ bind(&done); |
| 3128 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3129 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3130 | __ IncrementCounter(counters->math_pow(), 1); |
| 3131 | __ ret(2 * kPointerSize); |
| 3132 | } else { |
| 3133 | __ bind(&call_runtime); |
| 3134 | { |
| 3135 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3136 | __ PrepareCallCFunction(4, scratch); |
| 3137 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3138 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3139 | __ CallCFunction( |
| 3140 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3141 | } |
| 3142 | // Return value is in st(0) on ia32. |
| 3143 | // Store it into the (fixed) result register. |
| 3144 | __ sub(esp, Immediate(kDoubleSize)); |
| 3145 | __ fstp_d(Operand(esp, 0)); |
| 3146 | __ movdbl(double_result, Operand(esp, 0)); |
| 3147 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3148 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3149 | __ bind(&done); |
| 3150 | __ IncrementCounter(counters->math_pow(), 1); |
| 3151 | __ ret(0); |
| 3152 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3156 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3157 | // ----------- S t a t e ------------- |
| 3158 | // -- ecx : name |
| 3159 | // -- edx : receiver |
| 3160 | // -- esp[0] : return address |
| 3161 | // ----------------------------------- |
| 3162 | Label miss; |
| 3163 | |
| 3164 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3165 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3166 | __ j(not_equal, &miss); |
| 3167 | } |
| 3168 | |
| 3169 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3170 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3171 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | |
| 3175 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3176 | // ----------- S t a t e ------------- |
| 3177 | // -- ecx : name |
| 3178 | // -- edx : receiver |
| 3179 | // -- esp[0] : return address |
| 3180 | // ----------------------------------- |
| 3181 | Label miss; |
| 3182 | |
| 3183 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3184 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3185 | __ j(not_equal, &miss); |
| 3186 | } |
| 3187 | |
| 3188 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3189 | support_wrapper_); |
| 3190 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3191 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3195 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3196 | // ----------- S t a t e ------------- |
| 3197 | // -- eax : value |
| 3198 | // -- ecx : name |
| 3199 | // -- edx : receiver |
| 3200 | // -- esp[0] : return address |
| 3201 | // ----------------------------------- |
| 3202 | // |
| 3203 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3204 | // (currently anything except for external arrays which means anything with |
| 3205 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3206 | // accepted as the most common case. |
| 3207 | |
| 3208 | Label miss; |
| 3209 | |
| 3210 | Register receiver = edx; |
| 3211 | Register value = eax; |
| 3212 | Register scratch = ebx; |
| 3213 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3214 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3215 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3216 | __ j(not_equal, &miss); |
| 3217 | } |
| 3218 | |
| 3219 | // Check that the receiver isn't a smi. |
| 3220 | __ JumpIfSmi(receiver, &miss); |
| 3221 | |
| 3222 | // Check that the object is a JS array. |
| 3223 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3224 | __ j(not_equal, &miss); |
| 3225 | |
| 3226 | // Check that elements are FixedArray. |
| 3227 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3228 | // fast elements (including COW). |
| 3229 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3230 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3231 | __ j(not_equal, &miss); |
| 3232 | |
| 3233 | // Check that the array has fast properties, otherwise the length |
| 3234 | // property might have been redefined. |
| 3235 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3236 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3237 | Heap::kHashTableMapRootIndex); |
| 3238 | __ j(equal, &miss); |
| 3239 | |
| 3240 | // Check that value is a smi. |
| 3241 | __ JumpIfNotSmi(value, &miss); |
| 3242 | |
| 3243 | // Prepare tail call to StoreIC_ArrayLength. |
| 3244 | __ pop(scratch); |
| 3245 | __ push(receiver); |
| 3246 | __ push(value); |
| 3247 | __ push(scratch); // return address |
| 3248 | |
| 3249 | ExternalReference ref = |
| 3250 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3251 | __ TailCallExternalReference(ref, 2, 1); |
| 3252 | |
| 3253 | __ bind(&miss); |
| 3254 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3255 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3259 | void LoadFieldStub::Generate(MacroAssembler* masm) { |
| 3260 | StubCompiler::DoGenerateFastPropertyLoad(masm, eax, reg_, inobject_, index_); |
| 3261 | __ ret(0); |
| 3262 | } |
| 3263 | |
| 3264 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3265 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3266 | // The key is in edx and the parameter count is in eax. |
| 3267 | |
| 3268 | // The displacement is used for skipping the frame pointer on the |
| 3269 | // stack. It is the offset of the last parameter (if any) relative |
| 3270 | // to the frame pointer. |
| 3271 | static const int kDisplacement = 1 * kPointerSize; |
| 3272 | |
| 3273 | // Check that the key is a smi. |
| 3274 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3275 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3276 | |
| 3277 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3278 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3279 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3280 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3281 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3282 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3283 | |
| 3284 | // Check index against formal parameters count limit passed in |
| 3285 | // through register eax. Use unsigned comparison to get negative |
| 3286 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3287 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3288 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3289 | |
| 3290 | // Read the argument from the stack and return it. |
| 3291 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3292 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3293 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3294 | __ neg(edx); |
| 3295 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3296 | __ ret(0); |
| 3297 | |
| 3298 | // Arguments adaptor case: Check index against actual arguments |
| 3299 | // limit found in the arguments adaptor frame. Use unsigned |
| 3300 | // comparison to get negative check for free. |
| 3301 | __ bind(&adaptor); |
| 3302 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3303 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3304 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3305 | |
| 3306 | // Read the argument from the stack and return it. |
| 3307 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3308 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3309 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3310 | __ neg(edx); |
| 3311 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3312 | __ ret(0); |
| 3313 | |
| 3314 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3315 | // by calling the runtime system. |
| 3316 | __ bind(&slow); |
| 3317 | __ pop(ebx); // Return address. |
| 3318 | __ push(edx); |
| 3319 | __ push(ebx); |
| 3320 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3321 | } |
| 3322 | |
| 3323 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3324 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3325 | // esp[0] : return address |
| 3326 | // esp[4] : number of parameters |
| 3327 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3328 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3329 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3330 | // Check if the calling frame is an arguments adaptor frame. |
| 3331 | Label runtime; |
| 3332 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3333 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3334 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3335 | __ j(not_equal, &runtime, Label::kNear); |
| 3336 | |
| 3337 | // Patch the arguments.length and the parameters pointer. |
| 3338 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3339 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3340 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3341 | StandardFrameConstants::kCallerSPOffset)); |
| 3342 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3343 | |
| 3344 | __ bind(&runtime); |
| 3345 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3346 | } |
| 3347 | |
| 3348 | |
| 3349 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3350 | // esp[0] : return address |
| 3351 | // esp[4] : number of parameters (tagged) |
| 3352 | // esp[8] : receiver displacement |
| 3353 | // esp[12] : function |
| 3354 | |
| 3355 | // ebx = parameter count (tagged) |
| 3356 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3357 | |
| 3358 | // Check if the calling frame is an arguments adaptor frame. |
| 3359 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3360 | // Generate* functions. |
| 3361 | Label runtime; |
| 3362 | Label adaptor_frame, try_allocate; |
| 3363 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3364 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3365 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3366 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3367 | |
| 3368 | // No adaptor, parameter count = argument count. |
| 3369 | __ mov(ecx, ebx); |
| 3370 | __ jmp(&try_allocate, Label::kNear); |
| 3371 | |
| 3372 | // We have an adaptor frame. Patch the parameters pointer. |
| 3373 | __ bind(&adaptor_frame); |
| 3374 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3375 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3376 | StandardFrameConstants::kCallerSPOffset)); |
| 3377 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3378 | |
| 3379 | // ebx = parameter count (tagged) |
| 3380 | // ecx = argument count (tagged) |
| 3381 | // esp[4] = parameter count (tagged) |
| 3382 | // esp[8] = address of receiver argument |
| 3383 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3384 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3385 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3386 | __ mov(ebx, ecx); |
| 3387 | |
| 3388 | __ bind(&try_allocate); |
| 3389 | |
| 3390 | // Save mapped parameter count. |
| 3391 | __ push(ebx); |
| 3392 | |
| 3393 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3394 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3395 | const int kParameterMapHeaderSize = |
| 3396 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3397 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3398 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3399 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3400 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3401 | __ bind(&no_parameter_map); |
| 3402 | |
| 3403 | // 2. Backing store. |
| 3404 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3405 | |
| 3406 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3407 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3408 | |
| 3409 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3410 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3411 | |
| 3412 | // eax = address of new object(s) (tagged) |
| 3413 | // ecx = argument count (tagged) |
| 3414 | // esp[0] = mapped parameter count (tagged) |
| 3415 | // esp[8] = parameter count (tagged) |
| 3416 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3417 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3418 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3419 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3420 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3421 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3422 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3423 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3424 | __ mov(edi, Operand(edi, |
| 3425 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3426 | __ jmp(©, Label::kNear); |
| 3427 | |
| 3428 | __ bind(&has_mapped_parameters); |
| 3429 | __ mov(edi, Operand(edi, |
| 3430 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3431 | __ bind(©); |
| 3432 | |
| 3433 | // eax = address of new object (tagged) |
| 3434 | // ebx = mapped parameter count (tagged) |
| 3435 | // ecx = argument count (tagged) |
| 3436 | // edi = address of boilerplate object (tagged) |
| 3437 | // esp[0] = mapped parameter count (tagged) |
| 3438 | // esp[8] = parameter count (tagged) |
| 3439 | // esp[12] = address of receiver argument |
| 3440 | // Copy the JS object part. |
| 3441 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3442 | __ mov(edx, FieldOperand(edi, i)); |
| 3443 | __ mov(FieldOperand(eax, i), edx); |
| 3444 | } |
| 3445 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3446 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3447 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3448 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3449 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3450 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3451 | edx); |
| 3452 | |
| 3453 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3454 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3455 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3456 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3457 | ecx); |
| 3458 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3459 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3460 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3461 | // backing store. |
| 3462 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3463 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3464 | |
| 3465 | // eax = address of new object (tagged) |
| 3466 | // ebx = mapped parameter count (tagged) |
| 3467 | // ecx = argument count (tagged) |
| 3468 | // edi = address of parameter map or backing store (tagged) |
| 3469 | // esp[0] = mapped parameter count (tagged) |
| 3470 | // esp[8] = parameter count (tagged) |
| 3471 | // esp[12] = address of receiver argument |
| 3472 | // Free a register. |
| 3473 | __ push(eax); |
| 3474 | |
| 3475 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3476 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3477 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3478 | __ j(zero, &skip_parameter_map); |
| 3479 | |
| 3480 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3481 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3482 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3483 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3484 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3485 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3486 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3487 | |
| 3488 | // Copy the parameter slots and the holes in the arguments. |
| 3489 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3490 | // where parameters are stored in reverse order, at |
| 3491 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3492 | // The mapped parameter thus need to get indices |
| 3493 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3494 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3495 | // We loop from right to left. |
| 3496 | Label parameters_loop, parameters_test; |
| 3497 | __ push(ecx); |
| 3498 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3499 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3500 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3501 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3502 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3503 | __ mov(edx, edi); |
| 3504 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3505 | // eax = loop variable (tagged) |
| 3506 | // ebx = mapping index (tagged) |
| 3507 | // ecx = the hole value |
| 3508 | // edx = address of parameter map (tagged) |
| 3509 | // edi = address of backing store (tagged) |
| 3510 | // esp[0] = argument count (tagged) |
| 3511 | // esp[4] = address of new object (tagged) |
| 3512 | // esp[8] = mapped parameter count (tagged) |
| 3513 | // esp[16] = parameter count (tagged) |
| 3514 | // esp[20] = address of receiver argument |
| 3515 | __ jmp(¶meters_test, Label::kNear); |
| 3516 | |
| 3517 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3518 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3519 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3520 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3521 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3522 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3523 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3524 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3525 | __ pop(ecx); |
| 3526 | |
| 3527 | __ bind(&skip_parameter_map); |
| 3528 | |
| 3529 | // ecx = argument count (tagged) |
| 3530 | // edi = address of backing store (tagged) |
| 3531 | // esp[0] = address of new object (tagged) |
| 3532 | // esp[4] = mapped parameter count (tagged) |
| 3533 | // esp[12] = parameter count (tagged) |
| 3534 | // esp[16] = address of receiver argument |
| 3535 | // Copy arguments header and remaining slots (if there are any). |
| 3536 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3537 | Immediate(FACTORY->fixed_array_map())); |
| 3538 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3539 | |
| 3540 | Label arguments_loop, arguments_test; |
| 3541 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3542 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3543 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3544 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3545 | __ jmp(&arguments_test, Label::kNear); |
| 3546 | |
| 3547 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3548 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3549 | __ mov(eax, Operand(edx, 0)); |
| 3550 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3551 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3552 | |
| 3553 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3554 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3555 | __ j(less, &arguments_loop, Label::kNear); |
| 3556 | |
| 3557 | // Restore. |
| 3558 | __ pop(eax); // Address of arguments object. |
| 3559 | __ pop(ebx); // Parameter count. |
| 3560 | |
| 3561 | // Return and remove the on-stack parameters. |
| 3562 | __ ret(3 * kPointerSize); |
| 3563 | |
| 3564 | // Do the runtime call to allocate the arguments object. |
| 3565 | __ bind(&runtime); |
| 3566 | __ pop(eax); // Remove saved parameter count. |
| 3567 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3568 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | |
| 3572 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3573 | // esp[0] : return address |
| 3574 | // esp[4] : number of parameters |
| 3575 | // esp[8] : receiver displacement |
| 3576 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3577 | |
| 3578 | // Check if the calling frame is an arguments adaptor frame. |
| 3579 | Label adaptor_frame, try_allocate, runtime; |
| 3580 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3581 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3582 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3583 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3584 | |
| 3585 | // Get the length from the frame. |
| 3586 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3587 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3588 | |
| 3589 | // Patch the arguments.length and the parameters pointer. |
| 3590 | __ bind(&adaptor_frame); |
| 3591 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3592 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3593 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3594 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3595 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3596 | |
| 3597 | // Try the new space allocation. Start out with computing the size of |
| 3598 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3599 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3600 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3601 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3602 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3603 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3604 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3605 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3606 | |
| 3607 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3608 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3609 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3610 | // Get the arguments boilerplate from the current native context. |
| 3611 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3612 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3613 | const int offset = |
| 3614 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3615 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3616 | |
| 3617 | // Copy the JS object part. |
| 3618 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3619 | __ mov(ebx, FieldOperand(edi, i)); |
| 3620 | __ mov(FieldOperand(eax, i), ebx); |
| 3621 | } |
| 3622 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3623 | // Get the length (smi tagged) and set that as an in-object property too. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3624 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3625 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3626 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3627 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3628 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3629 | |
| 3630 | // If there are no actual arguments, we're done. |
| 3631 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3632 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3633 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3634 | |
| 3635 | // Get the parameters pointer from the stack. |
| 3636 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3637 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3638 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3639 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3640 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3641 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3642 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3643 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3644 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3645 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3646 | // Untag the length for the loop below. |
| 3647 | __ SmiUntag(ecx); |
| 3648 | |
| 3649 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3650 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3651 | __ bind(&loop); |
| 3652 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3653 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3654 | __ add(edi, Immediate(kPointerSize)); |
| 3655 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | __ dec(ecx); |
| 3657 | __ j(not_zero, &loop); |
| 3658 | |
| 3659 | // Return and remove the on-stack parameters. |
| 3660 | __ bind(&done); |
| 3661 | __ ret(3 * kPointerSize); |
| 3662 | |
| 3663 | // Do the runtime call to allocate the arguments object. |
| 3664 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3665 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | |
| 3669 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3670 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3671 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3672 | // at compilation. |
| 3673 | #ifdef V8_INTERPRETED_REGEXP |
| 3674 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3675 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3676 | |
| 3677 | // Stack frame on entry. |
| 3678 | // esp[0]: return address |
| 3679 | // esp[4]: last_match_info (expected JSArray) |
| 3680 | // esp[8]: previous index |
| 3681 | // esp[12]: subject string |
| 3682 | // esp[16]: JSRegExp object |
| 3683 | |
| 3684 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3685 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3686 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3687 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3688 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3689 | Label runtime; |
| 3690 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3691 | |
| 3692 | // Ensure that a RegExp stack is allocated. |
| 3693 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3694 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3695 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3696 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3697 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3698 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3699 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3700 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3701 | |
| 3702 | // Check that the first argument is a JSRegExp object. |
| 3703 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3704 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3705 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3706 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3707 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3708 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3709 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3710 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3711 | if (FLAG_debug_code) { |
| 3712 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3713 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3714 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3715 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3716 | } |
| 3717 | |
| 3718 | // ecx: RegExp data (FixedArray) |
| 3719 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3720 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3721 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3722 | __ j(not_equal, &runtime); |
| 3723 | |
| 3724 | // ecx: RegExp data (FixedArray) |
| 3725 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3726 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3727 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3728 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3729 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3730 | STATIC_ASSERT(kSmiTag == 0); |
| 3731 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3732 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3733 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3734 | __ j(above, &runtime); |
| 3735 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3736 | // Reset offset for possibly sliced string. |
| 3737 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3738 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3739 | __ JumpIfSmi(eax, &runtime); |
| 3740 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3741 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3742 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3743 | |
| 3744 | // eax: subject string |
| 3745 | // edx: subject string |
| 3746 | // ebx: subject string instance type |
| 3747 | // ecx: RegExp data (FixedArray) |
| 3748 | // Handle subject string according to its encoding and representation: |
| 3749 | // (1) Sequential two byte? If yes, go to (9). |
| 3750 | // (2) Sequential one byte? If yes, go to (6). |
| 3751 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3752 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3753 | // Otherwise bailout. |
| 3754 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3755 | // (5b) Is subject external? If yes, go to (8). |
| 3756 | // (6) One byte sequential. Load regexp code for one byte. |
| 3757 | // (E) Carry on. |
| 3758 | /// [...] |
| 3759 | |
| 3760 | // Deferred code at the end of the stub: |
| 3761 | // (7) Not a long external string? If yes, go to (10). |
| 3762 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3763 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3764 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3765 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3766 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3767 | |
| 3768 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3769 | external_string /* 8 */, check_underlying /* 5a */, |
| 3770 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3771 | not_long_external /* 10 */; |
| 3772 | |
| 3773 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3774 | __ and_(ebx, kIsNotStringMask | |
| 3775 | kStringRepresentationMask | |
| 3776 | kStringEncodingMask | |
| 3777 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3778 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3779 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3780 | |
| 3781 | // (2) Sequential one byte? If yes, go to (6). |
| 3782 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3783 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3784 | kStringRepresentationMask | |
| 3785 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3786 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3787 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3788 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3789 | // We check whether the subject string is a cons, since sequential strings |
| 3790 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3791 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3792 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3793 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3794 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3795 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3796 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3797 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3798 | // (4) Cons string. Check that it's flat. |
| 3799 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3800 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3801 | __ j(not_equal, &runtime); |
| 3802 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3803 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3804 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3805 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3806 | |
| 3807 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3808 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3809 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3810 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3811 | // (5b) Is subject external? If yes, go to (8). |
| 3812 | __ test_b(ebx, kStringRepresentationMask); |
| 3813 | // The underlying external string is never a short external string. |
| 3814 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3815 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3816 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3817 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3818 | // eax: sequential subject string (or look-alike, external string) |
| 3819 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3820 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3821 | // (6) One byte sequential. Load regexp code for one byte. |
| 3822 | __ bind(&seq_one_byte_string); |
| 3823 | // Load previous index and check range before edx is overwritten. We have |
| 3824 | // to use edx instead of eax here because it might have been only made to |
| 3825 | // look like a sequential string when it actually is an external string. |
| 3826 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3827 | __ JumpIfNotSmi(ebx, &runtime); |
| 3828 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3829 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3830 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3831 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3833 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3834 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3835 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3836 | // Check that the irregexp code has been generated for the actual string |
| 3837 | // encoding. If it has, the field contains a code object otherwise it contains |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3838 | // a smi (code flushing support). |
| 3839 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3840 | |
| 3841 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3842 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3843 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3844 | // ecx: encoding of subject string (1 if ASCII, 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3845 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3846 | Counters* counters = masm->isolate()->counters(); |
| 3847 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3849 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3850 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3851 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3852 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3853 | // Argument 9: Pass current isolate address. |
| 3854 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3855 | Immediate(ExternalReference::isolate_address())); |
| 3856 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3857 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3858 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3859 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3860 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3861 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3862 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3863 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3864 | |
| 3865 | // Argument 6: Set the number of capture registers to zero to force global |
| 3866 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3867 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3868 | |
| 3869 | // Argument 5: static offsets vector buffer. |
| 3870 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3871 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3872 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3873 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3874 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3875 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3876 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3877 | |
| 3878 | // Argument 1: Original subject string. |
| 3879 | // The original subject is in the previous stack frame. Therefore we have to |
| 3880 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3881 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3882 | // and thereby moves up esp by one kPointerSize.) |
| 3883 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3884 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3885 | |
| 3886 | // esi: original subject string |
| 3887 | // eax: underlying subject string |
| 3888 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3889 | // ecx: encoding of subject string (1 if ASCII 0 if two_byte); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3890 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3891 | // Argument 4: End of string data |
| 3892 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3893 | // Prepare start and end index of the input. |
| 3894 | // Load the length from the original sliced string if that is the case. |
| 3895 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3896 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3897 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3898 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3899 | |
| 3900 | // ebx: start index of the input string |
| 3901 | // esi: end index of the input string |
| 3902 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3903 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3904 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3905 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3906 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3908 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3909 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3910 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3911 | |
| 3912 | __ bind(&setup_two_byte); |
| 3913 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3914 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3915 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3916 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3917 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3918 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3919 | |
| 3920 | __ bind(&setup_rest); |
| 3921 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3922 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3923 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3924 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3925 | |
| 3926 | // Drop arguments and come back to JS mode. |
| 3927 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3928 | |
| 3929 | // Check the result. |
| 3930 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3931 | __ cmp(eax, 1); |
| 3932 | // We expect exactly one result since we force the called regexp to behave |
| 3933 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3934 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3935 | Label failure; |
| 3936 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3937 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3938 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3939 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3940 | __ j(not_equal, &runtime); |
| 3941 | // Result must now be exception. If there is no pending exception already a |
| 3942 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3943 | // haven't created the exception yet. Handle that in the runtime system. |
| 3944 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3945 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3946 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3947 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3948 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3949 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3950 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3951 | // For exception, throw the exception again. |
| 3952 | |
| 3953 | // Clear the pending exception variable. |
| 3954 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3955 | |
| 3956 | // Special handling of termination exceptions which are uncatchable |
| 3957 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3958 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3959 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3960 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3961 | |
| 3962 | // Handle normal exception by following handler chain. |
| 3963 | __ Throw(eax); |
| 3964 | |
| 3965 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3966 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3967 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3968 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3969 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3970 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | __ ret(4 * kPointerSize); |
| 3972 | |
| 3973 | // Load RegExp data. |
| 3974 | __ bind(&success); |
| 3975 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3976 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3977 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3978 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3979 | STATIC_ASSERT(kSmiTag == 0); |
| 3980 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3981 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3982 | |
| 3983 | // edx: Number of capture registers |
| 3984 | // Load last_match_info which is still known to be a fast case JSArray. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3985 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3987 | __ JumpIfSmi(eax, &runtime); |
| 3988 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3989 | __ j(not_equal, &runtime); |
| 3990 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3991 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3992 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3993 | __ cmp(eax, factory->fixed_array_map()); |
| 3994 | __ j(not_equal, &runtime); |
| 3995 | // Check that the last match info has space for the capture registers and the |
| 3996 | // additional information. |
| 3997 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3998 | __ SmiUntag(eax); |
| 3999 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 4000 | __ cmp(edx, eax); |
| 4001 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4002 | |
| 4003 | // ebx: last_match_info backing store (FixedArray) |
| 4004 | // edx: number of capture registers |
| 4005 | // Store the capture count. |
| 4006 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4007 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4008 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4009 | // Store last subject and last input. |
| 4010 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4011 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4012 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4013 | __ RecordWriteField(ebx, |
| 4014 | RegExpImpl::kLastSubjectOffset, |
| 4015 | eax, |
| 4016 | edi, |
| 4017 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4018 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4019 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4020 | __ RecordWriteField(ebx, |
| 4021 | RegExpImpl::kLastInputOffset, |
| 4022 | eax, |
| 4023 | edi, |
| 4024 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4025 | |
| 4026 | // Get the static offsets vector filled by the native regexp code. |
| 4027 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4028 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4029 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4030 | |
| 4031 | // ebx: last_match_info backing store (FixedArray) |
| 4032 | // ecx: offsets vector |
| 4033 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4034 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4035 | // Capture register counter starts from number of capture registers and |
| 4036 | // counts down until wraping after zero. |
| 4037 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4038 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4039 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4040 | // Read the value from the static offsets vector buffer. |
| 4041 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4042 | __ SmiTag(edi); |
| 4043 | // Store the smi value in the last match info. |
| 4044 | __ mov(FieldOperand(ebx, |
| 4045 | edx, |
| 4046 | times_pointer_size, |
| 4047 | RegExpImpl::kFirstCaptureOffset), |
| 4048 | edi); |
| 4049 | __ jmp(&next_capture); |
| 4050 | __ bind(&done); |
| 4051 | |
| 4052 | // Return last match info. |
| 4053 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4054 | __ ret(4 * kPointerSize); |
| 4055 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4056 | // Do the runtime call to execute the regexp. |
| 4057 | __ bind(&runtime); |
| 4058 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4059 | |
| 4060 | // Deferred code for string handling. |
| 4061 | // (7) Not a long external string? If yes, go to (10). |
| 4062 | __ bind(¬_seq_nor_cons); |
| 4063 | // Compare flags are still set from (3). |
| 4064 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4065 | |
| 4066 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4067 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4068 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4069 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4070 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4071 | if (FLAG_debug_code) { |
| 4072 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4073 | // Sequential strings have already been ruled out. |
| 4074 | __ test_b(ebx, kIsIndirectStringMask); |
| 4075 | __ Assert(zero, "external string expected, but not found"); |
| 4076 | } |
| 4077 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4078 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4079 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4080 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4081 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4082 | // (8a) Is the external string one byte? If yes, go to (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4083 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4084 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4085 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4086 | // eax: sequential subject string (or look-alike, external string) |
| 4087 | // edx: original subject string |
| 4088 | // ecx: RegExp data (FixedArray) |
| 4089 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4090 | __ bind(&seq_two_byte_string); |
| 4091 | // Load previous index and check range before edx is overwritten. We have |
| 4092 | // to use edx instead of eax here because it might have been only made to |
| 4093 | // look like a sequential string when it actually is an external string. |
| 4094 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4095 | __ JumpIfNotSmi(ebx, &runtime); |
| 4096 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4097 | __ j(above_equal, &runtime); |
| 4098 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4099 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4100 | __ jmp(&check_code); // Go to (E). |
| 4101 | |
| 4102 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4103 | __ bind(¬_long_external); |
| 4104 | // Catch non-string subject or short external string. |
| 4105 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4106 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4107 | __ j(not_zero, &runtime); |
| 4108 | |
| 4109 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4110 | // Load offset into edi and replace subject string with parent. |
| 4111 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4112 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4113 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4114 | #endif // V8_INTERPRETED_REGEXP |
| 4115 | } |
| 4116 | |
| 4117 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4118 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4119 | const int kMaxInlineLength = 100; |
| 4120 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4121 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4122 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4123 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4124 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4125 | __ j(above, &slowcase); |
| 4126 | // Smi-tagging is equivalent to multiplying by 2. |
| 4127 | STATIC_ASSERT(kSmiTag == 0); |
| 4128 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4129 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4130 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4131 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4132 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4133 | times_pointer_size, |
| 4134 | ebx, // In: Number of elements as a smi |
| 4135 | REGISTER_VALUE_IS_SMI, |
| 4136 | eax, // Out: Start of allocation (tagged). |
| 4137 | ecx, // Out: End of allocation. |
| 4138 | edx, // Scratch register |
| 4139 | &slowcase, |
| 4140 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4141 | // eax: Start of allocated area, object-tagged. |
| 4142 | |
| 4143 | // Set JSArray map to global.regexp_result_map(). |
| 4144 | // Set empty properties FixedArray. |
| 4145 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4146 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4147 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4148 | Factory* factory = masm->isolate()->factory(); |
| 4149 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4150 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4151 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4152 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4153 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4154 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4155 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4156 | |
| 4157 | // Set input, index and length fields from arguments. |
| 4158 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4159 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4160 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4161 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4162 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4163 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4164 | |
| 4165 | // Fill out the elements FixedArray. |
| 4166 | // eax: JSArray. |
| 4167 | // ebx: FixedArray. |
| 4168 | // ecx: Number of elements in array, as smi. |
| 4169 | |
| 4170 | // Set map. |
| 4171 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4172 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4173 | // Set length. |
| 4174 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4175 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4176 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4177 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4178 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4179 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4180 | // eax: JSArray. |
| 4181 | // ecx: Number of elements to fill. |
| 4182 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4183 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4184 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4185 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4186 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4187 | __ j(less_equal, &done, Label::kNear); // Jump if ecx is negative or zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4188 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4189 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4190 | __ jmp(&loop); |
| 4191 | |
| 4192 | __ bind(&done); |
| 4193 | __ ret(3 * kPointerSize); |
| 4194 | |
| 4195 | __ bind(&slowcase); |
| 4196 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4197 | } |
| 4198 | |
| 4199 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4200 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4201 | Register object, |
| 4202 | Register result, |
| 4203 | Register scratch1, |
| 4204 | Register scratch2, |
| 4205 | bool object_is_smi, |
| 4206 | Label* not_found) { |
| 4207 | // Use of registers. Register result is used as a temporary. |
| 4208 | Register number_string_cache = result; |
| 4209 | Register mask = scratch1; |
| 4210 | Register scratch = scratch2; |
| 4211 | |
| 4212 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4213 | ExternalReference roots_array_start = |
| 4214 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4215 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4216 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4217 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4218 | // Make the hash mask from the length of the number string cache. It |
| 4219 | // contains two elements (number and string) for each cache entry. |
| 4220 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4221 | __ shr(mask, kSmiTagSize + 1); // Untag length and divide it by two. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4222 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4223 | |
| 4224 | // Calculate the entry in the number string cache. The hash value in the |
| 4225 | // number string cache for smis is just the smi value, and the hash for |
| 4226 | // doubles is the xor of the upper and lower words. See |
| 4227 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4228 | Label smi_hash_calculated; |
| 4229 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4230 | if (object_is_smi) { |
| 4231 | __ mov(scratch, object); |
| 4232 | __ SmiUntag(scratch); |
| 4233 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4234 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4235 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4236 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4237 | __ mov(scratch, object); |
| 4238 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4239 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4240 | __ bind(¬_smi); |
| 4241 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4242 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4243 | __ j(not_equal, not_found); |
| 4244 | STATIC_ASSERT(8 == kDoubleSize); |
| 4245 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4246 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4247 | // Object is heap number and hash is now in scratch. Calculate cache index. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4248 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4249 | Register index = scratch; |
| 4250 | Register probe = mask; |
| 4251 | __ mov(probe, |
| 4252 | FieldOperand(number_string_cache, |
| 4253 | index, |
| 4254 | times_twice_pointer_size, |
| 4255 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4256 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4257 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4258 | CpuFeatureScope fscope(masm, SSE2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4259 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4260 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4261 | __ ucomisd(xmm0, xmm1); |
| 4262 | } else { |
| 4263 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4264 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4265 | __ FCmp(); |
| 4266 | } |
| 4267 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4268 | __ j(not_equal, not_found); // The cache did not contain this value. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4269 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | __ bind(&smi_hash_calculated); |
| 4273 | // Object is smi and hash is now in scratch. Calculate cache index. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4274 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4275 | Register index = scratch; |
| 4276 | // Check if the entry is the smi we are looking for. |
| 4277 | __ cmp(object, |
| 4278 | FieldOperand(number_string_cache, |
| 4279 | index, |
| 4280 | times_twice_pointer_size, |
| 4281 | FixedArray::kHeaderSize)); |
| 4282 | __ j(not_equal, not_found); |
| 4283 | |
| 4284 | // Get the result from the cache. |
| 4285 | __ bind(&load_result_from_cache); |
| 4286 | __ mov(result, |
| 4287 | FieldOperand(number_string_cache, |
| 4288 | index, |
| 4289 | times_twice_pointer_size, |
| 4290 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4291 | Counters* counters = masm->isolate()->counters(); |
| 4292 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | |
| 4296 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4297 | Label runtime; |
| 4298 | |
| 4299 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4300 | |
| 4301 | // Generate code to lookup number in the number string cache. |
| 4302 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4303 | __ ret(1 * kPointerSize); |
| 4304 | |
| 4305 | __ bind(&runtime); |
| 4306 | // Handle number to string in the runtime system if not found in the cache. |
| 4307 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4308 | } |
| 4309 | |
| 4310 | |
| 4311 | static int NegativeComparisonResult(Condition cc) { |
| 4312 | ASSERT(cc != equal); |
| 4313 | ASSERT((cc == less) || (cc == less_equal) |
| 4314 | || (cc == greater) || (cc == greater_equal)); |
| 4315 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4316 | } |
| 4317 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4318 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4319 | static void CheckInputType(MacroAssembler* masm, |
| 4320 | Register input, |
| 4321 | CompareIC::State expected, |
| 4322 | Label* fail) { |
| 4323 | Label ok; |
| 4324 | if (expected == CompareIC::SMI) { |
| 4325 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4326 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4327 | __ JumpIfSmi(input, &ok); |
| 4328 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4329 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4330 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4331 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4332 | // We could be strict about internalized/non-internalized here, but as long as |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4333 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4334 | __ bind(&ok); |
| 4335 | } |
| 4336 | |
| 4337 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4338 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4339 | Label* label, |
| 4340 | Register object, |
| 4341 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4342 | __ JumpIfSmi(object, label); |
| 4343 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4344 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4345 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4346 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4347 | __ j(not_equal, label); |
| 4348 | } |
| 4349 | |
| 4350 | |
| 4351 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4352 | Label check_unequal_objects; |
| 4353 | Condition cc = GetCondition(); |
| 4354 | |
| 4355 | Label miss; |
| 4356 | CheckInputType(masm, edx, left_, &miss); |
| 4357 | CheckInputType(masm, eax, right_, &miss); |
| 4358 | |
| 4359 | // Compare two smis. |
| 4360 | Label non_smi, smi_done; |
| 4361 | __ mov(ecx, edx); |
| 4362 | __ or_(ecx, eax); |
| 4363 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4364 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4365 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4366 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4367 | __ bind(&smi_done); |
| 4368 | __ mov(eax, edx); |
| 4369 | __ ret(0); |
| 4370 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4371 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4372 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4373 | // it is certain that at least one operand isn't a smi. |
| 4374 | |
| 4375 | // Identical objects can be compared fast, but there are some tricky cases |
| 4376 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4377 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4378 | { |
| 4379 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4380 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | __ j(not_equal, ¬_identical); |
| 4382 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4383 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4384 | // Check for undefined. undefined OP undefined is false even though |
| 4385 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4386 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4387 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4388 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4389 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4390 | __ ret(0); |
| 4391 | __ bind(&check_for_nan); |
| 4392 | } |
| 4393 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4394 | // Test for NaN. Compare heap numbers in a general way, |
| 4395 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4396 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4397 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4398 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4399 | if (cc != equal) { |
| 4400 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4401 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4402 | __ j(above_equal, ¬_identical); |
| 4403 | } |
| 4404 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4405 | __ ret(0); |
| 4406 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4407 | |
| 4408 | __ bind(¬_identical); |
| 4409 | } |
| 4410 | |
| 4411 | // Strict equality can quickly decide whether objects are equal. |
| 4412 | // Non-strict object equality is slower, so it is handled later in the stub. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4413 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4414 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4415 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4416 | // If we're doing a strict equality comparison, we don't have to do |
| 4417 | // type conversion, so we generate code to do fast comparison for objects |
| 4418 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4419 | // slow-case code. |
| 4420 | // If either is a Smi (we know that not both are), then they can only |
| 4421 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4422 | STATIC_ASSERT(kSmiTag == 0); |
| 4423 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4424 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4425 | __ and_(ecx, eax); |
| 4426 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4427 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4428 | // One operand is a smi. |
| 4429 | |
| 4430 | // Check whether the non-smi is a heap number. |
| 4431 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4432 | // ecx still holds eax & kSmiTag, which is either zero or one. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4433 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4434 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4435 | __ xor_(ebx, eax); |
| 4436 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4437 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4438 | // if eax was smi, ebx is now edx, else eax. |
| 4439 | |
| 4440 | // Check if the non-smi operand is a heap number. |
| 4441 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4442 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4443 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4444 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4445 | // Return non-equal (ebx is not zero) |
| 4446 | __ mov(eax, ebx); |
| 4447 | __ ret(0); |
| 4448 | |
| 4449 | __ bind(¬_smis); |
| 4450 | // If either operand is a JSObject or an oddball value, then they are not |
| 4451 | // equal since their pointers are different |
| 4452 | // There is no test for undetectability in strict equality. |
| 4453 | |
| 4454 | // Get the type of the first operand. |
| 4455 | // If the first object is a JS object, we have done pointer comparison. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4456 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4457 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4458 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4459 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4460 | |
| 4461 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4462 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4463 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4464 | __ bind(&return_not_equal); |
| 4465 | __ ret(0); |
| 4466 | |
| 4467 | __ bind(&first_non_object); |
| 4468 | // Check for oddballs: true, false, null, undefined. |
| 4469 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4470 | __ j(equal, &return_not_equal); |
| 4471 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4472 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4473 | __ j(above_equal, &return_not_equal); |
| 4474 | |
| 4475 | // Check for oddballs: true, false, null, undefined. |
| 4476 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4477 | __ j(equal, &return_not_equal); |
| 4478 | |
| 4479 | // Fall through to the general case. |
| 4480 | __ bind(&slow); |
| 4481 | } |
| 4482 | |
| 4483 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4484 | Label non_number_comparison; |
| 4485 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4486 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4487 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4488 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4489 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4490 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4491 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4492 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4493 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4494 | // Don't base result on EFLAGS when a NaN is involved. |
| 4495 | __ j(parity_even, &unordered, Label::kNear); |
| 4496 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4497 | __ mov(eax, 0); // equal |
| 4498 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4499 | __ cmov(above, eax, ecx); |
| 4500 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4501 | __ cmov(below, eax, ecx); |
| 4502 | __ ret(0); |
| 4503 | } else { |
| 4504 | FloatingPointHelper::CheckFloatOperands( |
| 4505 | masm, &non_number_comparison, ebx); |
| 4506 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4507 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4508 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4509 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4510 | // Don't base result on EFLAGS when a NaN is involved. |
| 4511 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4512 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4513 | Label below_label, above_label; |
| 4514 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4515 | __ j(below, &below_label, Label::kNear); |
| 4516 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4517 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4518 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4519 | __ ret(0); |
| 4520 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4521 | __ bind(&below_label); |
| 4522 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4523 | __ ret(0); |
| 4524 | |
| 4525 | __ bind(&above_label); |
| 4526 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4527 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4528 | } |
| 4529 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4530 | // If one of the numbers was NaN, then the result is always false. |
| 4531 | // The cc is never not-equal. |
| 4532 | __ bind(&unordered); |
| 4533 | ASSERT(cc != not_equal); |
| 4534 | if (cc == less || cc == less_equal) { |
| 4535 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4536 | } else { |
| 4537 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4538 | } |
| 4539 | __ ret(0); |
| 4540 | |
| 4541 | // The number comparison code did not provide a valid result. |
| 4542 | __ bind(&non_number_comparison); |
| 4543 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4544 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4545 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4546 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4547 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4548 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4549 | |
| 4550 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4551 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4552 | // non-zero value, which indicates not equal, so just return. |
| 4553 | __ ret(0); |
| 4554 | } |
| 4555 | |
| 4556 | __ bind(&check_for_strings); |
| 4557 | |
| 4558 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4559 | &check_unequal_objects); |
| 4560 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4561 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4562 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4563 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4564 | edx, |
| 4565 | eax, |
| 4566 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4567 | ebx); |
| 4568 | } else { |
| 4569 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4570 | edx, |
| 4571 | eax, |
| 4572 | ecx, |
| 4573 | ebx, |
| 4574 | edi); |
| 4575 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4576 | #ifdef DEBUG |
| 4577 | __ Abort("Unexpected fall-through from string comparison"); |
| 4578 | #endif |
| 4579 | |
| 4580 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4581 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4582 | // Non-strict equality. Objects are unequal if |
| 4583 | // they are both JSObjects and not undetectable, |
| 4584 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4585 | Label not_both_objects; |
| 4586 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4587 | // At most one is a smi, so we can test for smi by adding the two. |
| 4588 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4589 | // a heap object has the low bit clear. |
| 4590 | STATIC_ASSERT(kSmiTag == 0); |
| 4591 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4592 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4593 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4594 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4595 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4596 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4597 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4598 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4599 | // We do not bail out after this point. Both are JSObjects, and |
| 4600 | // they are equal if and only if both are undetectable. |
| 4601 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4602 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4603 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4604 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4605 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4606 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4607 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4608 | // The objects are both undetectable, so they both compare as the value |
| 4609 | // undefined, and are equal. |
| 4610 | __ Set(eax, Immediate(EQUAL)); |
| 4611 | __ bind(&return_unequal); |
| 4612 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4613 | // or return equal if we fell through to here. |
| 4614 | __ ret(0); // rax, rdx were pushed |
| 4615 | __ bind(¬_both_objects); |
| 4616 | } |
| 4617 | |
| 4618 | // Push arguments below the return address. |
| 4619 | __ pop(ecx); |
| 4620 | __ push(edx); |
| 4621 | __ push(eax); |
| 4622 | |
| 4623 | // Figure out which native to call and setup the arguments. |
| 4624 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4625 | if (cc == equal) { |
| 4626 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4627 | } else { |
| 4628 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4629 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | // Restore return address on the stack. |
| 4633 | __ push(ecx); |
| 4634 | |
| 4635 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4636 | // tagged as a small integer. |
| 4637 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4638 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4639 | __ bind(&miss); |
| 4640 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | |
| 4644 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4645 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4649 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4650 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4651 | } |
| 4652 | |
| 4653 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4654 | static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4655 | // Cache the called function in a global property cell. Cache states |
| 4656 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4657 | // megamorphic. |
| 4658 | // ebx : cache cell for call target |
| 4659 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4660 | ASSERT(!FLAG_optimize_constructed_arrays); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4661 | Isolate* isolate = masm->isolate(); |
| 4662 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4663 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4664 | // Load the cache state into ecx. |
| 4665 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4666 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4667 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4668 | // function without changing the state. |
| 4669 | __ cmp(ecx, edi); |
| 4670 | __ j(equal, &done, Label::kNear); |
| 4671 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4672 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4673 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4674 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4675 | // megamorphic. |
| 4676 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4677 | __ j(equal, &initialize, Label::kNear); |
| 4678 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4679 | // write-barrier is needed. |
| 4680 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4681 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4682 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4683 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4684 | // An uninitialized cache is patched with the function. |
| 4685 | __ bind(&initialize); |
| 4686 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4687 | // No need for a write barrier here - cells are rescanned. |
| 4688 | |
| 4689 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4693 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4694 | // Cache the called function in a global property cell. Cache states |
| 4695 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4696 | // megamorphic. |
| 4697 | // ebx : cache cell for call target |
| 4698 | // edi : the function to call |
| 4699 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4700 | Isolate* isolate = masm->isolate(); |
| 4701 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4702 | |
| 4703 | // Load the cache state into ecx. |
| 4704 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 4705 | |
| 4706 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4707 | // function without changing the state. |
| 4708 | __ cmp(ecx, edi); |
| 4709 | __ j(equal, &done); |
| 4710 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4711 | __ j(equal, &done); |
| 4712 | |
| 4713 | // Special handling of the Array() function, which caches not only the |
| 4714 | // monomorphic Array function but the initial ElementsKind with special |
| 4715 | // sentinels |
| 4716 | Handle<Object> terminal_kind_sentinel = |
| 4717 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4718 | LAST_FAST_ELEMENTS_KIND); |
| 4719 | __ cmp(ecx, Immediate(terminal_kind_sentinel)); |
| 4720 | __ j(above, &miss); |
| 4721 | // Load the global or builtins object from the current context |
| 4722 | __ LoadGlobalContext(ecx); |
| 4723 | // Make sure the function is the Array() function |
| 4724 | __ cmp(edi, Operand(ecx, |
| 4725 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4726 | __ j(not_equal, &megamorphic); |
| 4727 | __ jmp(&done); |
| 4728 | |
| 4729 | __ bind(&miss); |
| 4730 | |
| 4731 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4732 | // megamorphic. |
| 4733 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4734 | __ j(equal, &initialize); |
| 4735 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4736 | // write-barrier is needed. |
| 4737 | __ bind(&megamorphic); |
| 4738 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4739 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4740 | __ jmp(&done, Label::kNear); |
| 4741 | |
| 4742 | // An uninitialized cache is patched with the function or sentinel to |
| 4743 | // indicate the ElementsKind if function is the Array constructor. |
| 4744 | __ bind(&initialize); |
| 4745 | __ LoadGlobalContext(ecx); |
| 4746 | // Make sure the function is the Array() function |
| 4747 | __ cmp(edi, Operand(ecx, |
| 4748 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4749 | __ j(not_equal, ¬_array_function); |
| 4750 | |
| 4751 | // The target function is the Array constructor, install a sentinel value in |
| 4752 | // the constructor's type info cell that will track the initial ElementsKind |
| 4753 | // that should be used for the array when its constructed. |
| 4754 | Handle<Object> initial_kind_sentinel = |
| 4755 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4756 | GetInitialFastElementsKind()); |
| 4757 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4758 | Immediate(initial_kind_sentinel)); |
| 4759 | __ jmp(&done); |
| 4760 | |
| 4761 | __ bind(¬_array_function); |
| 4762 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4763 | // No need for a write barrier here - cells are rescanned. |
| 4764 | |
| 4765 | __ bind(&done); |
| 4766 | } |
| 4767 | |
| 4768 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4769 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4770 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4771 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4772 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4773 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4774 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4775 | // The receiver might implicitly be the global object. This is |
| 4776 | // indicated by passing the hole as the receiver to the call |
| 4777 | // function stub. |
| 4778 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4779 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4780 | // Get the receiver from the stack. |
| 4781 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4782 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4783 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4784 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4785 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4786 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4787 | __ mov(ecx, GlobalObjectOperand()); |
| 4788 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4789 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4790 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4793 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4794 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4795 | // Goto slow case if we do not have a function. |
| 4796 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4797 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4798 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4799 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4800 | if (FLAG_optimize_constructed_arrays) { |
| 4801 | GenerateRecordCallTarget(masm); |
| 4802 | } else { |
| 4803 | GenerateRecordCallTargetNoArray(masm); |
| 4804 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4805 | } |
| 4806 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | // Fast-case: Just invoke the function. |
| 4808 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4809 | |
| 4810 | if (ReceiverMightBeImplicit()) { |
| 4811 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4812 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4813 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4814 | __ InvokeFunction(edi, |
| 4815 | actual, |
| 4816 | JUMP_FUNCTION, |
| 4817 | NullCallWrapper(), |
| 4818 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4819 | __ bind(&call_as_function); |
| 4820 | } |
| 4821 | __ InvokeFunction(edi, |
| 4822 | actual, |
| 4823 | JUMP_FUNCTION, |
| 4824 | NullCallWrapper(), |
| 4825 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4826 | |
| 4827 | // Slow-case: Non-function called. |
| 4828 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4829 | if (RecordCallTarget()) { |
| 4830 | // If there is a call target cache, mark it megamorphic in the |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4831 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4832 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4833 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4834 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4835 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4836 | // Check for function proxy. |
| 4837 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4838 | __ j(not_equal, &non_function); |
| 4839 | __ pop(ecx); |
| 4840 | __ push(edi); // put proxy as additional argument under return address |
| 4841 | __ push(ecx); |
| 4842 | __ Set(eax, Immediate(argc_ + 1)); |
| 4843 | __ Set(ebx, Immediate(0)); |
| 4844 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4845 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4846 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4847 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4848 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4849 | } |
| 4850 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4851 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4852 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4853 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4854 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4855 | __ Set(eax, Immediate(argc_)); |
| 4856 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4857 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4858 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4859 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4860 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4861 | } |
| 4862 | |
| 4863 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4864 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4865 | // eax : number of arguments |
| 4866 | // ebx : cache cell for call target |
| 4867 | // edi : constructor function |
| 4868 | Label slow, non_function_call; |
| 4869 | |
| 4870 | // Check that function is not a smi. |
| 4871 | __ JumpIfSmi(edi, &non_function_call); |
| 4872 | // Check that function is a JSFunction. |
| 4873 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4874 | __ j(not_equal, &slow); |
| 4875 | |
| 4876 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4877 | if (FLAG_optimize_constructed_arrays) { |
| 4878 | GenerateRecordCallTarget(masm); |
| 4879 | } else { |
| 4880 | GenerateRecordCallTargetNoArray(masm); |
| 4881 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | // Jump to the function-specific construct stub. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4885 | Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; |
| 4886 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4887 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4888 | SharedFunctionInfo::kConstructStubOffset)); |
| 4889 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4890 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4891 | |
| 4892 | // edi: called object |
| 4893 | // eax: number of arguments |
| 4894 | // ecx: object map |
| 4895 | Label do_call; |
| 4896 | __ bind(&slow); |
| 4897 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4898 | __ j(not_equal, &non_function_call); |
| 4899 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4900 | __ jmp(&do_call); |
| 4901 | |
| 4902 | __ bind(&non_function_call); |
| 4903 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4904 | __ bind(&do_call); |
| 4905 | // Set expected number of arguments to zero (not changing eax). |
| 4906 | __ Set(ebx, Immediate(0)); |
| 4907 | Handle<Code> arguments_adaptor = |
| 4908 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4909 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4910 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4911 | } |
| 4912 | |
| 4913 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4914 | bool CEntryStub::NeedsImmovableCode() { |
| 4915 | return false; |
| 4916 | } |
| 4917 | |
| 4918 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4919 | bool CEntryStub::IsPregenerated() { |
| 4920 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4921 | result_size_ == 1; |
| 4922 | } |
| 4923 | |
| 4924 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4925 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4926 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4927 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 4928 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4929 | // It is important that the store buffer overflow stubs are generated first. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4930 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4934 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4935 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4936 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4937 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4938 | // which would lead to code stub initialization state being messed up. |
| 4939 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4940 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4941 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4942 | } |
| 4943 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4944 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4945 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4949 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4950 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4951 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4952 | code->set_is_pregenerated(true); |
| 4953 | } |
| 4954 | |
| 4955 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4956 | static void JumpIfOOM(MacroAssembler* masm, |
| 4957 | Register value, |
| 4958 | Register scratch, |
| 4959 | Label* oom_label) { |
| 4960 | __ mov(scratch, value); |
| 4961 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4962 | STATIC_ASSERT(kFailureTag == 3); |
| 4963 | __ and_(scratch, 0xf); |
| 4964 | __ cmp(scratch, 0xf); |
| 4965 | __ j(equal, oom_label); |
| 4966 | } |
| 4967 | |
| 4968 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4969 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4970 | Label* throw_normal_exception, |
| 4971 | Label* throw_termination_exception, |
| 4972 | Label* throw_out_of_memory_exception, |
| 4973 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4974 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4975 | // eax: result parameter for PerformGC, if any |
| 4976 | // ebx: pointer to C function (C callee-saved) |
| 4977 | // ebp: frame pointer (restored after C call) |
| 4978 | // esp: stack pointer (restored after C call) |
| 4979 | // edi: number of arguments including receiver (C callee-saved) |
| 4980 | // esi: pointer to the first argument (C callee-saved) |
| 4981 | |
| 4982 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4983 | |
| 4984 | // Check stack alignment. |
| 4985 | if (FLAG_debug_code) { |
| 4986 | __ CheckStackAlignment(); |
| 4987 | } |
| 4988 | |
| 4989 | if (do_gc) { |
| 4990 | // Pass failure code returned from last attempt as first argument to |
| 4991 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4992 | // stack alignment is known to be correct. This function takes one argument |
| 4993 | // which is passed on the stack, and we know that the stack has been |
| 4994 | // prepared to pass at least one argument. |
| 4995 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4996 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4997 | } |
| 4998 | |
| 4999 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5000 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5001 | if (always_allocate_scope) { |
| 5002 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5003 | } |
| 5004 | |
| 5005 | // Call C function. |
| 5006 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5007 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5008 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5009 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5010 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5011 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5012 | |
| 5013 | if (always_allocate_scope) { |
| 5014 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5015 | } |
| 5016 | |
| 5017 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5018 | // call as this may lead to crashes in the IC code later. |
| 5019 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5020 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5021 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5022 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5023 | __ int3(); |
| 5024 | __ bind(&okay); |
| 5025 | } |
| 5026 | |
| 5027 | // Check for failure result. |
| 5028 | Label failure_returned; |
| 5029 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5030 | __ lea(ecx, Operand(eax, 1)); |
| 5031 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5032 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5033 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5034 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5035 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5036 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5037 | |
| 5038 | // Check that there is no pending exception, otherwise we |
| 5039 | // should have returned some failure value. |
| 5040 | if (FLAG_debug_code) { |
| 5041 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5042 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5043 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5044 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5045 | // Cannot use check here as it attempts to generate call into runtime. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5046 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5047 | __ int3(); |
| 5048 | __ bind(&okay); |
| 5049 | __ pop(edx); |
| 5050 | } |
| 5051 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5052 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5053 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5054 | __ ret(0); |
| 5055 | |
| 5056 | // Handling of failure. |
| 5057 | __ bind(&failure_returned); |
| 5058 | |
| 5059 | Label retry; |
| 5060 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5061 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5062 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5063 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5064 | |
| 5065 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5066 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5067 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 5068 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5069 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 5070 | |
| 5071 | // See if we just retrieved an OOM exception. |
| 5072 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 5073 | |
| 5074 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5075 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5076 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5077 | |
| 5078 | // Special handling of termination exceptions which are uncatchable |
| 5079 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5080 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5081 | __ j(equal, throw_termination_exception); |
| 5082 | |
| 5083 | // Handle normal exception. |
| 5084 | __ jmp(throw_normal_exception); |
| 5085 | |
| 5086 | // Retry. |
| 5087 | __ bind(&retry); |
| 5088 | } |
| 5089 | |
| 5090 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5091 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5092 | // eax: number of arguments including receiver |
| 5093 | // ebx: pointer to C function (C callee-saved) |
| 5094 | // ebp: frame pointer (restored after C call) |
| 5095 | // esp: stack pointer (restored after C call) |
| 5096 | // esi: current context (C callee-saved) |
| 5097 | // edi: JS function of the caller (C callee-saved) |
| 5098 | |
| 5099 | // NOTE: Invocations of builtins may return failure objects instead |
| 5100 | // of a proper result. The builtin entry handles this by performing |
| 5101 | // a garbage collection and retrying the builtin (twice). |
| 5102 | |
| 5103 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5104 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5105 | |
| 5106 | // eax: result parameter for PerformGC, if any (setup below) |
| 5107 | // ebx: pointer to builtin function (C callee-saved) |
| 5108 | // ebp: frame pointer (restored after C call) |
| 5109 | // esp: stack pointer (restored after C call) |
| 5110 | // edi: number of arguments including receiver (C callee-saved) |
| 5111 | // esi: argv pointer (C callee-saved) |
| 5112 | |
| 5113 | Label throw_normal_exception; |
| 5114 | Label throw_termination_exception; |
| 5115 | Label throw_out_of_memory_exception; |
| 5116 | |
| 5117 | // Call into the runtime system. |
| 5118 | GenerateCore(masm, |
| 5119 | &throw_normal_exception, |
| 5120 | &throw_termination_exception, |
| 5121 | &throw_out_of_memory_exception, |
| 5122 | false, |
| 5123 | false); |
| 5124 | |
| 5125 | // Do space-specific GC and retry runtime call. |
| 5126 | GenerateCore(masm, |
| 5127 | &throw_normal_exception, |
| 5128 | &throw_termination_exception, |
| 5129 | &throw_out_of_memory_exception, |
| 5130 | true, |
| 5131 | false); |
| 5132 | |
| 5133 | // Do full GC and retry runtime call one final time. |
| 5134 | Failure* failure = Failure::InternalError(); |
| 5135 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5136 | GenerateCore(masm, |
| 5137 | &throw_normal_exception, |
| 5138 | &throw_termination_exception, |
| 5139 | &throw_out_of_memory_exception, |
| 5140 | true, |
| 5141 | true); |
| 5142 | |
| 5143 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5144 | // Set external caught exception to false. |
| 5145 | Isolate* isolate = masm->isolate(); |
| 5146 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5147 | isolate); |
| 5148 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5149 | |
| 5150 | // Set pending exception and eax to out of memory exception. |
| 5151 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5152 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5153 | Label already_have_failure; |
| 5154 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5155 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5156 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5157 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5158 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5159 | |
| 5160 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5161 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5162 | |
| 5163 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5164 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | |
| 5168 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5169 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5170 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5171 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5172 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5173 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5174 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5175 | |
| 5176 | // Push marker in two places. |
| 5177 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5178 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5179 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5180 | // Save callee-saved registers (C calling conventions). |
| 5181 | __ push(edi); |
| 5182 | __ push(esi); |
| 5183 | __ push(ebx); |
| 5184 | |
| 5185 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5186 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5187 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5188 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5189 | // If this is the outermost JS call, set js_entry_sp value. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5190 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5191 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5192 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5193 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5194 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5195 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5196 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5197 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5198 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5199 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5200 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5201 | // block that sets the pending exception. |
| 5202 | __ jmp(&invoke); |
| 5203 | __ bind(&handler_entry); |
| 5204 | handler_offset_ = handler_entry.pos(); |
| 5205 | // Caught exception: Store result (exception) in the pending exception |
| 5206 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5207 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5208 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5209 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5210 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5211 | __ jmp(&exit); |
| 5212 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5213 | // Invoke: Link this frame into the handler chain. There's only one |
| 5214 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5215 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5216 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5217 | |
| 5218 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5219 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5220 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5221 | |
| 5222 | // Fake a receiver (NULL). |
| 5223 | __ push(Immediate(0)); // receiver |
| 5224 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5225 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5226 | // pop the faked function when we return. Notice that we cannot store a |
| 5227 | // reference to the trampoline code directly in this stub, because the |
| 5228 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5230 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5231 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | __ mov(edx, Immediate(construct_entry)); |
| 5233 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5234 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5235 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5236 | __ mov(edx, Immediate(entry)); |
| 5237 | } |
| 5238 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5239 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5240 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5241 | |
| 5242 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5243 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5244 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5245 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5246 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5247 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5248 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5249 | __ j(not_equal, ¬_outermost_js_2); |
| 5250 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5251 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5252 | |
| 5253 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5254 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5255 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5256 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5257 | |
| 5258 | // Restore callee-saved registers (C calling conventions). |
| 5259 | __ pop(ebx); |
| 5260 | __ pop(esi); |
| 5261 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5262 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | |
| 5264 | // Restore frame pointer and return. |
| 5265 | __ pop(ebp); |
| 5266 | __ ret(0); |
| 5267 | } |
| 5268 | |
| 5269 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5270 | // Generate stub code for instanceof. |
| 5271 | // This code can patch a call site inlined cache of the instance of check, |
| 5272 | // which looks like this. |
| 5273 | // |
| 5274 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5275 | // 75 0a jne <some near label> |
| 5276 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5277 | // |
| 5278 | // If call site patching is requested the stack will have the delta from the |
| 5279 | // return address to the cmp instruction just below the return address. This |
| 5280 | // also means that call site patching can only take place with arguments in |
| 5281 | // registers. TOS looks like this when call site patching is requested |
| 5282 | // |
| 5283 | // esp[0] : return address |
| 5284 | // esp[4] : delta from return address to cmp instruction |
| 5285 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5286 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5287 | // Call site inlining and patching implies arguments in registers. |
| 5288 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5289 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5290 | // Fixed register usage throughout the stub. |
| 5291 | Register object = eax; // Object (lhs). |
| 5292 | Register map = ebx; // Map of the object. |
| 5293 | Register function = edx; // Function (rhs). |
| 5294 | Register prototype = edi; // Prototype of the function. |
| 5295 | Register scratch = ecx; |
| 5296 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5297 | // Constants describing the call site code to patch. |
| 5298 | static const int kDeltaToCmpImmediate = 2; |
| 5299 | static const int kDeltaToMov = 8; |
| 5300 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5301 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5302 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5303 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5304 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5305 | ExternalReference roots_array_start = |
| 5306 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5307 | |
| 5308 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5309 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5310 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5311 | // Get the object and function - they are always both needed. |
| 5312 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5313 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5314 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5315 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5316 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5317 | |
| 5318 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5319 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5320 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5321 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5322 | // If there is a call site cache don't look in the global cache, but do the |
| 5323 | // real lookup and update the call site cache. |
| 5324 | if (!HasCallSiteInlineCheck()) { |
| 5325 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5326 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5327 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5328 | __ cmp(function, Operand::StaticArray(scratch, |
| 5329 | times_pointer_size, |
| 5330 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5331 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5332 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5333 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5334 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5335 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5336 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5337 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5338 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5339 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5340 | __ bind(&miss); |
| 5341 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5342 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5343 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5344 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5345 | |
| 5346 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5347 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5348 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5349 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5350 | // Update the global instanceof or call site inlined cache with the current |
| 5351 | // map and function. The cached answer will be set when it is known below. |
| 5352 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5353 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5354 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5355 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5356 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5357 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5358 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5359 | } else { |
| 5360 | // The constants for the code patching are based on no push instructions |
| 5361 | // at the call site. |
| 5362 | ASSERT(HasArgsInRegisters()); |
| 5363 | // Get return address and delta to inlined map check. |
| 5364 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5365 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5366 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5367 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5368 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5369 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5370 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5371 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5372 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5373 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5374 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5375 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5376 | // Loop through the prototype chain of the object looking for the function |
| 5377 | // prototype. |
| 5378 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5379 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5380 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5381 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5382 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5383 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5384 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5385 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5386 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5387 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5388 | __ jmp(&loop); |
| 5389 | |
| 5390 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5391 | if (!HasCallSiteInlineCheck()) { |
| 5392 | __ Set(eax, Immediate(0)); |
| 5393 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5394 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5395 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5396 | } else { |
| 5397 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5398 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5399 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5400 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5401 | if (FLAG_debug_code) { |
| 5402 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5403 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5404 | } |
| 5405 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5406 | if (!ReturnTrueFalseObject()) { |
| 5407 | __ Set(eax, Immediate(0)); |
| 5408 | } |
| 5409 | } |
| 5410 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5411 | |
| 5412 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5413 | if (!HasCallSiteInlineCheck()) { |
| 5414 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5415 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5416 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5417 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5418 | } else { |
| 5419 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5420 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5421 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5422 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5423 | if (FLAG_debug_code) { |
| 5424 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5425 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5426 | } |
| 5427 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5428 | if (!ReturnTrueFalseObject()) { |
| 5429 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5430 | } |
| 5431 | } |
| 5432 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5433 | |
| 5434 | Label object_not_null, object_not_null_or_smi; |
| 5435 | __ bind(¬_js_object); |
| 5436 | // Before null, smi and string value checks, check that the rhs is a function |
| 5437 | // as for a non-function rhs an exception needs to be thrown. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5438 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5439 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5440 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5441 | |
| 5442 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5443 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5444 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5445 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5446 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5447 | |
| 5448 | __ bind(&object_not_null); |
| 5449 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5450 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5451 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5452 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5453 | |
| 5454 | __ bind(&object_not_null_or_smi); |
| 5455 | // String values is not instance of anything. |
| 5456 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5457 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5458 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5459 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5460 | |
| 5461 | // Slow-case: Go through the JavaScript implementation. |
| 5462 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5463 | if (!ReturnTrueFalseObject()) { |
| 5464 | // Tail call the builtin which returns 0 or 1. |
| 5465 | if (HasArgsInRegisters()) { |
| 5466 | // Push arguments below return address. |
| 5467 | __ pop(scratch); |
| 5468 | __ push(object); |
| 5469 | __ push(function); |
| 5470 | __ push(scratch); |
| 5471 | } |
| 5472 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5473 | } else { |
| 5474 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5475 | { |
| 5476 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5477 | __ push(object); |
| 5478 | __ push(function); |
| 5479 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5480 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5481 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5482 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5483 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5484 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5485 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5486 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5487 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5488 | __ bind(&done); |
| 5489 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5490 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5494 | Register InstanceofStub::left() { return eax; } |
| 5495 | |
| 5496 | |
| 5497 | Register InstanceofStub::right() { return edx; } |
| 5498 | |
| 5499 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5500 | // ------------------------------------------------------------------------- |
| 5501 | // StringCharCodeAtGenerator |
| 5502 | |
| 5503 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5504 | // If the receiver is a smi trigger the non-string case. |
| 5505 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5506 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5507 | |
| 5508 | // Fetch the instance type of the receiver into result register. |
| 5509 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5510 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5511 | // If the receiver is not a string trigger the non-string case. |
| 5512 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5513 | __ j(not_zero, receiver_not_string_); |
| 5514 | |
| 5515 | // If the index is non-smi trigger the non-smi case. |
| 5516 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5517 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | __ bind(&got_smi_index_); |
| 5519 | |
| 5520 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5521 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5522 | __ j(above_equal, index_out_of_range_); |
| 5523 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5524 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5525 | |
| 5526 | Factory* factory = masm->isolate()->factory(); |
| 5527 | StringCharLoadGenerator::Generate( |
| 5528 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5529 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5530 | __ SmiTag(result_); |
| 5531 | __ bind(&exit_); |
| 5532 | } |
| 5533 | |
| 5534 | |
| 5535 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5536 | MacroAssembler* masm, |
| 5537 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5538 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5539 | |
| 5540 | // Index is not a smi. |
| 5541 | __ bind(&index_not_smi_); |
| 5542 | // If index is a heap number, try converting it to an integer. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5543 | __ CheckMap(index_, |
| 5544 | masm->isolate()->factory()->heap_number_map(), |
| 5545 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5546 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | call_helper.BeforeCall(masm); |
| 5548 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5549 | __ push(index_); // Consumed by runtime conversion function. |
| 5550 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5551 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5552 | } else { |
| 5553 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5554 | // NumberToSmi discards numbers that are not exact integers. |
| 5555 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5556 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5557 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5558 | // Save the conversion result before the pop instructions below |
| 5559 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5560 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5561 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5562 | __ pop(object_); |
| 5563 | // Reload the instance type. |
| 5564 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5565 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5566 | call_helper.AfterCall(masm); |
| 5567 | // If index is still not a smi, it must be out of range. |
| 5568 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5569 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5570 | // Otherwise, return to the fast path. |
| 5571 | __ jmp(&got_smi_index_); |
| 5572 | |
| 5573 | // Call runtime. We get here when the receiver is a string and the |
| 5574 | // index is a number, but the code of getting the actual character |
| 5575 | // is too complex (e.g., when the string needs to be flattened). |
| 5576 | __ bind(&call_runtime_); |
| 5577 | call_helper.BeforeCall(masm); |
| 5578 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5579 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5580 | __ push(index_); |
| 5581 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5582 | if (!result_.is(eax)) { |
| 5583 | __ mov(result_, eax); |
| 5584 | } |
| 5585 | call_helper.AfterCall(masm); |
| 5586 | __ jmp(&exit_); |
| 5587 | |
| 5588 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5589 | } |
| 5590 | |
| 5591 | |
| 5592 | // ------------------------------------------------------------------------- |
| 5593 | // StringCharFromCodeGenerator |
| 5594 | |
| 5595 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5596 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5597 | STATIC_ASSERT(kSmiTag == 0); |
| 5598 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5599 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5600 | __ test(code_, |
| 5601 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5602 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5603 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5604 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5605 | Factory* factory = masm->isolate()->factory(); |
| 5606 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5607 | STATIC_ASSERT(kSmiTag == 0); |
| 5608 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5609 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5610 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5611 | __ mov(result_, FieldOperand(result_, |
| 5612 | code_, times_half_pointer_size, |
| 5613 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5614 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5615 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5616 | __ bind(&exit_); |
| 5617 | } |
| 5618 | |
| 5619 | |
| 5620 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5621 | MacroAssembler* masm, |
| 5622 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5623 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5624 | |
| 5625 | __ bind(&slow_case_); |
| 5626 | call_helper.BeforeCall(masm); |
| 5627 | __ push(code_); |
| 5628 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5629 | if (!result_.is(eax)) { |
| 5630 | __ mov(result_, eax); |
| 5631 | } |
| 5632 | call_helper.AfterCall(masm); |
| 5633 | __ jmp(&exit_); |
| 5634 | |
| 5635 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5636 | } |
| 5637 | |
| 5638 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5639 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5640 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5641 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5642 | |
| 5643 | // Load the two arguments. |
| 5644 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5645 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5646 | |
| 5647 | // Make sure that both arguments are strings if not known in advance. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5648 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5649 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5650 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5651 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5652 | |
| 5653 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5654 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5655 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5656 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5657 | } else { |
| 5658 | // Here at least one of the arguments is definitely a string. |
| 5659 | // We convert the one that is not known to be a string. |
| 5660 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5661 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5662 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5663 | &call_builtin); |
| 5664 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5665 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5666 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5667 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5668 | &call_builtin); |
| 5669 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5670 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | // Both arguments are strings. |
| 5674 | // eax: first string |
| 5675 | // edx: second string |
| 5676 | // Check if either of the strings are empty. In that case return the other. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5677 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5678 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5679 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5680 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5681 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5682 | // Second string is empty, result is first string which is already in eax. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5683 | Counters* counters = masm->isolate()->counters(); |
| 5684 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5685 | __ ret(2 * kPointerSize); |
| 5686 | __ bind(&second_not_zero_length); |
| 5687 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5688 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5689 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5690 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5691 | // First string is empty, result is second string which is in edx. |
| 5692 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5693 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5694 | __ ret(2 * kPointerSize); |
| 5695 | |
| 5696 | // Both strings are non-empty. |
| 5697 | // eax: first string |
| 5698 | // ebx: length of first string as a smi |
| 5699 | // ecx: length of second string as a smi |
| 5700 | // edx: second string |
| 5701 | // Look at the length of the result of adding the two strings. |
| 5702 | Label string_add_flat_result, longer_than_two; |
| 5703 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5704 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5705 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5706 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5707 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5708 | // Use the string table when adding two one character strings, as it |
| 5709 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5710 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5711 | __ j(not_equal, &longer_than_two); |
| 5712 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5713 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5714 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5715 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5716 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5717 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5718 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5719 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5720 | // Try to lookup two character string in string table. If it is not found |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5721 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5722 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5723 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5724 | masm, ebx, ecx, eax, edx, edi, |
| 5725 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5726 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5727 | __ ret(2 * kPointerSize); |
| 5728 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5729 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5730 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5731 | // Reload the arguments. |
| 5732 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5733 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5734 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5735 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5736 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5737 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5738 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5739 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5740 | // Pack both characters in ebx. |
| 5741 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5742 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5743 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5744 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5745 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5746 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5747 | |
| 5748 | __ bind(&longer_than_two); |
| 5749 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5750 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5751 | __ j(below, &string_add_flat_result); |
| 5752 | |
| 5753 | // If result is not supposed to be flat allocate a cons string object. If both |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5754 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5755 | Label non_ascii, allocated, ascii_data; |
| 5756 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5757 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5758 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5759 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5760 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5761 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5762 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5763 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5764 | __ j(zero, &non_ascii); |
| 5765 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5766 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5767 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5768 | __ bind(&allocated); |
| 5769 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5770 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5771 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5772 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5773 | Immediate(String::kEmptyHashField)); |
| 5774 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5775 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5776 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5777 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5778 | __ ret(2 * kPointerSize); |
| 5779 | __ bind(&non_ascii); |
| 5780 | // At least one of the strings is two-byte. Check whether it happens |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5781 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5782 | // ecx: first instance type AND second instance type. |
| 5783 | // edi: second instance type. |
| 5784 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5785 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5786 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5787 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5788 | __ xor_(edi, ecx); |
| 5789 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5790 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5791 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5792 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5793 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5794 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5795 | __ jmp(&allocated); |
| 5796 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5797 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5798 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5799 | // Handle creating a flat result from either external or sequential strings. |
| 5800 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5801 | // eax: first string |
| 5802 | // ebx: length of resulting flat string as a smi |
| 5803 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5804 | Label first_prepared, second_prepared; |
| 5805 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5806 | __ bind(&string_add_flat_result); |
| 5807 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5808 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5809 | // ecx: instance type of first string |
| 5810 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5811 | __ test_b(ecx, kStringRepresentationMask); |
| 5812 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5813 | // Rule out short external string and load string resource. |
| 5814 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5815 | __ test_b(ecx, kShortExternalStringMask); |
| 5816 | __ j(not_zero, &call_runtime); |
| 5817 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5818 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5819 | __ jmp(&first_prepared, Label::kNear); |
| 5820 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5821 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5822 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5823 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5824 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5825 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5826 | // Check whether both strings have same encoding. |
| 5827 | // edi: instance type of second string |
| 5828 | __ xor_(ecx, edi); |
| 5829 | __ test_b(ecx, kStringEncodingMask); |
| 5830 | __ j(not_zero, &call_runtime); |
| 5831 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5832 | __ test_b(edi, kStringRepresentationMask); |
| 5833 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5834 | // Rule out short external string and load string resource. |
| 5835 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5836 | __ test_b(edi, kShortExternalStringMask); |
| 5837 | __ j(not_zero, &call_runtime); |
| 5838 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5839 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5840 | __ jmp(&second_prepared, Label::kNear); |
| 5841 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5842 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5843 | __ bind(&second_prepared); |
| 5844 | |
| 5845 | // Push the addresses of both strings' first characters onto the stack. |
| 5846 | __ push(edx); |
| 5847 | __ push(eax); |
| 5848 | |
| 5849 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5850 | // edi: instance type of second string |
| 5851 | // First string and second string have the same encoding. |
| 5852 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5853 | __ test_b(edi, kStringEncodingMask); |
| 5854 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5855 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5856 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5857 | // ebx: length of resulting flat string as a smi |
| 5858 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5859 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5860 | // eax: result string |
| 5861 | __ mov(ecx, eax); |
| 5862 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5863 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5864 | // Load first argument's length and first character location. Account for |
| 5865 | // values currently on the stack when fetching arguments from it. |
| 5866 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5867 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5868 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5869 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5870 | // eax: result string |
| 5871 | // ecx: first character of result |
| 5872 | // edx: first char of first argument |
| 5873 | // edi: length of first argument |
| 5874 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5875 | // Load second argument's length and first character location. Account for |
| 5876 | // values currently on the stack when fetching arguments from it. |
| 5877 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5878 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5879 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5880 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | // eax: result string |
| 5882 | // ecx: next character of result |
| 5883 | // edx: first char of second argument |
| 5884 | // edi: length of second argument |
| 5885 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5886 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5887 | __ ret(2 * kPointerSize); |
| 5888 | |
| 5889 | // Handle creating a flat two byte result. |
| 5890 | // eax: first string - known to be two byte |
| 5891 | // ebx: length of resulting flat string as a smi |
| 5892 | // edx: second string |
| 5893 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5894 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5896 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5897 | // eax: result string |
| 5898 | __ mov(ecx, eax); |
| 5899 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5900 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5901 | // Load second argument's length and first character location. Account for |
| 5902 | // values currently on the stack when fetching arguments from it. |
| 5903 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5904 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5905 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5906 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5907 | // eax: result string |
| 5908 | // ecx: first character of result |
| 5909 | // edx: first char of first argument |
| 5910 | // edi: length of first argument |
| 5911 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5912 | // Load second argument's length and first character location. Account for |
| 5913 | // values currently on the stack when fetching arguments from it. |
| 5914 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5915 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5916 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5917 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5918 | // eax: result string |
| 5919 | // ecx: next character of result |
| 5920 | // edx: first char of second argument |
| 5921 | // edi: length of second argument |
| 5922 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5923 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5924 | __ ret(2 * kPointerSize); |
| 5925 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5926 | // Recover stack pointer before jumping to runtime. |
| 5927 | __ bind(&call_runtime_drop_two); |
| 5928 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5929 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5930 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5931 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5932 | |
| 5933 | if (call_builtin.is_linked()) { |
| 5934 | __ bind(&call_builtin); |
| 5935 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5936 | } |
| 5937 | } |
| 5938 | |
| 5939 | |
| 5940 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5941 | int stack_offset, |
| 5942 | Register arg, |
| 5943 | Register scratch1, |
| 5944 | Register scratch2, |
| 5945 | Register scratch3, |
| 5946 | Label* slow) { |
| 5947 | // First check if the argument is already a string. |
| 5948 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5949 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5950 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5951 | __ j(below, &done); |
| 5952 | |
| 5953 | // Check the number to string cache. |
| 5954 | Label not_cached; |
| 5955 | __ bind(¬_string); |
| 5956 | // Puts the cached result into scratch1. |
| 5957 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5958 | arg, |
| 5959 | scratch1, |
| 5960 | scratch2, |
| 5961 | scratch3, |
| 5962 | false, |
| 5963 | ¬_cached); |
| 5964 | __ mov(arg, scratch1); |
| 5965 | __ mov(Operand(esp, stack_offset), arg); |
| 5966 | __ jmp(&done); |
| 5967 | |
| 5968 | // Check if the argument is a safe string wrapper. |
| 5969 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5970 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5971 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5972 | __ j(not_equal, slow); |
| 5973 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5974 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5975 | __ j(zero, slow); |
| 5976 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5977 | __ mov(Operand(esp, stack_offset), arg); |
| 5978 | |
| 5979 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | |
| 5983 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5984 | Register dest, |
| 5985 | Register src, |
| 5986 | Register count, |
| 5987 | Register scratch, |
| 5988 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5989 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5990 | __ bind(&loop); |
| 5991 | // This loop just copies one character at a time, as it is only used for very |
| 5992 | // short strings. |
| 5993 | if (ascii) { |
| 5994 | __ mov_b(scratch, Operand(src, 0)); |
| 5995 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5996 | __ add(src, Immediate(1)); |
| 5997 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5998 | } else { |
| 5999 | __ mov_w(scratch, Operand(src, 0)); |
| 6000 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6001 | __ add(src, Immediate(2)); |
| 6002 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6003 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6004 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6005 | __ j(not_zero, &loop); |
| 6006 | } |
| 6007 | |
| 6008 | |
| 6009 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6010 | Register dest, |
| 6011 | Register src, |
| 6012 | Register count, |
| 6013 | Register scratch, |
| 6014 | bool ascii) { |
| 6015 | // Copy characters using rep movs of doublewords. |
| 6016 | // The destination is aligned on a 4 byte boundary because we are |
| 6017 | // copying to the beginning of a newly allocated string. |
| 6018 | ASSERT(dest.is(edi)); // rep movs destination |
| 6019 | ASSERT(src.is(esi)); // rep movs source |
| 6020 | ASSERT(count.is(ecx)); // rep movs count |
| 6021 | ASSERT(!scratch.is(dest)); |
| 6022 | ASSERT(!scratch.is(src)); |
| 6023 | ASSERT(!scratch.is(count)); |
| 6024 | |
| 6025 | // Nothing to do for zero characters. |
| 6026 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6027 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6028 | __ j(zero, &done); |
| 6029 | |
| 6030 | // Make count the number of bytes to copy. |
| 6031 | if (!ascii) { |
| 6032 | __ shl(count, 1); |
| 6033 | } |
| 6034 | |
| 6035 | // Don't enter the rep movs if there are less than 4 bytes to copy. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6036 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6037 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6038 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6039 | |
| 6040 | // Copy from edi to esi using rep movs instruction. |
| 6041 | __ mov(scratch, count); |
| 6042 | __ sar(count, 2); // Number of doublewords to copy. |
| 6043 | __ cld(); |
| 6044 | __ rep_movs(); |
| 6045 | |
| 6046 | // Find number of bytes left. |
| 6047 | __ mov(count, scratch); |
| 6048 | __ and_(count, 3); |
| 6049 | |
| 6050 | // Check if there are more bytes to copy. |
| 6051 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6052 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6053 | __ j(zero, &done); |
| 6054 | |
| 6055 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6056 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6057 | __ bind(&loop); |
| 6058 | __ mov_b(scratch, Operand(src, 0)); |
| 6059 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6060 | __ add(src, Immediate(1)); |
| 6061 | __ add(dest, Immediate(1)); |
| 6062 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | __ j(not_zero, &loop); |
| 6064 | |
| 6065 | __ bind(&done); |
| 6066 | } |
| 6067 | |
| 6068 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6069 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6070 | Register c1, |
| 6071 | Register c2, |
| 6072 | Register scratch1, |
| 6073 | Register scratch2, |
| 6074 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6075 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6076 | Label* not_found) { |
| 6077 | // Register scratch3 is the general scratch register in this function. |
| 6078 | Register scratch = scratch3; |
| 6079 | |
| 6080 | // Make sure that both characters are not digits as such strings has a |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6081 | // different hash algorithm. Don't try to look for these in the string table. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6082 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6083 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6084 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6085 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6086 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6087 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6088 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6089 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6090 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6091 | |
| 6092 | __ bind(¬_array_index); |
| 6093 | // Calculate the two character string hash. |
| 6094 | Register hash = scratch1; |
| 6095 | GenerateHashInit(masm, hash, c1, scratch); |
| 6096 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6097 | GenerateHashGetHash(masm, hash, scratch); |
| 6098 | |
| 6099 | // Collect the two characters in a register. |
| 6100 | Register chars = c1; |
| 6101 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6102 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6103 | |
| 6104 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6105 | // hash: hash of two character string. |
| 6106 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6107 | // Load the string table. |
| 6108 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6109 | ExternalReference roots_array_start = |
| 6110 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6111 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 6112 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6113 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6114 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6115 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6116 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6117 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6118 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6119 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6120 | |
| 6121 | // Registers |
| 6122 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6123 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6124 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6125 | // mask: capacity mask |
| 6126 | // scratch: - |
| 6127 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6128 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6129 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6130 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6131 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6132 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6133 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6134 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6135 | __ mov(scratch, hash); |
| 6136 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6137 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6138 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6139 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6140 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6141 | // Load the entry from the string table. |
| 6142 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6143 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6144 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6145 | scratch, |
| 6146 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6147 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6148 | |
| 6149 | // If entry is undefined no string with this hash can be found. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6150 | Factory* factory = masm->isolate()->factory(); |
| 6151 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6152 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6153 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6154 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6155 | |
| 6156 | // If length is not 2 the string is not a candidate. |
| 6157 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6158 | Immediate(Smi::FromInt(2))); |
| 6159 | __ j(not_equal, &next_probe[i]); |
| 6160 | |
| 6161 | // As we are out of registers save the mask on the stack and use that |
| 6162 | // register as a temporary. |
| 6163 | __ push(mask); |
| 6164 | Register temp = mask; |
| 6165 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6166 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6168 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6169 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6170 | temp, temp, &next_probe_pop_mask[i]); |
| 6171 | |
| 6172 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6173 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6174 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6175 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6176 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6177 | __ bind(&next_probe_pop_mask[i]); |
| 6178 | __ pop(mask); |
| 6179 | __ bind(&next_probe[i]); |
| 6180 | } |
| 6181 | |
| 6182 | // No matching 2 character string found by probing. |
| 6183 | __ jmp(not_found); |
| 6184 | |
| 6185 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6186 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6187 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6188 | __ pop(mask); // Pop saved mask from the stack. |
| 6189 | if (!result.is(eax)) { |
| 6190 | __ mov(eax, result); |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | |
| 6195 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6196 | Register hash, |
| 6197 | Register character, |
| 6198 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6199 | // hash = (seed + character) + ((seed + character) << 10); |
| 6200 | if (Serializer::enabled()) { |
| 6201 | ExternalReference roots_array_start = |
| 6202 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6203 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6204 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6205 | times_pointer_size, |
| 6206 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6207 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6208 | __ add(scratch, character); |
| 6209 | __ mov(hash, scratch); |
| 6210 | __ shl(scratch, 10); |
| 6211 | __ add(hash, scratch); |
| 6212 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6213 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6214 | __ lea(scratch, Operand(character, seed)); |
| 6215 | __ shl(scratch, 10); |
| 6216 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6217 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6218 | // hash ^= hash >> 6; |
| 6219 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6220 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6221 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | |
| 6225 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6226 | Register hash, |
| 6227 | Register character, |
| 6228 | Register scratch) { |
| 6229 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6230 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6231 | // hash += hash << 10; |
| 6232 | __ mov(scratch, hash); |
| 6233 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6234 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6235 | // hash ^= hash >> 6; |
| 6236 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6237 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6238 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | |
| 6242 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6243 | Register hash, |
| 6244 | Register scratch) { |
| 6245 | // hash += hash << 3; |
| 6246 | __ mov(scratch, hash); |
| 6247 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6248 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6249 | // hash ^= hash >> 11; |
| 6250 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6251 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6252 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6253 | // hash += hash << 15; |
| 6254 | __ mov(scratch, hash); |
| 6255 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6256 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6257 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6258 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6259 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6260 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6261 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6262 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6263 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6264 | __ bind(&hash_not_zero); |
| 6265 | } |
| 6266 | |
| 6267 | |
| 6268 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6269 | Label runtime; |
| 6270 | |
| 6271 | // Stack frame on entry. |
| 6272 | // esp[0]: return address |
| 6273 | // esp[4]: to |
| 6274 | // esp[8]: from |
| 6275 | // esp[12]: string |
| 6276 | |
| 6277 | // Make sure first argument is a string. |
| 6278 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6279 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6280 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6281 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6282 | __ j(NegateCondition(is_string), &runtime); |
| 6283 | |
| 6284 | // eax: string |
| 6285 | // ebx: instance type |
| 6286 | |
| 6287 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6288 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6289 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6290 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6291 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6292 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6293 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6294 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6295 | // Shorter than original string's length: an actual substring. |
| 6296 | __ j(below, ¬_original_string, Label::kNear); |
| 6297 | // Longer than original string's length or negative: unsafe arguments. |
| 6298 | __ j(above, &runtime); |
| 6299 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6300 | Counters* counters = masm->isolate()->counters(); |
| 6301 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6302 | __ ret(3 * kPointerSize); |
| 6303 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6304 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6305 | Label single_char; |
| 6306 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6307 | __ j(equal, &single_char); |
| 6308 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6309 | // eax: string |
| 6310 | // ebx: instance type |
| 6311 | // ecx: sub string length (smi) |
| 6312 | // edx: from index (smi) |
| 6313 | // Deal with different string types: update the index if necessary |
| 6314 | // and put the underlying string into edi. |
| 6315 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6316 | // If the string is not indirect, it can only be sequential or external. |
| 6317 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6318 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6319 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6320 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6321 | |
| 6322 | Factory* factory = masm->isolate()->factory(); |
| 6323 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6324 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6325 | // Cons string. Check whether it is flat, then fetch first part. |
| 6326 | // Flat cons strings have an empty second part. |
| 6327 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6328 | factory->empty_string()); |
| 6329 | __ j(not_equal, &runtime); |
| 6330 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6331 | // Update instance type. |
| 6332 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6333 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6334 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6335 | |
| 6336 | __ bind(&sliced_string); |
| 6337 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6338 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6339 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6340 | // Update instance type. |
| 6341 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6342 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6343 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6344 | |
| 6345 | __ bind(&seq_or_external_string); |
| 6346 | // Sequential or external string. Just move string to the expected register. |
| 6347 | __ mov(edi, eax); |
| 6348 | |
| 6349 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6350 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6351 | if (FLAG_string_slices) { |
| 6352 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6353 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6354 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6355 | // edx: adjusted start index (smi) |
| 6356 | // ecx: length (smi) |
| 6357 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6358 | // Short slice. Copy instead of slicing. |
| 6359 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6360 | // Allocate new sliced string. At this point we do not reload the instance |
| 6361 | // type including the string encoding because we simply rely on the info |
| 6362 | // provided by the original string. It does not matter if the original |
| 6363 | // string's encoding is wrong because we always have to recheck encoding of |
| 6364 | // the newly created string's parent anyways due to externalized strings. |
| 6365 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6366 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6367 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6368 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6369 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6370 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6371 | __ jmp(&set_slice_header, Label::kNear); |
| 6372 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6373 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6374 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6375 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6376 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6377 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6378 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6379 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6380 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6381 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6382 | |
| 6383 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6386 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6387 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6388 | // edx: adjusted start index (smi) |
| 6389 | // ecx: length (smi) |
| 6390 | // The subject string can only be external or sequential string of either |
| 6391 | // encoding at this point. |
| 6392 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6393 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6394 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6395 | __ test_b(ebx, kExternalStringTag); |
| 6396 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6397 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6398 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6399 | // Rule out short external strings. |
| 6400 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6401 | __ test_b(ebx, kShortExternalStringMask); |
| 6402 | __ j(not_zero, &runtime); |
| 6403 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6404 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6405 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6406 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6407 | |
| 6408 | __ bind(&sequential_string); |
| 6409 | // Stash away (adjusted) index and (underlying) string. |
| 6410 | __ push(edx); |
| 6411 | __ push(edi); |
| 6412 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6413 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6414 | __ test_b(ebx, kStringEncodingMask); |
| 6415 | __ j(zero, &two_byte_sequential); |
| 6416 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6417 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6418 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6419 | |
| 6420 | // eax: result string |
| 6421 | // ecx: result string length |
| 6422 | __ mov(edx, esi); // esi used by following code. |
| 6423 | // Locate first character of result. |
| 6424 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6425 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6426 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6427 | __ pop(esi); |
| 6428 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6429 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6430 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6431 | |
| 6432 | // eax: result string |
| 6433 | // ecx: result length |
| 6434 | // edx: original value of esi |
| 6435 | // edi: first character of result |
| 6436 | // esi: character of sub string start |
| 6437 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6438 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6439 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6440 | __ ret(3 * kPointerSize); |
| 6441 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6442 | __ bind(&two_byte_sequential); |
| 6443 | // Sequential two-byte string. Allocate the result. |
| 6444 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6445 | |
| 6446 | // eax: result string |
| 6447 | // ecx: result string length |
| 6448 | __ mov(edx, esi); // esi used by following code. |
| 6449 | // Locate first character of result. |
| 6450 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6451 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6452 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6453 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6454 | __ pop(esi); |
| 6455 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6456 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6457 | // byte character. |
| 6458 | STATIC_ASSERT(kSmiTag == 0); |
| 6459 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6460 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6461 | |
| 6462 | // eax: result string |
| 6463 | // ecx: result length |
| 6464 | // edx: original value of esi |
| 6465 | // edi: first character of result |
| 6466 | // esi: character of sub string start |
| 6467 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6468 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6469 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6470 | __ ret(3 * kPointerSize); |
| 6471 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6472 | // Drop pushed values on the stack before tail call. |
| 6473 | __ bind(&runtime_drop_two); |
| 6474 | __ Drop(2); |
| 6475 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6476 | // Just jump to runtime to create the sub string. |
| 6477 | __ bind(&runtime); |
| 6478 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6479 | |
| 6480 | __ bind(&single_char); |
| 6481 | // eax: string |
| 6482 | // ebx: instance type |
| 6483 | // ecx: sub string length (smi) |
| 6484 | // edx: from index (smi) |
| 6485 | StringCharAtGenerator generator( |
| 6486 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6487 | generator.GenerateFast(masm); |
| 6488 | __ ret(3 * kPointerSize); |
| 6489 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6493 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6494 | Register left, |
| 6495 | Register right, |
| 6496 | Register scratch1, |
| 6497 | Register scratch2) { |
| 6498 | Register length = scratch1; |
| 6499 | |
| 6500 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6501 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6502 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6503 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6504 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6505 | __ bind(&strings_not_equal); |
| 6506 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6507 | __ ret(0); |
| 6508 | |
| 6509 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6510 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6511 | __ bind(&check_zero_length); |
| 6512 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6513 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6514 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6515 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6516 | __ ret(0); |
| 6517 | |
| 6518 | // Compare characters. |
| 6519 | __ bind(&compare_chars); |
| 6520 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6521 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Characters are equal. |
| 6524 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6525 | __ ret(0); |
| 6526 | } |
| 6527 | |
| 6528 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6529 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6530 | Register left, |
| 6531 | Register right, |
| 6532 | Register scratch1, |
| 6533 | Register scratch2, |
| 6534 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6535 | Counters* counters = masm->isolate()->counters(); |
| 6536 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6537 | |
| 6538 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6539 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6540 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6541 | __ mov(scratch3, scratch1); |
| 6542 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6543 | |
| 6544 | Register length_delta = scratch3; |
| 6545 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6546 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6547 | // Right string is shorter. Change scratch1 to be length of right string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6548 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6549 | __ bind(&left_shorter); |
| 6550 | |
| 6551 | Register min_length = scratch1; |
| 6552 | |
| 6553 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6554 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6555 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6556 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6557 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6558 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6559 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6560 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6561 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6562 | |
| 6563 | // Compare lengths - strings up to min-length are equal. |
| 6564 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6565 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6566 | Label length_not_equal; |
| 6567 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6568 | |
| 6569 | // Result is EQUAL. |
| 6570 | STATIC_ASSERT(EQUAL == 0); |
| 6571 | STATIC_ASSERT(kSmiTag == 0); |
| 6572 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6573 | __ ret(0); |
| 6574 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6575 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6576 | Label result_less; |
| 6577 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6578 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6579 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6580 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6581 | __ j(above, &result_greater, Label::kNear); |
| 6582 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6583 | |
| 6584 | // Result is LESS. |
| 6585 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6586 | __ ret(0); |
| 6587 | |
| 6588 | // Result is GREATER. |
| 6589 | __ bind(&result_greater); |
| 6590 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6591 | __ ret(0); |
| 6592 | } |
| 6593 | |
| 6594 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6595 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6596 | MacroAssembler* masm, |
| 6597 | Register left, |
| 6598 | Register right, |
| 6599 | Register length, |
| 6600 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6601 | Label* chars_not_equal, |
| 6602 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6603 | // Change index to run from -length to -1 by adding length to string |
| 6604 | // start. This means that loop ends when index reaches zero, which |
| 6605 | // doesn't need an additional compare. |
| 6606 | __ SmiUntag(length); |
| 6607 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6608 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6609 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6610 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6611 | __ neg(length); |
| 6612 | Register index = length; // index = -length; |
| 6613 | |
| 6614 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6615 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6616 | __ bind(&loop); |
| 6617 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6618 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6619 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6620 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6621 | __ j(not_zero, &loop); |
| 6622 | } |
| 6623 | |
| 6624 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6625 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6626 | Label runtime; |
| 6627 | |
| 6628 | // Stack frame on entry. |
| 6629 | // esp[0]: return address |
| 6630 | // esp[4]: right string |
| 6631 | // esp[8]: left string |
| 6632 | |
| 6633 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6634 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6635 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6636 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6637 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6638 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6639 | STATIC_ASSERT(EQUAL == 0); |
| 6640 | STATIC_ASSERT(kSmiTag == 0); |
| 6641 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6642 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6643 | __ ret(2 * kPointerSize); |
| 6644 | |
| 6645 | __ bind(¬_same); |
| 6646 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6647 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6648 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6649 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6650 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6651 | // Drop arguments from the stack. |
| 6652 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6653 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6654 | __ push(ecx); |
| 6655 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6656 | |
| 6657 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6658 | // tagged as a small integer. |
| 6659 | __ bind(&runtime); |
| 6660 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6661 | } |
| 6662 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6663 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6664 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6665 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6666 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6667 | __ mov(ecx, edx); |
| 6668 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6669 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6670 | |
| 6671 | if (GetCondition() == equal) { |
| 6672 | // For equality we do not care about the sign of the result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6673 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6674 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6675 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6676 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6677 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6678 | // Correct sign of result in case of overflow. |
| 6679 | __ not_(edx); |
| 6680 | __ bind(&done); |
| 6681 | __ mov(eax, edx); |
| 6682 | } |
| 6683 | __ ret(0); |
| 6684 | |
| 6685 | __ bind(&miss); |
| 6686 | GenerateMiss(masm); |
| 6687 | } |
| 6688 | |
| 6689 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6690 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6691 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6692 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6693 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6694 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6695 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6696 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6697 | if (left_ == CompareIC::SMI) { |
| 6698 | __ JumpIfNotSmi(edx, &miss); |
| 6699 | } |
| 6700 | if (right_ == CompareIC::SMI) { |
| 6701 | __ JumpIfNotSmi(eax, &miss); |
| 6702 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6703 | |
| 6704 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6705 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6706 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6707 | CpuFeatureScope scope1(masm, SSE2); |
| 6708 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6709 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6710 | // Load left and right operand. |
| 6711 | Label done, left, left_smi, right_smi; |
| 6712 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6713 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6714 | masm->isolate()->factory()->heap_number_map()); |
| 6715 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6716 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6717 | __ jmp(&left, Label::kNear); |
| 6718 | __ bind(&right_smi); |
| 6719 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6720 | __ SmiUntag(ecx); |
| 6721 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6722 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6723 | __ bind(&left); |
| 6724 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6725 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6726 | masm->isolate()->factory()->heap_number_map()); |
| 6727 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6728 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6729 | __ jmp(&done); |
| 6730 | __ bind(&left_smi); |
| 6731 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6732 | __ SmiUntag(ecx); |
| 6733 | __ cvtsi2sd(xmm0, ecx); |
| 6734 | |
| 6735 | __ bind(&done); |
| 6736 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6737 | __ ucomisd(xmm0, xmm1); |
| 6738 | |
| 6739 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6740 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6741 | |
| 6742 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6743 | // Performing mov, because xor would destroy the flag register. |
| 6744 | __ mov(eax, 0); // equal |
| 6745 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6746 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6747 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6748 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6749 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6750 | } else { |
| 6751 | __ mov(ecx, edx); |
| 6752 | __ and_(ecx, eax); |
| 6753 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6754 | |
| 6755 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6756 | masm->isolate()->factory()->heap_number_map()); |
| 6757 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6758 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6759 | masm->isolate()->factory()->heap_number_map()); |
| 6760 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6763 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6764 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6765 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6766 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6767 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6768 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6769 | __ bind(&maybe_undefined1); |
| 6770 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6771 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6772 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6773 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6774 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6775 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6776 | __ jmp(&unordered); |
| 6777 | } |
| 6778 | |
| 6779 | __ bind(&maybe_undefined2); |
| 6780 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6781 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6782 | __ j(equal, &unordered); |
| 6783 | } |
| 6784 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6785 | __ bind(&miss); |
| 6786 | GenerateMiss(masm); |
| 6787 | } |
| 6788 | |
| 6789 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6790 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6791 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6792 | ASSERT(GetCondition() == equal); |
| 6793 | |
| 6794 | // Registers containing left and right operands respectively. |
| 6795 | Register left = edx; |
| 6796 | Register right = eax; |
| 6797 | Register tmp1 = ecx; |
| 6798 | Register tmp2 = ebx; |
| 6799 | |
| 6800 | // Check that both operands are heap objects. |
| 6801 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6802 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6803 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6804 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6805 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6806 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6807 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6808 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6809 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6810 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6811 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6812 | STATIC_ASSERT(kInternalizedTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6813 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6814 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6815 | __ j(zero, &miss, Label::kNear); |
| 6816 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6817 | // Internalized strings are compared by identity. |
| 6818 | Label done; |
| 6819 | __ cmp(left, right); |
| 6820 | // Make sure eax is non-zero. At this point input operands are |
| 6821 | // guaranteed to be non-zero. |
| 6822 | ASSERT(right.is(eax)); |
| 6823 | __ j(not_equal, &done, Label::kNear); |
| 6824 | STATIC_ASSERT(EQUAL == 0); |
| 6825 | STATIC_ASSERT(kSmiTag == 0); |
| 6826 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6827 | __ bind(&done); |
| 6828 | __ ret(0); |
| 6829 | |
| 6830 | __ bind(&miss); |
| 6831 | GenerateMiss(masm); |
| 6832 | } |
| 6833 | |
| 6834 | |
| 6835 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6836 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6837 | ASSERT(GetCondition() == equal); |
| 6838 | |
| 6839 | // Registers containing left and right operands respectively. |
| 6840 | Register left = edx; |
| 6841 | Register right = eax; |
| 6842 | Register tmp1 = ecx; |
| 6843 | Register tmp2 = ebx; |
| 6844 | |
| 6845 | // Check that both operands are heap objects. |
| 6846 | Label miss; |
| 6847 | __ mov(tmp1, left); |
| 6848 | STATIC_ASSERT(kSmiTag == 0); |
| 6849 | __ and_(tmp1, right); |
| 6850 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6851 | |
| 6852 | // Check that both operands are unique names. This leaves the instance |
| 6853 | // types loaded in tmp1 and tmp2. |
| 6854 | STATIC_ASSERT(kInternalizedTag != 0); |
| 6855 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6856 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6857 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6858 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6859 | |
| 6860 | Label succeed1; |
| 6861 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
| 6862 | __ j(not_zero, &succeed1); |
| 6863 | __ cmpb(tmp1, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6864 | __ j(not_equal, &miss); |
| 6865 | __ bind(&succeed1); |
| 6866 | |
| 6867 | Label succeed2; |
| 6868 | __ test(tmp2, Immediate(kIsInternalizedMask)); |
| 6869 | __ j(not_zero, &succeed2); |
| 6870 | __ cmpb(tmp2, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6871 | __ j(not_equal, &miss); |
| 6872 | __ bind(&succeed2); |
| 6873 | |
| 6874 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6875 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6876 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6877 | // Make sure eax is non-zero. At this point input operands are |
| 6878 | // guaranteed to be non-zero. |
| 6879 | ASSERT(right.is(eax)); |
| 6880 | __ j(not_equal, &done, Label::kNear); |
| 6881 | STATIC_ASSERT(EQUAL == 0); |
| 6882 | STATIC_ASSERT(kSmiTag == 0); |
| 6883 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6884 | __ bind(&done); |
| 6885 | __ ret(0); |
| 6886 | |
| 6887 | __ bind(&miss); |
| 6888 | GenerateMiss(masm); |
| 6889 | } |
| 6890 | |
| 6891 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6892 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6893 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6894 | Label miss; |
| 6895 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6896 | bool equality = Token::IsEqualityOp(op_); |
| 6897 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6898 | // Registers containing left and right operands respectively. |
| 6899 | Register left = edx; |
| 6900 | Register right = eax; |
| 6901 | Register tmp1 = ecx; |
| 6902 | Register tmp2 = ebx; |
| 6903 | Register tmp3 = edi; |
| 6904 | |
| 6905 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6906 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6907 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6908 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6909 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6910 | |
| 6911 | // Check that both operands are strings. This leaves the instance |
| 6912 | // types loaded in tmp1 and tmp2. |
| 6913 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6914 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6915 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6916 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6917 | __ mov(tmp3, tmp1); |
| 6918 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6919 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6920 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6921 | __ j(not_zero, &miss); |
| 6922 | |
| 6923 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6924 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6925 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6926 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6927 | STATIC_ASSERT(EQUAL == 0); |
| 6928 | STATIC_ASSERT(kSmiTag == 0); |
| 6929 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6930 | __ ret(0); |
| 6931 | |
| 6932 | // Handle not identical strings. |
| 6933 | __ bind(¬_same); |
| 6934 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6935 | // Check that both strings are internalized. If they are, we're done |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6936 | // because we already know they are not identical. But in the case of |
| 6937 | // non-equality compare, we still need to determine the order. |
| 6938 | if (equality) { |
| 6939 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6940 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6941 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6942 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6943 | __ j(zero, &do_compare, Label::kNear); |
| 6944 | // Make sure eax is non-zero. At this point input operands are |
| 6945 | // guaranteed to be non-zero. |
| 6946 | ASSERT(right.is(eax)); |
| 6947 | __ ret(0); |
| 6948 | __ bind(&do_compare); |
| 6949 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6950 | |
| 6951 | // Check that both strings are sequential ASCII. |
| 6952 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6953 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6954 | |
| 6955 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6956 | if (equality) { |
| 6957 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6958 | masm, left, right, tmp1, tmp2); |
| 6959 | } else { |
| 6960 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6961 | masm, left, right, tmp1, tmp2, tmp3); |
| 6962 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6963 | |
| 6964 | // Handle more complex cases in runtime. |
| 6965 | __ bind(&runtime); |
| 6966 | __ pop(tmp1); // Return address. |
| 6967 | __ push(left); |
| 6968 | __ push(right); |
| 6969 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6970 | if (equality) { |
| 6971 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6972 | } else { |
| 6973 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6974 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6975 | |
| 6976 | __ bind(&miss); |
| 6977 | GenerateMiss(masm); |
| 6978 | } |
| 6979 | |
| 6980 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6981 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6982 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6983 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6984 | __ mov(ecx, edx); |
| 6985 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6986 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6987 | |
| 6988 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6989 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6990 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6991 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6992 | |
| 6993 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6994 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6995 | __ ret(0); |
| 6996 | |
| 6997 | __ bind(&miss); |
| 6998 | GenerateMiss(masm); |
| 6999 | } |
| 7000 | |
| 7001 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7002 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7003 | Label miss; |
| 7004 | __ mov(ecx, edx); |
| 7005 | __ and_(ecx, eax); |
| 7006 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7007 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7008 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7009 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7010 | __ cmp(ecx, known_map_); |
| 7011 | __ j(not_equal, &miss, Label::kNear); |
| 7012 | __ cmp(ebx, known_map_); |
| 7013 | __ j(not_equal, &miss, Label::kNear); |
| 7014 | |
| 7015 | __ sub(eax, edx); |
| 7016 | __ ret(0); |
| 7017 | |
| 7018 | __ bind(&miss); |
| 7019 | GenerateMiss(masm); |
| 7020 | } |
| 7021 | |
| 7022 | |
| 7023 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7024 | { |
| 7025 | // Call the runtime system in a fresh internal frame. |
| 7026 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7027 | masm->isolate()); |
| 7028 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7029 | __ push(edx); // Preserve edx and eax. |
| 7030 | __ push(eax); |
| 7031 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7032 | __ push(eax); |
| 7033 | __ push(Immediate(Smi::FromInt(op_))); |
| 7034 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7035 | // Compute the entry point of the rewritten stub. |
| 7036 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7037 | __ pop(eax); |
| 7038 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7039 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7040 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7041 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7042 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7043 | } |
| 7044 | |
| 7045 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7046 | // Helper function used to check that the dictionary doesn't contain |
| 7047 | // the property. This function may return false negatives, so miss_label |
| 7048 | // must always call a backup property check that is complete. |
| 7049 | // This function is safe to call if the receiver has fast properties. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7050 | // Name must be a unique name and receiver must be a heap object. |
| 7051 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7052 | Label* miss, |
| 7053 | Label* done, |
| 7054 | Register properties, |
| 7055 | Handle<Name> name, |
| 7056 | Register r0) { |
| 7057 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7058 | |
| 7059 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7060 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7061 | // undefined value), it guarantees the hash table doesn't contain the |
| 7062 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7063 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7064 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7065 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7066 | Register index = r0; |
| 7067 | // Capacity is smi 2^n. |
| 7068 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7069 | __ dec(index); |
| 7070 | __ and_(index, |
| 7071 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7072 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7073 | |
| 7074 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7075 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7076 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7077 | Register entity_name = r0; |
| 7078 | // Having undefined at this place means the name is not contained. |
| 7079 | ASSERT_EQ(kSmiTagSize, 1); |
| 7080 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7081 | kElementsStartOffset - kHeapObjectTag)); |
| 7082 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7083 | __ j(equal, done); |
| 7084 | |
| 7085 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7086 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7087 | __ j(equal, miss); |
| 7088 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7089 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7090 | // Check for the hole and skip. |
| 7091 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7092 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7093 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7094 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7095 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7096 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7097 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7098 | __ j(not_zero, &good); |
| 7099 | __ cmpb(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7100 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7101 | __ j(not_equal, miss); |
| 7102 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7103 | } |
| 7104 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7105 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7106 | __ push(Immediate(Handle<Object>(name))); |
| 7107 | __ push(Immediate(name->Hash())); |
| 7108 | __ CallStub(&stub); |
| 7109 | __ test(r0, r0); |
| 7110 | __ j(not_zero, miss); |
| 7111 | __ jmp(done); |
| 7112 | } |
| 7113 | |
| 7114 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7115 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7116 | // |done| label if a property with the given name is found leaving the |
| 7117 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7118 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7119 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7120 | Label* miss, |
| 7121 | Label* done, |
| 7122 | Register elements, |
| 7123 | Register name, |
| 7124 | Register r0, |
| 7125 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7126 | ASSERT(!elements.is(r0)); |
| 7127 | ASSERT(!elements.is(r1)); |
| 7128 | ASSERT(!name.is(r0)); |
| 7129 | ASSERT(!name.is(r1)); |
| 7130 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7131 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7132 | |
| 7133 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7134 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7135 | __ dec(r1); |
| 7136 | |
| 7137 | // Generate an unrolled loop that performs a few probes before |
| 7138 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7139 | // cover ~93% of loads from dictionaries. |
| 7140 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7141 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7142 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7143 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7144 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7145 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7146 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7147 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7148 | |
| 7149 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7150 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7151 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7152 | |
| 7153 | // Check if the key is identical to the name. |
| 7154 | __ cmp(name, Operand(elements, |
| 7155 | r0, |
| 7156 | times_4, |
| 7157 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7158 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7159 | } |
| 7160 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7161 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7162 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7163 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7164 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7165 | __ push(r0); |
| 7166 | __ CallStub(&stub); |
| 7167 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7168 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7169 | __ j(zero, miss); |
| 7170 | __ jmp(done); |
| 7171 | } |
| 7172 | |
| 7173 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7174 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7175 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7176 | // we cannot call anything that could cause a GC from this stub. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7177 | // Stack frame on entry: |
| 7178 | // esp[0 * kPointerSize]: return address. |
| 7179 | // esp[1 * kPointerSize]: key's hash. |
| 7180 | // esp[2 * kPointerSize]: key. |
| 7181 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7182 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7183 | // result_: used as scratch. |
| 7184 | // index_: will hold an index of entry if lookup is successful. |
| 7185 | // might alias with result_. |
| 7186 | // Returns: |
| 7187 | // result_ is zero if lookup failed, non zero otherwise. |
| 7188 | |
| 7189 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7190 | |
| 7191 | Register scratch = result_; |
| 7192 | |
| 7193 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7194 | __ dec(scratch); |
| 7195 | __ SmiUntag(scratch); |
| 7196 | __ push(scratch); |
| 7197 | |
| 7198 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7199 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7200 | // undefined value), it guarantees the hash table doesn't contain the |
| 7201 | // property. It's true even if some slots represent deleted properties |
| 7202 | // (their names are the null value). |
| 7203 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7204 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7205 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7206 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7207 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7208 | } |
| 7209 | __ and_(scratch, Operand(esp, 0)); |
| 7210 | |
| 7211 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7212 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7213 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7214 | |
| 7215 | // Having undefined at this place means the name is not contained. |
| 7216 | ASSERT_EQ(kSmiTagSize, 1); |
| 7217 | __ mov(scratch, Operand(dictionary_, |
| 7218 | index_, |
| 7219 | times_pointer_size, |
| 7220 | kElementsStartOffset - kHeapObjectTag)); |
| 7221 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7222 | __ j(equal, ¬_in_dictionary); |
| 7223 | |
| 7224 | // Stop if found the property. |
| 7225 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7226 | __ j(equal, &in_dictionary); |
| 7227 | |
| 7228 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7229 | // If we hit a key that is not a unique name during negative |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7230 | // lookup we have to bailout as this key might be equal to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7231 | // key we are looking for. |
| 7232 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7233 | // Check if the entry name is not a unique name. |
| 7234 | Label cont; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7235 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7236 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7237 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7238 | __ j(not_zero, &cont); |
| 7239 | __ cmpb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7240 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7241 | __ j(not_equal, &maybe_in_dictionary); |
| 7242 | __ bind(&cont); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | __ bind(&maybe_in_dictionary); |
| 7247 | // If we are doing negative lookup then probing failure should be |
| 7248 | // treated as a lookup success. For positive lookup probing failure |
| 7249 | // should be treated as lookup failure. |
| 7250 | if (mode_ == POSITIVE_LOOKUP) { |
| 7251 | __ mov(result_, Immediate(0)); |
| 7252 | __ Drop(1); |
| 7253 | __ ret(2 * kPointerSize); |
| 7254 | } |
| 7255 | |
| 7256 | __ bind(&in_dictionary); |
| 7257 | __ mov(result_, Immediate(1)); |
| 7258 | __ Drop(1); |
| 7259 | __ ret(2 * kPointerSize); |
| 7260 | |
| 7261 | __ bind(¬_in_dictionary); |
| 7262 | __ mov(result_, Immediate(0)); |
| 7263 | __ Drop(1); |
| 7264 | __ ret(2 * kPointerSize); |
| 7265 | } |
| 7266 | |
| 7267 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7268 | struct AheadOfTimeWriteBarrierStubList { |
| 7269 | Register object, value, address; |
| 7270 | RememberedSetAction action; |
| 7271 | }; |
| 7272 | |
| 7273 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7274 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7275 | |
| 7276 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7277 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7278 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7279 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7280 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7281 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7282 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7283 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7284 | // Used in StoreStubCompiler::CompileStoreField and |
| 7285 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7286 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7287 | // GenerateStoreField calls the stub with two different permutations of |
| 7288 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7289 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7290 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7291 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7292 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7293 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7294 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7295 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7296 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7297 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7298 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7299 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7300 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7301 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7302 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7303 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7304 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7305 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7306 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7307 | // FastNewClosureStub |
| 7308 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7309 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7310 | { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7311 | }; |
| 7312 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7313 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7314 | |
| 7315 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7316 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7317 | !entry->object.is(no_reg); |
| 7318 | entry++) { |
| 7319 | if (object_.is(entry->object) && |
| 7320 | value_.is(entry->value) && |
| 7321 | address_.is(entry->address) && |
| 7322 | remembered_set_action_ == entry->action && |
| 7323 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7324 | return true; |
| 7325 | } |
| 7326 | } |
| 7327 | return false; |
| 7328 | } |
| 7329 | |
| 7330 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7331 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7332 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7333 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7334 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7335 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7336 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7337 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7342 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7343 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7344 | !entry->object.is(no_reg); |
| 7345 | entry++) { |
| 7346 | RecordWriteStub stub(entry->object, |
| 7347 | entry->value, |
| 7348 | entry->address, |
| 7349 | entry->action, |
| 7350 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7351 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7352 | } |
| 7353 | } |
| 7354 | |
| 7355 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7356 | bool CodeStub::CanUseFPRegisters() { |
| 7357 | return CpuFeatures::IsSupported(SSE2); |
| 7358 | } |
| 7359 | |
| 7360 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7361 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7362 | // the value has just been written into the object, now this stub makes sure |
| 7363 | // we keep the GC informed. The word in the object where the value has been |
| 7364 | // written is in the address register. |
| 7365 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7366 | Label skip_to_incremental_noncompacting; |
| 7367 | Label skip_to_incremental_compacting; |
| 7368 | |
| 7369 | // The first two instructions are generated with labels so as to get the |
| 7370 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7371 | // forth between a compare instructions (a nop in this position) and the |
| 7372 | // real branch when we start and stop incremental heap marking. |
| 7373 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7374 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7375 | |
| 7376 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7377 | __ RememberedSetHelper(object_, |
| 7378 | address_, |
| 7379 | value_, |
| 7380 | save_fp_regs_mode_, |
| 7381 | MacroAssembler::kReturnAtEnd); |
| 7382 | } else { |
| 7383 | __ ret(0); |
| 7384 | } |
| 7385 | |
| 7386 | __ bind(&skip_to_incremental_noncompacting); |
| 7387 | GenerateIncremental(masm, INCREMENTAL); |
| 7388 | |
| 7389 | __ bind(&skip_to_incremental_compacting); |
| 7390 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7391 | |
| 7392 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7393 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7394 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7395 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7396 | } |
| 7397 | |
| 7398 | |
| 7399 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7400 | regs_.Save(masm); |
| 7401 | |
| 7402 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7403 | Label dont_need_remembered_set; |
| 7404 | |
| 7405 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7406 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7407 | regs_.scratch0(), |
| 7408 | &dont_need_remembered_set); |
| 7409 | |
| 7410 | __ CheckPageFlag(regs_.object(), |
| 7411 | regs_.scratch0(), |
| 7412 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7413 | not_zero, |
| 7414 | &dont_need_remembered_set); |
| 7415 | |
| 7416 | // First notify the incremental marker if necessary, then update the |
| 7417 | // remembered set. |
| 7418 | CheckNeedsToInformIncrementalMarker( |
| 7419 | masm, |
| 7420 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7421 | mode); |
| 7422 | InformIncrementalMarker(masm, mode); |
| 7423 | regs_.Restore(masm); |
| 7424 | __ RememberedSetHelper(object_, |
| 7425 | address_, |
| 7426 | value_, |
| 7427 | save_fp_regs_mode_, |
| 7428 | MacroAssembler::kReturnAtEnd); |
| 7429 | |
| 7430 | __ bind(&dont_need_remembered_set); |
| 7431 | } |
| 7432 | |
| 7433 | CheckNeedsToInformIncrementalMarker( |
| 7434 | masm, |
| 7435 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7436 | mode); |
| 7437 | InformIncrementalMarker(masm, mode); |
| 7438 | regs_.Restore(masm); |
| 7439 | __ ret(0); |
| 7440 | } |
| 7441 | |
| 7442 | |
| 7443 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7444 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7445 | int argument_count = 3; |
| 7446 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7447 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7448 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7449 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7450 | Immediate(ExternalReference::isolate_address())); |
| 7451 | |
| 7452 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7453 | if (mode == INCREMENTAL_COMPACTION) { |
| 7454 | __ CallCFunction( |
| 7455 | ExternalReference::incremental_evacuation_record_write_function( |
| 7456 | masm->isolate()), |
| 7457 | argument_count); |
| 7458 | } else { |
| 7459 | ASSERT(mode == INCREMENTAL); |
| 7460 | __ CallCFunction( |
| 7461 | ExternalReference::incremental_marking_record_write_function( |
| 7462 | masm->isolate()), |
| 7463 | argument_count); |
| 7464 | } |
| 7465 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7466 | } |
| 7467 | |
| 7468 | |
| 7469 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7470 | MacroAssembler* masm, |
| 7471 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7472 | Mode mode) { |
| 7473 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7474 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7475 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7476 | __ and_(regs_.scratch0(), regs_.object()); |
| 7477 | __ mov(regs_.scratch1(), |
| 7478 | Operand(regs_.scratch0(), |
| 7479 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7480 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7481 | __ mov(Operand(regs_.scratch0(), |
| 7482 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7483 | regs_.scratch1()); |
| 7484 | __ j(negative, &need_incremental); |
| 7485 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7486 | // Let's look at the color of the object: If it is not black we don't have |
| 7487 | // to inform the incremental marker. |
| 7488 | __ JumpIfBlack(regs_.object(), |
| 7489 | regs_.scratch0(), |
| 7490 | regs_.scratch1(), |
| 7491 | &object_is_black, |
| 7492 | Label::kNear); |
| 7493 | |
| 7494 | regs_.Restore(masm); |
| 7495 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7496 | __ RememberedSetHelper(object_, |
| 7497 | address_, |
| 7498 | value_, |
| 7499 | save_fp_regs_mode_, |
| 7500 | MacroAssembler::kReturnAtEnd); |
| 7501 | } else { |
| 7502 | __ ret(0); |
| 7503 | } |
| 7504 | |
| 7505 | __ bind(&object_is_black); |
| 7506 | |
| 7507 | // Get the value from the slot. |
| 7508 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7509 | |
| 7510 | if (mode == INCREMENTAL_COMPACTION) { |
| 7511 | Label ensure_not_white; |
| 7512 | |
| 7513 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7514 | regs_.scratch1(), // Scratch. |
| 7515 | MemoryChunk::kEvacuationCandidateMask, |
| 7516 | zero, |
| 7517 | &ensure_not_white, |
| 7518 | Label::kNear); |
| 7519 | |
| 7520 | __ CheckPageFlag(regs_.object(), |
| 7521 | regs_.scratch1(), // Scratch. |
| 7522 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7523 | not_zero, |
| 7524 | &ensure_not_white, |
| 7525 | Label::kNear); |
| 7526 | |
| 7527 | __ jmp(&need_incremental); |
| 7528 | |
| 7529 | __ bind(&ensure_not_white); |
| 7530 | } |
| 7531 | |
| 7532 | // We need an extra register for this, so we push the object register |
| 7533 | // temporarily. |
| 7534 | __ push(regs_.object()); |
| 7535 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7536 | regs_.scratch1(), // Scratch. |
| 7537 | regs_.object(), // Scratch. |
| 7538 | &need_incremental_pop_object, |
| 7539 | Label::kNear); |
| 7540 | __ pop(regs_.object()); |
| 7541 | |
| 7542 | regs_.Restore(masm); |
| 7543 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7544 | __ RememberedSetHelper(object_, |
| 7545 | address_, |
| 7546 | value_, |
| 7547 | save_fp_regs_mode_, |
| 7548 | MacroAssembler::kReturnAtEnd); |
| 7549 | } else { |
| 7550 | __ ret(0); |
| 7551 | } |
| 7552 | |
| 7553 | __ bind(&need_incremental_pop_object); |
| 7554 | __ pop(regs_.object()); |
| 7555 | |
| 7556 | __ bind(&need_incremental); |
| 7557 | |
| 7558 | // Fall through when we need to inform the incremental marker. |
| 7559 | } |
| 7560 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7561 | |
| 7562 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7563 | // ----------- S t a t e ------------- |
| 7564 | // -- eax : element value to store |
| 7565 | // -- ebx : array literal |
| 7566 | // -- edi : map of array literal |
| 7567 | // -- ecx : element index as smi |
| 7568 | // -- edx : array literal index in function |
| 7569 | // -- esp[0] : return address |
| 7570 | // ----------------------------------- |
| 7571 | |
| 7572 | Label element_done; |
| 7573 | Label double_elements; |
| 7574 | Label smi_element; |
| 7575 | Label slow_elements; |
| 7576 | Label slow_elements_from_double; |
| 7577 | Label fast_elements; |
| 7578 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7579 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7580 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7581 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7582 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7583 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7584 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7585 | // Store into the array literal requires a elements transition. Call into |
| 7586 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7587 | |
| 7588 | __ bind(&slow_elements); |
| 7589 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7590 | // call. |
| 7591 | __ push(ebx); |
| 7592 | __ push(ecx); |
| 7593 | __ push(eax); |
| 7594 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7595 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7596 | __ push(edx); |
| 7597 | __ push(edi); // Return return address so that tail call returns to right |
| 7598 | // place. |
| 7599 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7600 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7601 | __ bind(&slow_elements_from_double); |
| 7602 | __ pop(edx); |
| 7603 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7604 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7605 | // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7606 | __ bind(&fast_elements); |
| 7607 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7608 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7609 | FixedArrayBase::kHeaderSize)); |
| 7610 | __ mov(Operand(ecx, 0), eax); |
| 7611 | // Update the write barrier for the array store. |
| 7612 | __ RecordWrite(ebx, ecx, eax, |
| 7613 | kDontSaveFPRegs, |
| 7614 | EMIT_REMEMBERED_SET, |
| 7615 | OMIT_SMI_CHECK); |
| 7616 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7617 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7618 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7619 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7620 | __ bind(&smi_element); |
| 7621 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7622 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7623 | FixedArrayBase::kHeaderSize), eax); |
| 7624 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7625 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7626 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7627 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7628 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7629 | __ push(edx); |
| 7630 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7631 | __ StoreNumberToDoubleElements(eax, |
| 7632 | edx, |
| 7633 | ecx, |
| 7634 | edi, |
| 7635 | xmm0, |
| 7636 | &slow_elements_from_double, |
| 7637 | false); |
| 7638 | __ pop(edx); |
| 7639 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7642 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7643 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 7644 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7645 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7646 | int parameter_count_offset = |
| 7647 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7648 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7649 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7650 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7651 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7652 | ? kPointerSize |
| 7653 | : 0; |
| 7654 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7655 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7656 | } |
| 7657 | |
| 7658 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7659 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7660 | if (entry_hook_ != NULL) { |
| 7661 | ProfileEntryHookStub stub; |
| 7662 | masm->CallStub(&stub); |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | |
| 7667 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7668 | // Ecx is the only volatile register we must save. |
| 7669 | __ push(ecx); |
| 7670 | |
| 7671 | // Calculate and push the original stack pointer. |
| 7672 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7673 | __ push(eax); |
| 7674 | |
| 7675 | // Calculate and push the function address. |
| 7676 | __ mov(eax, Operand(eax, 0)); |
| 7677 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7678 | __ push(eax); |
| 7679 | |
| 7680 | // Call the entry hook. |
| 7681 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7682 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7683 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7684 | |
| 7685 | // Restore ecx. |
| 7686 | __ pop(ecx); |
| 7687 | __ ret(0); |
| 7688 | } |
| 7689 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7690 | #undef __ |
| 7691 | |
| 7692 | } } // namespace v8::internal |
| 7693 | |
| 7694 | #endif // V8_TARGET_ARCH_IA32 |