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" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 46 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 50 | descriptor->register_param_count_ = 4; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->stack_parameter_count_ = NULL; |
| 53 | descriptor->deoptimization_handler_ = |
| 54 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 55 | } |
| 56 | |
| 57 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 58 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 59 | Isolate* isolate, |
| 60 | CodeStubInterfaceDescriptor* descriptor) { |
| 61 | static Register registers[] = { edx, ecx }; |
| 62 | descriptor->register_param_count_ = 2; |
| 63 | descriptor->register_params_ = registers; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 64 | descriptor->stack_parameter_count_ = NULL; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 65 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 66 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 70 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 71 | Isolate* isolate, |
| 72 | CodeStubInterfaceDescriptor* descriptor) { |
| 73 | static Register registers[] = { eax, ebx }; |
| 74 | descriptor->register_param_count_ = 2; |
| 75 | descriptor->register_params_ = registers; |
| 76 | descriptor->deoptimization_handler_ = |
| 77 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 78 | } |
| 79 | |
| 80 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 81 | static void InitializeArrayConstructorDescriptor(Isolate* isolate, |
| 82 | CodeStubInterfaceDescriptor* descriptor) { |
| 83 | // register state |
| 84 | // edi -- constructor function |
| 85 | // ebx -- type info cell with elements kind |
| 86 | // eax -- number of arguments to the constructor function |
| 87 | static Register registers[] = { edi, ebx }; |
| 88 | descriptor->register_param_count_ = 2; |
| 89 | // stack param count needs (constructor pointer, and single argument) |
| 90 | descriptor->stack_parameter_count_ = &eax; |
| 91 | descriptor->register_params_ = registers; |
| 92 | descriptor->extra_expression_stack_count_ = 1; |
| 93 | descriptor->deoptimization_handler_ = |
| 94 | FUNCTION_ADDR(ArrayConstructor_StubFailure); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 99 | Isolate* isolate, |
| 100 | CodeStubInterfaceDescriptor* descriptor) { |
| 101 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 106 | Isolate* isolate, |
| 107 | CodeStubInterfaceDescriptor* descriptor) { |
| 108 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 113 | Isolate* isolate, |
| 114 | CodeStubInterfaceDescriptor* descriptor) { |
| 115 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 116 | } |
| 117 | |
| 118 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 119 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 120 | |
| 121 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 122 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 123 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 124 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 125 | __ ret(0); |
| 126 | |
| 127 | __ bind(&check_heap_number); |
| 128 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 129 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 130 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 131 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 132 | __ ret(0); |
| 133 | |
| 134 | __ bind(&call_builtin); |
| 135 | __ pop(ecx); // Pop return address. |
| 136 | __ push(eax); |
| 137 | __ push(ecx); // Push return address. |
| 138 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 139 | } |
| 140 | |
| 141 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 142 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 143 | // Create a new closure from the given function info in new |
| 144 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 145 | Counters* counters = masm->isolate()->counters(); |
| 146 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 147 | Label gc; |
| 148 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 149 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 150 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 151 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 152 | // Get the function info from the stack. |
| 153 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 154 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 155 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 156 | ? Context::FUNCTION_MAP_INDEX |
| 157 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 158 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 159 | // 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] | 160 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 161 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 162 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 163 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 164 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 165 | |
| 166 | // Initialize the rest of the function. We don't have to update the |
| 167 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 168 | Factory* factory = masm->isolate()->factory(); |
| 169 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 170 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 171 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 172 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 173 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 174 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 175 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 176 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 177 | |
| 178 | // Initialize the code pointer in the function to be the one |
| 179 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 180 | // But first check if there is an optimized version for our context. |
| 181 | Label check_optimized; |
| 182 | Label install_unoptimized; |
| 183 | if (FLAG_cache_optimized_code) { |
| 184 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 185 | __ test(ebx, ebx); |
| 186 | __ j(not_zero, &check_optimized, Label::kNear); |
| 187 | } |
| 188 | __ bind(&install_unoptimized); |
| 189 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 190 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 191 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 192 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 193 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 194 | |
| 195 | // Return and remove the on-stack parameter. |
| 196 | __ ret(1 * kPointerSize); |
| 197 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 198 | __ bind(&check_optimized); |
| 199 | |
| 200 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 201 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 202 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 203 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 204 | // Map must never be empty, so check the first elements. |
| 205 | Label install_optimized; |
| 206 | // Speculatively move code object into edx. |
| 207 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 208 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 209 | __ j(equal, &install_optimized); |
| 210 | |
| 211 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 212 | Label loop; |
| 213 | Label restore; |
| 214 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 215 | __ bind(&loop); |
| 216 | // Do not double check first entry. |
| 217 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 218 | __ j(equal, &restore); |
| 219 | __ sub(edx, Immediate(Smi::FromInt( |
| 220 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 221 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 222 | __ j(not_equal, &loop, Label::kNear); |
| 223 | // Hit: fetch the optimized code. |
| 224 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 225 | |
| 226 | __ bind(&install_optimized); |
| 227 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 228 | |
| 229 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 230 | // map and either unmangle them on marking or do nothing as the whole map is |
| 231 | // discarded on major GC anyway. |
| 232 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 233 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 234 | |
| 235 | // Now link a function into a list of optimized functions. |
| 236 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 237 | |
| 238 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 239 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 240 | |
| 241 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 242 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 243 | // it clobbers all the registers passed. |
| 244 | __ mov(edx, eax); |
| 245 | __ RecordWriteContextSlot( |
| 246 | ecx, |
| 247 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 248 | edx, |
| 249 | ebx, |
| 250 | kDontSaveFPRegs); |
| 251 | |
| 252 | // Return and remove the on-stack parameter. |
| 253 | __ ret(1 * kPointerSize); |
| 254 | |
| 255 | __ bind(&restore); |
| 256 | // Restore SharedFunctionInfo into edx. |
| 257 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 258 | __ jmp(&install_unoptimized); |
| 259 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 260 | // Create a new closure through the slower runtime call. |
| 261 | __ bind(&gc); |
| 262 | __ pop(ecx); // Temporarily remove return address. |
| 263 | __ pop(edx); |
| 264 | __ push(esi); |
| 265 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 266 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 267 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 268 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
| 272 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 273 | // Try to allocate the context in new space. |
| 274 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 275 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 276 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 277 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 278 | |
| 279 | // Get the function from the stack. |
| 280 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 281 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 282 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 283 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 284 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 285 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 286 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 287 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 288 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 289 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 290 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 291 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 292 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 293 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 294 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 295 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 296 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 297 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 298 | |
| 299 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 300 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 301 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 302 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 303 | } |
| 304 | |
| 305 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 306 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 307 | __ ret(1 * kPointerSize); |
| 308 | |
| 309 | // Need to collect. Call into runtime system. |
| 310 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 311 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 315 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 316 | // Stack layout on entry: |
| 317 | // |
| 318 | // [esp + (1 * kPointerSize)]: function |
| 319 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 320 | |
| 321 | // Try to allocate the context in new space. |
| 322 | Label gc; |
| 323 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 324 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 325 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 326 | |
| 327 | // Get the function or sentinel from the stack. |
| 328 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 329 | |
| 330 | // Get the serialized scope info from the stack. |
| 331 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 332 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 333 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 334 | Factory* factory = masm->isolate()->factory(); |
| 335 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 336 | factory->block_context_map()); |
| 337 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 338 | Immediate(Smi::FromInt(length))); |
| 339 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 340 | // 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] | 341 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 342 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 343 | // we still have to look up. |
| 344 | Label after_sentinel; |
| 345 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 346 | if (FLAG_debug_code) { |
| 347 | const char* message = "Expected 0 as a Smi sentinel"; |
| 348 | __ cmp(ecx, 0); |
| 349 | __ Assert(equal, message); |
| 350 | } |
| 351 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 352 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 353 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 354 | __ bind(&after_sentinel); |
| 355 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 356 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 357 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 358 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 359 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 360 | |
| 361 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 362 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 363 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 364 | |
| 365 | // Initialize the rest of the slots to the hole value. |
| 366 | if (slots_ == 1) { |
| 367 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 368 | factory->the_hole_value()); |
| 369 | } else { |
| 370 | __ mov(ebx, factory->the_hole_value()); |
| 371 | for (int i = 0; i < slots_; i++) { |
| 372 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | // Return and remove the on-stack parameters. |
| 377 | __ mov(esi, eax); |
| 378 | __ ret(2 * kPointerSize); |
| 379 | |
| 380 | // Need to collect. Call into runtime system. |
| 381 | __ bind(&gc); |
| 382 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 383 | } |
| 384 | |
| 385 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 386 | static void GenerateFastCloneShallowArrayCommon( |
| 387 | MacroAssembler* masm, |
| 388 | int length, |
| 389 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 390 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 391 | Label* fail) { |
| 392 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 393 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 394 | // ecx: boilerplate literal array. |
| 395 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 396 | |
| 397 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 398 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 399 | if (length > 0) { |
| 400 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 401 | ? FixedDoubleArray::SizeFor(length) |
| 402 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 403 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 404 | int size = JSArray::kSize; |
| 405 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 406 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 407 | size += AllocationSiteInfo::kSize; |
| 408 | } |
| 409 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 410 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 411 | // Allocate both the JS array and the elements array in one big |
| 412 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 413 | AllocationFlags flags = TAG_OBJECT; |
| 414 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 415 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 416 | } |
| 417 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 418 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 419 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 420 | __ mov(FieldOperand(eax, allocation_info_start), |
| 421 | Immediate(Handle<Map>(masm->isolate()->heap()-> |
| 422 | allocation_site_info_map()))); |
| 423 | __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); |
| 424 | } |
| 425 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 426 | // Copy the JS array part. |
| 427 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 428 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 429 | __ mov(ebx, FieldOperand(ecx, i)); |
| 430 | __ mov(FieldOperand(eax, i), ebx); |
| 431 | } |
| 432 | } |
| 433 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 434 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 435 | // Get hold of the elements array of the boilerplate and setup the |
| 436 | // elements pointer in the resulting object. |
| 437 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 438 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 439 | __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 440 | } else { |
| 441 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 442 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 443 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 444 | |
| 445 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 446 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 447 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 448 | __ mov(ebx, FieldOperand(ecx, i)); |
| 449 | __ mov(FieldOperand(edx, i), ebx); |
| 450 | } |
| 451 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 452 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 453 | int i; |
| 454 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 455 | __ mov(ebx, FieldOperand(ecx, i)); |
| 456 | __ mov(FieldOperand(edx, i), ebx); |
| 457 | } |
| 458 | while (i < elements_size) { |
| 459 | __ fld_d(FieldOperand(ecx, i)); |
| 460 | __ fstp_d(FieldOperand(edx, i)); |
| 461 | i += kDoubleSize; |
| 462 | } |
| 463 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 466 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 467 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 468 | |
| 469 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 470 | // Stack layout on entry: |
| 471 | // |
| 472 | // [esp + kPointerSize]: constant elements. |
| 473 | // [esp + (2 * kPointerSize)]: literal index. |
| 474 | // [esp + (3 * kPointerSize)]: literals array. |
| 475 | |
| 476 | // Load boilerplate object into ecx and check if we need to create a |
| 477 | // boilerplate. |
| 478 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 479 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 480 | STATIC_ASSERT(kPointerSize == 4); |
| 481 | STATIC_ASSERT(kSmiTagSize == 1); |
| 482 | STATIC_ASSERT(kSmiTag == 0); |
| 483 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 484 | FixedArray::kHeaderSize)); |
| 485 | Factory* factory = masm->isolate()->factory(); |
| 486 | __ cmp(ecx, factory->undefined_value()); |
| 487 | Label slow_case; |
| 488 | __ j(equal, &slow_case); |
| 489 | |
| 490 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 491 | // ecx is boilerplate object. |
| 492 | if (mode == CLONE_ANY_ELEMENTS) { |
| 493 | Label double_elements, check_fast_elements; |
| 494 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 495 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 496 | &check_fast_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 497 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 498 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 499 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 500 | __ ret(3 * kPointerSize); |
| 501 | |
| 502 | __ bind(&check_fast_elements); |
| 503 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 504 | &double_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 505 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 506 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 507 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 508 | __ ret(3 * kPointerSize); |
| 509 | |
| 510 | __ bind(&double_elements); |
| 511 | mode = CLONE_DOUBLE_ELEMENTS; |
| 512 | // Fall through to generate the code to handle double elements. |
| 513 | } |
| 514 | |
| 515 | if (FLAG_debug_code) { |
| 516 | const char* message; |
| 517 | Handle<Map> expected_map; |
| 518 | if (mode == CLONE_ELEMENTS) { |
| 519 | message = "Expected (writable) fixed array"; |
| 520 | expected_map = factory->fixed_array_map(); |
| 521 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 522 | message = "Expected (writable) fixed double array"; |
| 523 | expected_map = factory->fixed_double_array_map(); |
| 524 | } else { |
| 525 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 526 | message = "Expected copy-on-write fixed array"; |
| 527 | expected_map = factory->fixed_cow_array_map(); |
| 528 | } |
| 529 | __ push(ecx); |
| 530 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 531 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 532 | __ Assert(equal, message); |
| 533 | __ pop(ecx); |
| 534 | } |
| 535 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 536 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 537 | allocation_site_mode_, |
| 538 | &slow_case); |
| 539 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 540 | // Return and remove the on-stack parameters. |
| 541 | __ ret(3 * kPointerSize); |
| 542 | |
| 543 | __ bind(&slow_case); |
| 544 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 545 | } |
| 546 | |
| 547 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 548 | // The stub expects its argument on the stack and returns its result in tos_: |
| 549 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 550 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 551 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 552 | // 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] | 553 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 554 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 555 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 556 | const Register map = edx; |
| 557 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 558 | if (!types_.IsEmpty()) { |
| 559 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 560 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 561 | |
| 562 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 563 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 564 | |
| 565 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 566 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 567 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 568 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 569 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 570 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 571 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 572 | if (types_.Contains(SMI)) { |
| 573 | // Smis: 0 -> false, all other -> true |
| 574 | Label not_smi; |
| 575 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 576 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 577 | if (!tos_.is(argument)) { |
| 578 | __ mov(tos_, argument); |
| 579 | } |
| 580 | __ ret(1 * kPointerSize); |
| 581 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 582 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 583 | // If we need a map later and have a Smi -> patch. |
| 584 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 585 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 586 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 587 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 588 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 589 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 590 | if (types_.CanBeUndetectable()) { |
| 591 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 592 | 1 << Map::kIsUndetectable); |
| 593 | // Undetectable -> false. |
| 594 | Label not_undetectable; |
| 595 | __ j(zero, ¬_undetectable, Label::kNear); |
| 596 | __ Set(tos_, Immediate(0)); |
| 597 | __ ret(1 * kPointerSize); |
| 598 | __ bind(¬_undetectable); |
| 599 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 600 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 601 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 602 | if (types_.Contains(SPEC_OBJECT)) { |
| 603 | // spec object -> true. |
| 604 | Label not_js_object; |
| 605 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 606 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 607 | // argument contains the correct return value already. |
| 608 | if (!tos_.is(argument)) { |
| 609 | __ Set(tos_, Immediate(1)); |
| 610 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 611 | __ ret(1 * kPointerSize); |
| 612 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 613 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 614 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 615 | if (types_.Contains(STRING)) { |
| 616 | // String value -> false iff empty. |
| 617 | Label not_string; |
| 618 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 619 | __ j(above_equal, ¬_string, Label::kNear); |
| 620 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 621 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 622 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (types_.Contains(HEAP_NUMBER)) { |
| 626 | // heap number -> false iff +0, -0, or NaN. |
| 627 | Label not_heap_number, false_result; |
| 628 | __ cmp(map, factory->heap_number_map()); |
| 629 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 630 | __ fldz(); |
| 631 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 632 | __ FCmp(); |
| 633 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 634 | // argument contains the correct return value already. |
| 635 | if (!tos_.is(argument)) { |
| 636 | __ Set(tos_, Immediate(1)); |
| 637 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 638 | __ ret(1 * kPointerSize); |
| 639 | __ bind(&false_result); |
| 640 | __ Set(tos_, Immediate(0)); |
| 641 | __ ret(1 * kPointerSize); |
| 642 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 643 | } |
| 644 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 645 | __ bind(&patch); |
| 646 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 650 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 651 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 652 | // store the registers in any particular way, but we do have to store and |
| 653 | // restore them. |
| 654 | __ pushad(); |
| 655 | if (save_doubles_ == kSaveFPRegs) { |
| 656 | CpuFeatures::Scope scope(SSE2); |
| 657 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 658 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 659 | XMMRegister reg = XMMRegister::from_code(i); |
| 660 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 661 | } |
| 662 | } |
| 663 | const int argument_count = 1; |
| 664 | |
| 665 | AllowExternalCallThatCantCauseGC scope(masm); |
| 666 | __ PrepareCallCFunction(argument_count, ecx); |
| 667 | __ mov(Operand(esp, 0 * kPointerSize), |
| 668 | Immediate(ExternalReference::isolate_address())); |
| 669 | __ CallCFunction( |
| 670 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 671 | argument_count); |
| 672 | if (save_doubles_ == kSaveFPRegs) { |
| 673 | CpuFeatures::Scope scope(SSE2); |
| 674 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 675 | XMMRegister reg = XMMRegister::from_code(i); |
| 676 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 677 | } |
| 678 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 679 | } |
| 680 | __ popad(); |
| 681 | __ ret(0); |
| 682 | } |
| 683 | |
| 684 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 685 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 686 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 687 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 688 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 689 | const Register argument = eax; |
| 690 | if (types_.Contains(type)) { |
| 691 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 692 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 693 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 694 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 695 | if (!result) { |
| 696 | // If we have to return zero, there is no way around clearing tos_. |
| 697 | __ Set(tos_, Immediate(0)); |
| 698 | } else if (!tos_.is(argument)) { |
| 699 | // If we have to return non-zero, we can re-use the argument if it is the |
| 700 | // same register as the result, because we never see Smi-zero here. |
| 701 | __ Set(tos_, Immediate(1)); |
| 702 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 703 | __ ret(1 * kPointerSize); |
| 704 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | |
| 709 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 710 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 711 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 712 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 713 | __ push(ecx); // Push return address. |
| 714 | // Patch the caller to an appropriate specialized stub and return the |
| 715 | // operation result to the caller of the stub. |
| 716 | __ TailCallExternalReference( |
| 717 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 718 | 3, |
| 719 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 723 | class FloatingPointHelper : public AllStatic { |
| 724 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 725 | enum ArgLocation { |
| 726 | ARGS_ON_STACK, |
| 727 | ARGS_IN_REGISTERS |
| 728 | }; |
| 729 | |
| 730 | // Code pattern for loading a floating point value. Input value must |
| 731 | // be either a smi or a heap number object (fp value). Requirements: |
| 732 | // operand in register number. Returns operand as floating point number |
| 733 | // on FPU stack. |
| 734 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 735 | |
| 736 | // Code pattern for loading floating point values. Input values must |
| 737 | // be either smi or heap number objects (fp values). Requirements: |
| 738 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 739 | // Returns operands as floating point numbers on FPU stack. |
| 740 | static void LoadFloatOperands(MacroAssembler* masm, |
| 741 | Register scratch, |
| 742 | ArgLocation arg_location = ARGS_ON_STACK); |
| 743 | |
| 744 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 745 | // Expects operands in edx, eax. |
| 746 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 747 | |
| 748 | // Test if operands are smi or number objects (fp). Requirements: |
| 749 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 750 | // operands, jumps to the non_float label otherwise. |
| 751 | static void CheckFloatOperands(MacroAssembler* masm, |
| 752 | Label* non_float, |
| 753 | Register scratch); |
| 754 | |
| 755 | // Takes the operands in edx and eax and loads them as integers in eax |
| 756 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 757 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 758 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 759 | BinaryOpIC::TypeInfo left_type, |
| 760 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 761 | Label* operand_conversion_failure); |
| 762 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 763 | // Assumes that operands are smis or heap numbers and loads them |
| 764 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 765 | // Leaves operands unchanged. |
| 766 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 767 | |
| 768 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 769 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 770 | // either operand is not a number. Operands are in edx and eax. |
| 771 | // Leaves operands unchanged. |
| 772 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 773 | |
| 774 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 775 | // Expects operands in edx, eax. |
| 776 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 777 | |
| 778 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 779 | // have int32 values. |
| 780 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 781 | Label* non_int32, |
| 782 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 783 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 784 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 785 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 786 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 787 | Label* non_int32, |
| 788 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 789 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 790 | Register scratch, |
| 791 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 792 | }; |
| 793 | |
| 794 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 795 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 796 | // is faster than using the built-in instructions on floating point registers. |
| 797 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 798 | // trashed registers. |
| 799 | static void IntegerConvert(MacroAssembler* masm, |
| 800 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 801 | bool use_sse3, |
| 802 | Label* conversion_failure) { |
| 803 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 804 | Label done, right_exponent, normal_exponent; |
| 805 | Register scratch = ebx; |
| 806 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 807 | // Get exponent word. |
| 808 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 809 | // Get exponent alone in scratch2. |
| 810 | __ mov(scratch2, scratch); |
| 811 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 812 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 813 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 814 | // Load ecx with zero. We use this either for the final shift or |
| 815 | // for the answer. |
| 816 | __ xor_(ecx, ecx); |
| 817 | // If the exponent is above 83, the number contains no significant |
| 818 | // bits in the range 0..2^31, so the result is zero. |
| 819 | static const uint32_t kResultIsZeroExponent = 83; |
| 820 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 821 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 822 | if (use_sse3) { |
| 823 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 824 | // 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] | 825 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 826 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 827 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 828 | // Load x87 register with heap number. |
| 829 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 830 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 831 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 832 | // Do conversion, which cannot fail because we checked the exponent. |
| 833 | __ fisttp_d(Operand(esp, 0)); |
| 834 | __ 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] | 835 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 836 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 837 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 838 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 839 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 840 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 841 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 842 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 843 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 844 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 845 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 846 | // If the exponent is higher than that then go to slow case. This catches |
| 847 | // 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] | 848 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 849 | |
| 850 | { |
| 851 | // Handle a big exponent. The only reason we have this code is that the |
| 852 | // >>> 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] | 853 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 854 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 855 | __ j(not_equal, conversion_failure); |
| 856 | // We have the big exponent, typically from >>>. This means the number is |
| 857 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 858 | __ mov(scratch2, scratch); |
| 859 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 860 | // Put back the implicit 1. |
| 861 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 862 | // Shift up the mantissa bits to take up the space the exponent used to |
| 863 | // take. We just orred in the implicit bit so that took care of one and |
| 864 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 865 | // shift distance. |
| 866 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 867 | __ shl(scratch2, big_shift_distance); |
| 868 | // Get the second half of the double. |
| 869 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 870 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 871 | // mantissa word. |
| 872 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 873 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 874 | // 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] | 875 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 876 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 877 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 878 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 882 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 883 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 884 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 885 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 886 | |
| 887 | __ bind(&right_exponent); |
| 888 | // Here ecx is the shift, scratch is the exponent word. |
| 889 | // Get the top bits of the mantissa. |
| 890 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 891 | // Put back the implicit 1. |
| 892 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 893 | // Shift up the mantissa bits to take up the space the exponent used to |
| 894 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 895 | // word. Shift them to the top bits. |
| 896 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 897 | __ shl(scratch, shift_distance); |
| 898 | // Get the second half of the double. For some exponents we don't |
| 899 | // actually need this because the bits get shifted out again, but |
| 900 | // it's probably slower to test than just to do it. |
| 901 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 902 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 903 | // mantissa word. |
| 904 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 905 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 906 | // Move down according to the exponent. |
| 907 | __ shr_cl(scratch2); |
| 908 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 909 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 910 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 911 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 912 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 913 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 914 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 915 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 916 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 917 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 918 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 919 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 923 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 924 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 925 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 926 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 927 | Register source, |
| 928 | Label* conversion_failure) { |
| 929 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 930 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 931 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 932 | } |
| 933 | |
| 934 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 935 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 936 | const char* op_name = Token::Name(op_); |
| 937 | const char* overwrite_name = NULL; // Make g++ happy. |
| 938 | switch (mode_) { |
| 939 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 940 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 941 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 942 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 943 | op_name, |
| 944 | overwrite_name, |
| 945 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | |
| 949 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 950 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 951 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 952 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 953 | GenerateTypeTransition(masm); |
| 954 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 955 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 956 | GenerateSmiStub(masm); |
| 957 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 958 | case UnaryOpIC::NUMBER: |
| 959 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 960 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 961 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 962 | GenerateGenericStub(masm); |
| 963 | break; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 968 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 969 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 970 | |
| 971 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 972 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 973 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 974 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 975 | |
| 976 | __ push(ecx); // Push return address. |
| 977 | |
| 978 | // Patch the caller to an appropriate specialized stub and return the |
| 979 | // operation result to the caller of the stub. |
| 980 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 981 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
| 985 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 986 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 987 | switch (op_) { |
| 988 | case Token::SUB: |
| 989 | GenerateSmiStubSub(masm); |
| 990 | break; |
| 991 | case Token::BIT_NOT: |
| 992 | GenerateSmiStubBitNot(masm); |
| 993 | break; |
| 994 | default: |
| 995 | UNREACHABLE(); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1000 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1001 | Label non_smi, undo, slow; |
| 1002 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 1003 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1004 | __ bind(&undo); |
| 1005 | GenerateSmiCodeUndo(masm); |
| 1006 | __ bind(&non_smi); |
| 1007 | __ bind(&slow); |
| 1008 | GenerateTypeTransition(masm); |
| 1009 | } |
| 1010 | |
| 1011 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1012 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1013 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1014 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1015 | __ bind(&non_smi); |
| 1016 | GenerateTypeTransition(masm); |
| 1017 | } |
| 1018 | |
| 1019 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1020 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 1021 | Label* non_smi, |
| 1022 | Label* undo, |
| 1023 | Label* slow, |
| 1024 | Label::Distance non_smi_near, |
| 1025 | Label::Distance undo_near, |
| 1026 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1027 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1028 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1029 | |
| 1030 | // 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] | 1031 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1032 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1033 | |
| 1034 | // 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] | 1035 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1036 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1037 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1038 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1039 | __ ret(0); |
| 1040 | } |
| 1041 | |
| 1042 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1043 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1044 | MacroAssembler* masm, |
| 1045 | Label* non_smi, |
| 1046 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1047 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1048 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1049 | |
| 1050 | // Flip bits and revert inverted smi-tag. |
| 1051 | __ not_(eax); |
| 1052 | __ and_(eax, ~kSmiTagMask); |
| 1053 | __ ret(0); |
| 1054 | } |
| 1055 | |
| 1056 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1057 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1058 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1063 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1064 | switch (op_) { |
| 1065 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1066 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1067 | break; |
| 1068 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1069 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1070 | break; |
| 1071 | default: |
| 1072 | UNREACHABLE(); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1077 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1078 | Label non_smi, undo, slow, call_builtin; |
| 1079 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1080 | __ bind(&non_smi); |
| 1081 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1082 | __ bind(&undo); |
| 1083 | GenerateSmiCodeUndo(masm); |
| 1084 | __ bind(&slow); |
| 1085 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1086 | __ bind(&call_builtin); |
| 1087 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1091 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1092 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1093 | Label non_smi, slow; |
| 1094 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1095 | __ bind(&non_smi); |
| 1096 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1097 | __ bind(&slow); |
| 1098 | GenerateTypeTransition(masm); |
| 1099 | } |
| 1100 | |
| 1101 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1102 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1103 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1104 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1105 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1106 | __ j(not_equal, slow); |
| 1107 | |
| 1108 | if (mode_ == UNARY_OVERWRITE) { |
| 1109 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1110 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1111 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1112 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1113 | // edx: operand |
| 1114 | |
| 1115 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1116 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1117 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1118 | |
| 1119 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1120 | { |
| 1121 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1122 | __ push(edx); |
| 1123 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1124 | __ pop(edx); |
| 1125 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1126 | |
| 1127 | __ bind(&heapnumber_allocated); |
| 1128 | // eax: allocated 'empty' number |
| 1129 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1130 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1131 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1132 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1133 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1134 | } |
| 1135 | __ ret(0); |
| 1136 | } |
| 1137 | |
| 1138 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1139 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1140 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1141 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1142 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1143 | __ j(not_equal, slow); |
| 1144 | |
| 1145 | // 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] | 1146 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1147 | |
| 1148 | // 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] | 1149 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1150 | __ not_(ecx); |
| 1151 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1152 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1153 | |
| 1154 | // Tag the result as a smi and we're done. |
| 1155 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1156 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1157 | __ ret(0); |
| 1158 | |
| 1159 | // Try to store the result in a heap number. |
| 1160 | __ bind(&try_float); |
| 1161 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1162 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1163 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1164 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1165 | __ jmp(&heapnumber_allocated); |
| 1166 | |
| 1167 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1168 | { |
| 1169 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1170 | // Push the original HeapNumber on the stack. The integer value can't |
| 1171 | // be stored since it's untagged and not in the smi range (so we can't |
| 1172 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1173 | __ push(ebx); |
| 1174 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1175 | // New HeapNumber is in eax. |
| 1176 | __ pop(edx); |
| 1177 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1178 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1179 | // This conversion won't go slow-case. |
| 1180 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1181 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1182 | |
| 1183 | __ bind(&heapnumber_allocated); |
| 1184 | } |
| 1185 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1186 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1187 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1188 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1189 | } else { |
| 1190 | __ push(ecx); |
| 1191 | __ fild_s(Operand(esp, 0)); |
| 1192 | __ pop(ecx); |
| 1193 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1194 | } |
| 1195 | __ ret(0); |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1200 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1201 | switch (op_) { |
| 1202 | case Token::SUB: |
| 1203 | GenerateGenericStubSub(masm); |
| 1204 | break; |
| 1205 | case Token::BIT_NOT: |
| 1206 | GenerateGenericStubBitNot(masm); |
| 1207 | break; |
| 1208 | default: |
| 1209 | UNREACHABLE(); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1214 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1215 | Label non_smi, undo, slow; |
| 1216 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1217 | __ bind(&non_smi); |
| 1218 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1219 | __ bind(&undo); |
| 1220 | GenerateSmiCodeUndo(masm); |
| 1221 | __ bind(&slow); |
| 1222 | GenerateGenericCodeFallback(masm); |
| 1223 | } |
| 1224 | |
| 1225 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1226 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1227 | Label non_smi, slow; |
| 1228 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1229 | __ bind(&non_smi); |
| 1230 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1231 | __ bind(&slow); |
| 1232 | GenerateGenericCodeFallback(masm); |
| 1233 | } |
| 1234 | |
| 1235 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1236 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1237 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1238 | __ pop(ecx); // pop return address. |
| 1239 | __ push(eax); |
| 1240 | __ push(ecx); // push return address |
| 1241 | switch (op_) { |
| 1242 | case Token::SUB: |
| 1243 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1244 | break; |
| 1245 | case Token::BIT_NOT: |
| 1246 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1247 | break; |
| 1248 | default: |
| 1249 | UNREACHABLE(); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1254 | void BinaryOpStub::Initialize() { |
| 1255 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1256 | } |
| 1257 | |
| 1258 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1259 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1260 | __ pop(ecx); // Save return address. |
| 1261 | __ push(edx); |
| 1262 | __ push(eax); |
| 1263 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1264 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1265 | |
| 1266 | __ push(ecx); // Push return address. |
| 1267 | |
| 1268 | // Patch the caller to an appropriate specialized stub and return the |
| 1269 | // operation result to the caller of the stub. |
| 1270 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1271 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1272 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1273 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1274 | 1); |
| 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | // Prepare for a type transition runtime call when the args are already on |
| 1279 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1280 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1281 | __ pop(ecx); // Save return address. |
| 1282 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1283 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1284 | |
| 1285 | __ push(ecx); // Push return address. |
| 1286 | |
| 1287 | // Patch the caller to an appropriate specialized stub and return the |
| 1288 | // operation result to the caller of the stub. |
| 1289 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1290 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1291 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1292 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | 1); |
| 1294 | } |
| 1295 | |
| 1296 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1297 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1298 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1300 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1301 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1302 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1303 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1304 | Comment load_comment(masm, "-- Load arguments"); |
| 1305 | Register left = edx; |
| 1306 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1307 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1308 | left = eax; |
| 1309 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1310 | __ mov(ebx, eax); |
| 1311 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | // 2. Prepare the smi check of both operands by oring them together. |
| 1316 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1317 | Label not_smis; |
| 1318 | Register combined = ecx; |
| 1319 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1320 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1321 | case Token::BIT_OR: |
| 1322 | // Perform the operation into eax and smi check the result. Preserve |
| 1323 | // eax in case the result is not a smi. |
| 1324 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1325 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1326 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1327 | combined = right; |
| 1328 | break; |
| 1329 | |
| 1330 | case Token::BIT_XOR: |
| 1331 | case Token::BIT_AND: |
| 1332 | case Token::ADD: |
| 1333 | case Token::SUB: |
| 1334 | case Token::MUL: |
| 1335 | case Token::DIV: |
| 1336 | case Token::MOD: |
| 1337 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1338 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1339 | break; |
| 1340 | |
| 1341 | case Token::SHL: |
| 1342 | case Token::SAR: |
| 1343 | case Token::SHR: |
| 1344 | // Move the right operand into ecx for the shift operation, use eax |
| 1345 | // for the smi check register. |
| 1346 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1347 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1348 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1349 | combined = right; |
| 1350 | break; |
| 1351 | |
| 1352 | default: |
| 1353 | break; |
| 1354 | } |
| 1355 | |
| 1356 | // 3. Perform the smi check of the operands. |
| 1357 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1358 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1359 | |
| 1360 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1361 | // eax and check the result if necessary. |
| 1362 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1363 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1364 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1365 | case Token::BIT_OR: |
| 1366 | // Nothing to do. |
| 1367 | break; |
| 1368 | |
| 1369 | case Token::BIT_XOR: |
| 1370 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1371 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case Token::BIT_AND: |
| 1375 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1376 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | |
| 1379 | case Token::SHL: |
| 1380 | // Remove tags from operands (but keep sign). |
| 1381 | __ SmiUntag(left); |
| 1382 | __ SmiUntag(ecx); |
| 1383 | // Perform the operation. |
| 1384 | __ shl_cl(left); |
| 1385 | // Check that the *signed* result fits in a smi. |
| 1386 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1387 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1388 | // Tag the result and store it in register eax. |
| 1389 | __ SmiTag(left); |
| 1390 | __ mov(eax, left); |
| 1391 | break; |
| 1392 | |
| 1393 | case Token::SAR: |
| 1394 | // Remove tags from operands (but keep sign). |
| 1395 | __ SmiUntag(left); |
| 1396 | __ SmiUntag(ecx); |
| 1397 | // Perform the operation. |
| 1398 | __ sar_cl(left); |
| 1399 | // Tag the result and store it in register eax. |
| 1400 | __ SmiTag(left); |
| 1401 | __ mov(eax, left); |
| 1402 | break; |
| 1403 | |
| 1404 | case Token::SHR: |
| 1405 | // Remove tags from operands (but keep sign). |
| 1406 | __ SmiUntag(left); |
| 1407 | __ SmiUntag(ecx); |
| 1408 | // Perform the operation. |
| 1409 | __ shr_cl(left); |
| 1410 | // Check that the *unsigned* result fits in a smi. |
| 1411 | // Neither of the two high-order bits can be set: |
| 1412 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1413 | // - 0x40000000: this number would convert to negative when |
| 1414 | // Smi tagging these two cases can only happen with shifts |
| 1415 | // by 0 or 1 when handed a valid smi. |
| 1416 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1417 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1418 | // Tag the result and store it in register eax. |
| 1419 | __ SmiTag(left); |
| 1420 | __ mov(eax, left); |
| 1421 | break; |
| 1422 | |
| 1423 | case Token::ADD: |
| 1424 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1425 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1426 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1430 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1431 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | __ mov(eax, left); |
| 1433 | break; |
| 1434 | |
| 1435 | case Token::MUL: |
| 1436 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1437 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1438 | // We can't revert the multiplication if the result is not a smi |
| 1439 | // so save the right operand. |
| 1440 | __ mov(ebx, right); |
| 1441 | // Remove tag from one of the operands (but keep sign). |
| 1442 | __ SmiUntag(right); |
| 1443 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1444 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1445 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1446 | // Check for negative zero result. Use combined = left | right. |
| 1447 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1448 | break; |
| 1449 | |
| 1450 | case Token::DIV: |
| 1451 | // We can't revert the division if the result is not a smi so |
| 1452 | // save the left operand. |
| 1453 | __ mov(edi, left); |
| 1454 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1455 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1456 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1457 | // Sign extend left into edx:eax. |
| 1458 | ASSERT(left.is(eax)); |
| 1459 | __ cdq(); |
| 1460 | // Divide edx:eax by right. |
| 1461 | __ idiv(right); |
| 1462 | // Check for the corner case of dividing the most negative smi by |
| 1463 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1464 | // instruction. |
| 1465 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1466 | __ cmp(eax, 0x40000000); |
| 1467 | __ j(equal, &use_fp_on_smis); |
| 1468 | // Check for negative zero result. Use combined = left | right. |
| 1469 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1470 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1471 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1472 | __ j(not_zero, &use_fp_on_smis); |
| 1473 | // Tag the result and store it in register eax. |
| 1474 | __ SmiTag(eax); |
| 1475 | break; |
| 1476 | |
| 1477 | case Token::MOD: |
| 1478 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1479 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1480 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Sign extend left into edx:eax. |
| 1483 | ASSERT(left.is(eax)); |
| 1484 | __ cdq(); |
| 1485 | // Divide edx:eax by right. |
| 1486 | __ idiv(right); |
| 1487 | // Check for negative zero result. Use combined = left | right. |
| 1488 | __ NegativeZeroTest(edx, combined, slow); |
| 1489 | // Move remainder to register eax. |
| 1490 | __ mov(eax, edx); |
| 1491 | break; |
| 1492 | |
| 1493 | default: |
| 1494 | UNREACHABLE(); |
| 1495 | } |
| 1496 | |
| 1497 | // 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] | 1498 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1499 | case Token::ADD: |
| 1500 | case Token::SUB: |
| 1501 | case Token::MUL: |
| 1502 | case Token::DIV: |
| 1503 | __ ret(0); |
| 1504 | break; |
| 1505 | case Token::MOD: |
| 1506 | case Token::BIT_OR: |
| 1507 | case Token::BIT_AND: |
| 1508 | case Token::BIT_XOR: |
| 1509 | case Token::SAR: |
| 1510 | case Token::SHL: |
| 1511 | case Token::SHR: |
| 1512 | __ ret(2 * kPointerSize); |
| 1513 | break; |
| 1514 | default: |
| 1515 | UNREACHABLE(); |
| 1516 | } |
| 1517 | |
| 1518 | // 6. For some operations emit inline code to perform floating point |
| 1519 | // operations on known smis (e.g., if the result of the operation |
| 1520 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1521 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1522 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1523 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1524 | // Undo the effects of some operations, and some register moves. |
| 1525 | case Token::SHL: |
| 1526 | // The arguments are saved on the stack, and only used from there. |
| 1527 | break; |
| 1528 | case Token::ADD: |
| 1529 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1530 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1531 | break; |
| 1532 | case Token::SUB: |
| 1533 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1534 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1535 | break; |
| 1536 | case Token::MUL: |
| 1537 | // Right was clobbered but a copy is in ebx. |
| 1538 | __ mov(right, ebx); |
| 1539 | break; |
| 1540 | case Token::DIV: |
| 1541 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1542 | // division. They should be in eax, ebx for jump to not_smi. |
| 1543 | __ mov(eax, edi); |
| 1544 | break; |
| 1545 | default: |
| 1546 | // No other operators jump to use_fp_on_smis. |
| 1547 | break; |
| 1548 | } |
| 1549 | __ jmp(¬_smis); |
| 1550 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1551 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1552 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1553 | case Token::SHL: |
| 1554 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1556 | __ bind(&use_fp_on_smis); |
| 1557 | // Result we want is in left == edx, so we can put the allocated heap |
| 1558 | // number in eax. |
| 1559 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1560 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1561 | // It's OK to overwrite the arguments on the stack because we |
| 1562 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1563 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1564 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1565 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1566 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1567 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1568 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1569 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1570 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1571 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1572 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1573 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1574 | } else { |
| 1575 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1576 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1577 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1578 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1579 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1580 | __ ret(2 * kPointerSize); |
| 1581 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | case Token::ADD: |
| 1585 | case Token::SUB: |
| 1586 | case Token::MUL: |
| 1587 | case Token::DIV: { |
| 1588 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1589 | __ bind(&use_fp_on_smis); |
| 1590 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1591 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1592 | case Token::ADD: |
| 1593 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1594 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | case Token::SUB: |
| 1597 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1598 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1599 | break; |
| 1600 | case Token::MUL: |
| 1601 | // Right was clobbered but a copy is in ebx. |
| 1602 | __ mov(right, ebx); |
| 1603 | break; |
| 1604 | case Token::DIV: |
| 1605 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1606 | // division. |
| 1607 | __ mov(edx, edi); |
| 1608 | __ mov(eax, right); |
| 1609 | break; |
| 1610 | default: UNREACHABLE(); |
| 1611 | break; |
| 1612 | } |
| 1613 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1614 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1615 | CpuFeatures::Scope use_sse2(SSE2); |
| 1616 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1617 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1618 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1619 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1620 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1621 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1622 | default: UNREACHABLE(); |
| 1623 | } |
| 1624 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1625 | } else { // SSE2 not available, use FPU. |
| 1626 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1627 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | case Token::ADD: __ faddp(1); break; |
| 1629 | case Token::SUB: __ fsubp(1); break; |
| 1630 | case Token::MUL: __ fmulp(1); break; |
| 1631 | case Token::DIV: __ fdivp(1); break; |
| 1632 | default: UNREACHABLE(); |
| 1633 | } |
| 1634 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1635 | } |
| 1636 | __ mov(eax, ecx); |
| 1637 | __ ret(0); |
| 1638 | break; |
| 1639 | } |
| 1640 | |
| 1641 | default: |
| 1642 | break; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1647 | // edx and eax. |
| 1648 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1649 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1650 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1651 | case Token::BIT_OR: |
| 1652 | case Token::SHL: |
| 1653 | case Token::SAR: |
| 1654 | case Token::SHR: |
| 1655 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1656 | // check. |
| 1657 | __ mov(eax, ecx); |
| 1658 | break; |
| 1659 | |
| 1660 | case Token::DIV: |
| 1661 | case Token::MOD: |
| 1662 | // Operands are in eax, ebx at this point. |
| 1663 | __ mov(edx, eax); |
| 1664 | __ mov(eax, ebx); |
| 1665 | break; |
| 1666 | |
| 1667 | default: |
| 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1673 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | Label call_runtime; |
| 1675 | |
| 1676 | switch (op_) { |
| 1677 | case Token::ADD: |
| 1678 | case Token::SUB: |
| 1679 | case Token::MUL: |
| 1680 | case Token::DIV: |
| 1681 | break; |
| 1682 | case Token::MOD: |
| 1683 | case Token::BIT_OR: |
| 1684 | case Token::BIT_AND: |
| 1685 | case Token::BIT_XOR: |
| 1686 | case Token::SAR: |
| 1687 | case Token::SHL: |
| 1688 | case Token::SHR: |
| 1689 | GenerateRegisterArgsPush(masm); |
| 1690 | break; |
| 1691 | default: |
| 1692 | UNREACHABLE(); |
| 1693 | } |
| 1694 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1695 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1696 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1697 | BinaryOpStub_GenerateSmiCode( |
| 1698 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1699 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1700 | BinaryOpStub_GenerateSmiCode( |
| 1701 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1702 | } |
| 1703 | __ bind(&call_runtime); |
| 1704 | switch (op_) { |
| 1705 | case Token::ADD: |
| 1706 | case Token::SUB: |
| 1707 | case Token::MUL: |
| 1708 | case Token::DIV: |
| 1709 | GenerateTypeTransition(masm); |
| 1710 | break; |
| 1711 | case Token::MOD: |
| 1712 | case Token::BIT_OR: |
| 1713 | case Token::BIT_AND: |
| 1714 | case Token::BIT_XOR: |
| 1715 | case Token::SAR: |
| 1716 | case Token::SHL: |
| 1717 | case Token::SHR: |
| 1718 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1719 | break; |
| 1720 | default: |
| 1721 | UNREACHABLE(); |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1726 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1727 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1728 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1729 | ASSERT(op_ == Token::ADD); |
| 1730 | // If both arguments are strings, call the string add stub. |
| 1731 | // Otherwise, do a transition. |
| 1732 | |
| 1733 | // Registers containing left and right operands respectively. |
| 1734 | Register left = edx; |
| 1735 | Register right = eax; |
| 1736 | |
| 1737 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1738 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1739 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1740 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1741 | |
| 1742 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1743 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1744 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1745 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1746 | |
| 1747 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1748 | GenerateRegisterArgsPush(masm); |
| 1749 | __ TailCallStub(&string_add_stub); |
| 1750 | |
| 1751 | __ bind(&call_runtime); |
| 1752 | GenerateTypeTransition(masm); |
| 1753 | } |
| 1754 | |
| 1755 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1756 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1757 | Label* alloc_failure, |
| 1758 | OverwriteMode mode); |
| 1759 | |
| 1760 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1761 | // Input: |
| 1762 | // edx: left operand (tagged) |
| 1763 | // eax: right operand (tagged) |
| 1764 | // Output: |
| 1765 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1766 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1768 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | |
| 1770 | // Floating point case. |
| 1771 | switch (op_) { |
| 1772 | case Token::ADD: |
| 1773 | case Token::SUB: |
| 1774 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1775 | case Token::DIV: |
| 1776 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | Label not_floats; |
| 1778 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1779 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1780 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1781 | // It could be that only SMIs have been seen at either the left |
| 1782 | // or the right operand. For precise type feedback, patch the IC |
| 1783 | // again if this changes. |
| 1784 | // In theory, we would need the same check in the non-SSE2 case, |
| 1785 | // but since we don't support Crankshaft on such hardware we can |
| 1786 | // afford not to care about precise type feedback. |
| 1787 | if (left_type_ == BinaryOpIC::SMI) { |
| 1788 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1789 | } |
| 1790 | if (right_type_ == BinaryOpIC::SMI) { |
| 1791 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1792 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1793 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1794 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1795 | if (op_ == Token::MOD) { |
| 1796 | GenerateRegisterArgsPush(masm); |
| 1797 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1798 | } else { |
| 1799 | switch (op_) { |
| 1800 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1801 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1802 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1803 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1804 | default: UNREACHABLE(); |
| 1805 | } |
| 1806 | // Check result type if it is currently Int32. |
| 1807 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1808 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1809 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1810 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1811 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1812 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1813 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1814 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1815 | } else { // SSE2 not available, use FPU. |
| 1816 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1817 | FloatingPointHelper::LoadFloatOperands( |
| 1818 | masm, |
| 1819 | ecx, |
| 1820 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1821 | if (op_ == Token::MOD) { |
| 1822 | // The operands are now on the FPU stack, but we don't need them. |
| 1823 | __ fstp(0); |
| 1824 | __ fstp(0); |
| 1825 | GenerateRegisterArgsPush(masm); |
| 1826 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1827 | } else { |
| 1828 | switch (op_) { |
| 1829 | case Token::ADD: __ faddp(1); break; |
| 1830 | case Token::SUB: __ fsubp(1); break; |
| 1831 | case Token::MUL: __ fmulp(1); break; |
| 1832 | case Token::DIV: __ fdivp(1); break; |
| 1833 | default: UNREACHABLE(); |
| 1834 | } |
| 1835 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1836 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1837 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1838 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1839 | __ ret(0); |
| 1840 | __ bind(&after_alloc_failure); |
| 1841 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1842 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1843 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | __ bind(¬_floats); |
| 1847 | __ bind(¬_int32); |
| 1848 | GenerateTypeTransition(masm); |
| 1849 | break; |
| 1850 | } |
| 1851 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1852 | case Token::BIT_OR: |
| 1853 | case Token::BIT_AND: |
| 1854 | case Token::BIT_XOR: |
| 1855 | case Token::SAR: |
| 1856 | case Token::SHL: |
| 1857 | case Token::SHR: { |
| 1858 | GenerateRegisterArgsPush(masm); |
| 1859 | Label not_floats; |
| 1860 | Label not_int32; |
| 1861 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1862 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1863 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1864 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1865 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1866 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1867 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1868 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1869 | case Token::SAR: __ sar_cl(eax); break; |
| 1870 | case Token::SHL: __ shl_cl(eax); break; |
| 1871 | case Token::SHR: __ shr_cl(eax); break; |
| 1872 | default: UNREACHABLE(); |
| 1873 | } |
| 1874 | if (op_ == Token::SHR) { |
| 1875 | // Check if result is non-negative and fits in a smi. |
| 1876 | __ test(eax, Immediate(0xc0000000)); |
| 1877 | __ j(not_zero, &call_runtime); |
| 1878 | } else { |
| 1879 | // Check if result fits in a smi. |
| 1880 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1881 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1882 | } |
| 1883 | // Tag smi result and return. |
| 1884 | __ SmiTag(eax); |
| 1885 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1886 | |
| 1887 | // All ops except SHR return a signed int32 that we load in |
| 1888 | // a HeapNumber. |
| 1889 | if (op_ != Token::SHR) { |
| 1890 | __ bind(&non_smi_result); |
| 1891 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1892 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1893 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1894 | switch (mode_) { |
| 1895 | case OVERWRITE_LEFT: |
| 1896 | case OVERWRITE_RIGHT: |
| 1897 | // If the operand was an object, we skip the |
| 1898 | // allocation of a heap number. |
| 1899 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1900 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1901 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1902 | // Fall through! |
| 1903 | case NO_OVERWRITE: |
| 1904 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1905 | __ bind(&skip_allocation); |
| 1906 | break; |
| 1907 | default: UNREACHABLE(); |
| 1908 | } |
| 1909 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1910 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1911 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1912 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1913 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1914 | } else { |
| 1915 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1916 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1917 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1918 | } |
| 1919 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1920 | } |
| 1921 | |
| 1922 | __ bind(¬_floats); |
| 1923 | __ bind(¬_int32); |
| 1924 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1925 | break; |
| 1926 | } |
| 1927 | default: UNREACHABLE(); break; |
| 1928 | } |
| 1929 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1930 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1931 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1932 | __ bind(&call_runtime); |
| 1933 | |
| 1934 | switch (op_) { |
| 1935 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1936 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1938 | case Token::DIV: |
| 1939 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | break; |
| 1941 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1942 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1944 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1946 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1947 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1949 | break; |
| 1950 | default: |
| 1951 | UNREACHABLE(); |
| 1952 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1953 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1957 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1958 | if (op_ == Token::ADD) { |
| 1959 | // Handle string addition here, because it is the only operation |
| 1960 | // that does not do a ToNumber conversion on the operands. |
| 1961 | GenerateAddStrings(masm); |
| 1962 | } |
| 1963 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1964 | Factory* factory = masm->isolate()->factory(); |
| 1965 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1966 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1967 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1968 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1969 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1970 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1971 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1972 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1973 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1974 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1975 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1976 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1977 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1978 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1979 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1980 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1981 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1982 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1983 | } |
| 1984 | __ bind(&done); |
| 1985 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1986 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1990 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1991 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1992 | |
| 1993 | // Floating point case. |
| 1994 | switch (op_) { |
| 1995 | case Token::ADD: |
| 1996 | case Token::SUB: |
| 1997 | case Token::MUL: |
| 1998 | case Token::DIV: { |
| 1999 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2000 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2001 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2002 | |
| 2003 | // It could be that only SMIs have been seen at either the left |
| 2004 | // or the right operand. For precise type feedback, patch the IC |
| 2005 | // again if this changes. |
| 2006 | // In theory, we would need the same check in the non-SSE2 case, |
| 2007 | // but since we don't support Crankshaft on such hardware we can |
| 2008 | // afford not to care about precise type feedback. |
| 2009 | if (left_type_ == BinaryOpIC::SMI) { |
| 2010 | __ JumpIfNotSmi(edx, ¬_floats); |
| 2011 | } |
| 2012 | if (right_type_ == BinaryOpIC::SMI) { |
| 2013 | __ JumpIfNotSmi(eax, ¬_floats); |
| 2014 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2016 | if (left_type_ == BinaryOpIC::INT32) { |
| 2017 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2018 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2019 | } |
| 2020 | if (right_type_ == BinaryOpIC::INT32) { |
| 2021 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2022 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2023 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2024 | |
| 2025 | switch (op_) { |
| 2026 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2027 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2028 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2029 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2030 | default: UNREACHABLE(); |
| 2031 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2032 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2034 | __ ret(0); |
| 2035 | } else { // SSE2 not available, use FPU. |
| 2036 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2037 | FloatingPointHelper::LoadFloatOperands( |
| 2038 | masm, |
| 2039 | ecx, |
| 2040 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2041 | switch (op_) { |
| 2042 | case Token::ADD: __ faddp(1); break; |
| 2043 | case Token::SUB: __ fsubp(1); break; |
| 2044 | case Token::MUL: __ fmulp(1); break; |
| 2045 | case Token::DIV: __ fdivp(1); break; |
| 2046 | default: UNREACHABLE(); |
| 2047 | } |
| 2048 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2049 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2050 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2051 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2052 | __ ret(0); |
| 2053 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2054 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2055 | __ jmp(&call_runtime); |
| 2056 | } |
| 2057 | |
| 2058 | __ bind(¬_floats); |
| 2059 | GenerateTypeTransition(masm); |
| 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | case Token::MOD: { |
| 2064 | // For MOD we go directly to runtime in the non-smi case. |
| 2065 | break; |
| 2066 | } |
| 2067 | case Token::BIT_OR: |
| 2068 | case Token::BIT_AND: |
| 2069 | case Token::BIT_XOR: |
| 2070 | case Token::SAR: |
| 2071 | case Token::SHL: |
| 2072 | case Token::SHR: { |
| 2073 | GenerateRegisterArgsPush(masm); |
| 2074 | Label not_floats; |
| 2075 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2076 | // We do not check the input arguments here, as any value is |
| 2077 | // unconditionally truncated to an int32 anyway. To get the |
| 2078 | // right optimized code, int32 type feedback is just right. |
| 2079 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2080 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2081 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2082 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2083 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2084 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2085 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2086 | case Token::SAR: __ sar_cl(eax); break; |
| 2087 | case Token::SHL: __ shl_cl(eax); break; |
| 2088 | case Token::SHR: __ shr_cl(eax); break; |
| 2089 | default: UNREACHABLE(); |
| 2090 | } |
| 2091 | if (op_ == Token::SHR) { |
| 2092 | // Check if result is non-negative and fits in a smi. |
| 2093 | __ test(eax, Immediate(0xc0000000)); |
| 2094 | __ j(not_zero, &call_runtime); |
| 2095 | } else { |
| 2096 | // Check if result fits in a smi. |
| 2097 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2098 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2099 | } |
| 2100 | // Tag smi result and return. |
| 2101 | __ SmiTag(eax); |
| 2102 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2103 | |
| 2104 | // All ops except SHR return a signed int32 that we load in |
| 2105 | // a HeapNumber. |
| 2106 | if (op_ != Token::SHR) { |
| 2107 | __ bind(&non_smi_result); |
| 2108 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2109 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2110 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2111 | switch (mode_) { |
| 2112 | case OVERWRITE_LEFT: |
| 2113 | case OVERWRITE_RIGHT: |
| 2114 | // If the operand was an object, we skip the |
| 2115 | // allocation of a heap number. |
| 2116 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2117 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2118 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2119 | // Fall through! |
| 2120 | case NO_OVERWRITE: |
| 2121 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2122 | __ bind(&skip_allocation); |
| 2123 | break; |
| 2124 | default: UNREACHABLE(); |
| 2125 | } |
| 2126 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2127 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2128 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2129 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2130 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2131 | } else { |
| 2132 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2133 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2134 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2135 | } |
| 2136 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2137 | } |
| 2138 | |
| 2139 | __ bind(¬_floats); |
| 2140 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2141 | break; |
| 2142 | } |
| 2143 | default: UNREACHABLE(); break; |
| 2144 | } |
| 2145 | |
| 2146 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2147 | // use the runtime system to get the correct result. |
| 2148 | __ bind(&call_runtime); |
| 2149 | |
| 2150 | switch (op_) { |
| 2151 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2152 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2154 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2155 | case Token::MOD: |
| 2156 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2160 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2161 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2162 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2163 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2164 | break; |
| 2165 | default: |
| 2166 | UNREACHABLE(); |
| 2167 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2168 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2172 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2173 | Label call_runtime; |
| 2174 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2175 | Counters* counters = masm->isolate()->counters(); |
| 2176 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2177 | |
| 2178 | switch (op_) { |
| 2179 | case Token::ADD: |
| 2180 | case Token::SUB: |
| 2181 | case Token::MUL: |
| 2182 | case Token::DIV: |
| 2183 | break; |
| 2184 | case Token::MOD: |
| 2185 | case Token::BIT_OR: |
| 2186 | case Token::BIT_AND: |
| 2187 | case Token::BIT_XOR: |
| 2188 | case Token::SAR: |
| 2189 | case Token::SHL: |
| 2190 | case Token::SHR: |
| 2191 | GenerateRegisterArgsPush(masm); |
| 2192 | break; |
| 2193 | default: |
| 2194 | UNREACHABLE(); |
| 2195 | } |
| 2196 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2197 | BinaryOpStub_GenerateSmiCode( |
| 2198 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Floating point case. |
| 2201 | switch (op_) { |
| 2202 | case Token::ADD: |
| 2203 | case Token::SUB: |
| 2204 | case Token::MUL: |
| 2205 | case Token::DIV: { |
| 2206 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2207 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2208 | CpuFeatures::Scope use_sse2(SSE2); |
| 2209 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2210 | |
| 2211 | switch (op_) { |
| 2212 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2213 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2214 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2215 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2216 | default: UNREACHABLE(); |
| 2217 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2218 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2219 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2220 | __ ret(0); |
| 2221 | } else { // SSE2 not available, use FPU. |
| 2222 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2223 | FloatingPointHelper::LoadFloatOperands( |
| 2224 | masm, |
| 2225 | ecx, |
| 2226 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2227 | switch (op_) { |
| 2228 | case Token::ADD: __ faddp(1); break; |
| 2229 | case Token::SUB: __ fsubp(1); break; |
| 2230 | case Token::MUL: __ fmulp(1); break; |
| 2231 | case Token::DIV: __ fdivp(1); break; |
| 2232 | default: UNREACHABLE(); |
| 2233 | } |
| 2234 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2235 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2236 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2237 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2238 | __ ret(0); |
| 2239 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2240 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2241 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2242 | } |
| 2243 | __ bind(¬_floats); |
| 2244 | break; |
| 2245 | } |
| 2246 | case Token::MOD: { |
| 2247 | // For MOD we go directly to runtime in the non-smi case. |
| 2248 | break; |
| 2249 | } |
| 2250 | case Token::BIT_OR: |
| 2251 | case Token::BIT_AND: |
| 2252 | case Token::BIT_XOR: |
| 2253 | case Token::SAR: |
| 2254 | case Token::SHL: |
| 2255 | case Token::SHR: { |
| 2256 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2257 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2258 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2259 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2260 | BinaryOpIC::GENERIC, |
| 2261 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2262 | &call_runtime); |
| 2263 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2264 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2265 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2266 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2267 | case Token::SAR: __ sar_cl(eax); break; |
| 2268 | case Token::SHL: __ shl_cl(eax); break; |
| 2269 | case Token::SHR: __ shr_cl(eax); break; |
| 2270 | default: UNREACHABLE(); |
| 2271 | } |
| 2272 | if (op_ == Token::SHR) { |
| 2273 | // Check if result is non-negative and fits in a smi. |
| 2274 | __ test(eax, Immediate(0xc0000000)); |
| 2275 | __ j(not_zero, &call_runtime); |
| 2276 | } else { |
| 2277 | // Check if result fits in a smi. |
| 2278 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2279 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | } |
| 2281 | // Tag smi result and return. |
| 2282 | __ SmiTag(eax); |
| 2283 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2284 | |
| 2285 | // All ops except SHR return a signed int32 that we load in |
| 2286 | // a HeapNumber. |
| 2287 | if (op_ != Token::SHR) { |
| 2288 | __ bind(&non_smi_result); |
| 2289 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2290 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2291 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | switch (mode_) { |
| 2293 | case OVERWRITE_LEFT: |
| 2294 | case OVERWRITE_RIGHT: |
| 2295 | // If the operand was an object, we skip the |
| 2296 | // allocation of a heap number. |
| 2297 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2298 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2299 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2300 | // Fall through! |
| 2301 | case NO_OVERWRITE: |
| 2302 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2303 | __ bind(&skip_allocation); |
| 2304 | break; |
| 2305 | default: UNREACHABLE(); |
| 2306 | } |
| 2307 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2308 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2309 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2310 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2311 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2312 | } else { |
| 2313 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2314 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2315 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2316 | } |
| 2317 | __ ret(2 * kPointerSize); |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
| 2321 | default: UNREACHABLE(); break; |
| 2322 | } |
| 2323 | |
| 2324 | // If all else fails, use the runtime system to get the correct |
| 2325 | // result. |
| 2326 | __ bind(&call_runtime); |
| 2327 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2328 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2329 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2330 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2331 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2333 | case Token::DIV: |
| 2334 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | break; |
| 2336 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2337 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2338 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2339 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2340 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2341 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2342 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2343 | break; |
| 2344 | default: |
| 2345 | UNREACHABLE(); |
| 2346 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2347 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2351 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2352 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2353 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2354 | |
| 2355 | // Registers containing left and right operands respectively. |
| 2356 | Register left = edx; |
| 2357 | Register right = eax; |
| 2358 | |
| 2359 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2360 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2361 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2362 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2363 | |
| 2364 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2365 | GenerateRegisterArgsPush(masm); |
| 2366 | __ TailCallStub(&string_add_left_stub); |
| 2367 | |
| 2368 | // Left operand is not a string, test right. |
| 2369 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2370 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2371 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2372 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2373 | |
| 2374 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2375 | GenerateRegisterArgsPush(masm); |
| 2376 | __ TailCallStub(&string_add_right_stub); |
| 2377 | |
| 2378 | // Neither argument is a string. |
| 2379 | __ bind(&call_runtime); |
| 2380 | } |
| 2381 | |
| 2382 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2383 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2384 | Label* alloc_failure, |
| 2385 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2386 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2387 | switch (mode) { |
| 2388 | case OVERWRITE_LEFT: { |
| 2389 | // If the argument in edx is already an object, we skip the |
| 2390 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2391 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2392 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2393 | // for the possible runtime call. |
| 2394 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2395 | // Now edx can be overwritten losing one of the arguments as we are |
| 2396 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2397 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2398 | __ bind(&skip_allocation); |
| 2399 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2400 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | case OVERWRITE_RIGHT: |
| 2404 | // If the argument in eax is already an object, we skip the |
| 2405 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2406 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2407 | // Fall through! |
| 2408 | case NO_OVERWRITE: |
| 2409 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2410 | // for the possible runtime call. |
| 2411 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2412 | // Now eax can be overwritten losing one of the arguments as we are |
| 2413 | // now done and will not need it any more. |
| 2414 | __ mov(eax, ebx); |
| 2415 | __ bind(&skip_allocation); |
| 2416 | break; |
| 2417 | default: UNREACHABLE(); |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2422 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2423 | __ pop(ecx); |
| 2424 | __ push(edx); |
| 2425 | __ push(eax); |
| 2426 | __ push(ecx); |
| 2427 | } |
| 2428 | |
| 2429 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2430 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2431 | // TAGGED case: |
| 2432 | // Input: |
| 2433 | // esp[4]: tagged number input argument (should be number). |
| 2434 | // esp[0]: return address. |
| 2435 | // Output: |
| 2436 | // eax: tagged double result. |
| 2437 | // UNTAGGED case: |
| 2438 | // Input:: |
| 2439 | // esp[0]: return address. |
| 2440 | // xmm1: untagged double input argument |
| 2441 | // Output: |
| 2442 | // xmm1: untagged double result. |
| 2443 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2444 | Label runtime_call; |
| 2445 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2446 | Label skip_cache; |
| 2447 | const bool tagged = (argument_type_ == TAGGED); |
| 2448 | if (tagged) { |
| 2449 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2450 | Label input_not_smi; |
| 2451 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2452 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2453 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2454 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2455 | // Then load the low and high words of the double into ebx, edx. |
| 2456 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2457 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2458 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2459 | __ mov(Operand(esp, 0), eax); |
| 2460 | __ fild_s(Operand(esp, 0)); |
| 2461 | __ fst_d(Operand(esp, 0)); |
| 2462 | __ pop(edx); |
| 2463 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2464 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2465 | __ bind(&input_not_smi); |
| 2466 | // Check if input is a HeapNumber. |
| 2467 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2468 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2469 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2470 | __ j(not_equal, &runtime_call); |
| 2471 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2472 | // low and high words into ebx, edx. |
| 2473 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2474 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2475 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2476 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2477 | __ bind(&loaded); |
| 2478 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2479 | CpuFeatures::Scope scope(SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2480 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2481 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2482 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2483 | } else { |
| 2484 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2485 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2486 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2487 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2491 | // ebx = low 32 bits of double value |
| 2492 | // edx = high 32 bits of double value |
| 2493 | // Compute hash (the shifts are arithmetic): |
| 2494 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2495 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2497 | __ mov(eax, ecx); |
| 2498 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2499 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2500 | __ mov(eax, ecx); |
| 2501 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2502 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2503 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2504 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2505 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2506 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2507 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2508 | // ebx = low 32 bits of double value. |
| 2509 | // edx = high 32 bits of double value. |
| 2510 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2511 | ExternalReference cache_array = |
| 2512 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2513 | __ mov(eax, Immediate(cache_array)); |
| 2514 | int cache_array_index = |
| 2515 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2516 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2517 | // Eax points to the cache for the type type_. |
| 2518 | // 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] | 2519 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2520 | __ j(zero, &runtime_call_clear_stack); |
| 2521 | #ifdef DEBUG |
| 2522 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2523 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2524 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2525 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2526 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2527 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2528 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2529 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2530 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2531 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2532 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2533 | } |
| 2534 | #endif |
| 2535 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2536 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2537 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2538 | // 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] | 2539 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2540 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2541 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2542 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2543 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2544 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2545 | Counters* counters = masm->isolate()->counters(); |
| 2546 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2547 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2548 | if (tagged) { |
| 2549 | __ fstp(0); |
| 2550 | __ ret(kPointerSize); |
| 2551 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2552 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2553 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2554 | __ Ret(); |
| 2555 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2556 | |
| 2557 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2558 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2559 | // Update cache with new value. |
| 2560 | // We are short on registers, so use no_reg as scratch. |
| 2561 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2562 | if (tagged) { |
| 2563 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2564 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2565 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2566 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2567 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2568 | __ movdbl(Operand(esp, 0), xmm1); |
| 2569 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2570 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2571 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2572 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2573 | __ mov(Operand(ecx, 0), ebx); |
| 2574 | __ mov(Operand(ecx, kIntSize), edx); |
| 2575 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2576 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2577 | if (tagged) { |
| 2578 | __ ret(kPointerSize); |
| 2579 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2580 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2581 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2582 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2583 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2584 | // Skip cache and return answer directly, only in untagged case. |
| 2585 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2586 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2587 | __ movdbl(Operand(esp, 0), xmm1); |
| 2588 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2589 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2590 | __ fstp_d(Operand(esp, 0)); |
| 2591 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2592 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2593 | // We return the value in xmm1 without adding it to the cache, but |
| 2594 | // 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] | 2595 | { |
| 2596 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2597 | // Allocate an unused object bigger than a HeapNumber. |
| 2598 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2599 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2600 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2601 | __ Ret(); |
| 2602 | } |
| 2603 | |
| 2604 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2605 | if (tagged) { |
| 2606 | __ bind(&runtime_call_clear_stack); |
| 2607 | __ fstp(0); |
| 2608 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2609 | ExternalReference runtime = |
| 2610 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2611 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2612 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2613 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2614 | __ bind(&runtime_call_clear_stack); |
| 2615 | __ bind(&runtime_call); |
| 2616 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2617 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2618 | { |
| 2619 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2620 | __ push(eax); |
| 2621 | __ CallRuntime(RuntimeFunction(), 1); |
| 2622 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2623 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2624 | __ Ret(); |
| 2625 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | |
| 2629 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2630 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2631 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2632 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2633 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2634 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2635 | default: |
| 2636 | UNIMPLEMENTED(); |
| 2637 | return Runtime::kAbort; |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2642 | void TranscendentalCacheStub::GenerateOperation( |
| 2643 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2644 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2645 | // Input value is on FP stack, and also in ebx/edx. |
| 2646 | // Input value is possibly in xmm1. |
| 2647 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2648 | if (type == TranscendentalCache::SIN || |
| 2649 | type == TranscendentalCache::COS || |
| 2650 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2651 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2652 | // return NaN for infinities and NaN. They can share all code except |
| 2653 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2654 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2655 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2656 | // work. We must reduce it to the appropriate range. |
| 2657 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2658 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2659 | int supported_exponent_limit = |
| 2660 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2661 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2662 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2663 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2664 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2665 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2666 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2667 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2668 | __ fstp(0); |
| 2669 | // NaN is represented by 0x7ff8000000000000. |
| 2670 | __ push(Immediate(0x7ff80000)); |
| 2671 | __ push(Immediate(0)); |
| 2672 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2673 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2674 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2675 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2676 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2677 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2678 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2679 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2680 | __ fldpi(); |
| 2681 | __ fadd(0); |
| 2682 | __ fld(1); |
| 2683 | // FPU Stack: input, 2*pi, input. |
| 2684 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2685 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2686 | __ fwait(); |
| 2687 | __ fnstsw_ax(); |
| 2688 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2689 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2690 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2691 | __ fnclex(); |
| 2692 | __ bind(&no_exceptions); |
| 2693 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2694 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2695 | // Compute st(0) % st(1) |
| 2696 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2697 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2698 | __ bind(&partial_remainder_loop); |
| 2699 | __ fprem1(); |
| 2700 | __ fwait(); |
| 2701 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2702 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2703 | // If C2 is set, computation only has partial result. Loop to |
| 2704 | // continue computation. |
| 2705 | __ j(not_zero, &partial_remainder_loop); |
| 2706 | } |
| 2707 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2708 | __ fstp(2); |
| 2709 | __ fstp(0); |
| 2710 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2711 | |
| 2712 | // FPU Stack: input % 2*pi |
| 2713 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2714 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2715 | case TranscendentalCache::SIN: |
| 2716 | __ fsin(); |
| 2717 | break; |
| 2718 | case TranscendentalCache::COS: |
| 2719 | __ fcos(); |
| 2720 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2721 | case TranscendentalCache::TAN: |
| 2722 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2723 | // FP register stack. |
| 2724 | __ fptan(); |
| 2725 | __ fstp(0); // Pop FP register stack. |
| 2726 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2727 | default: |
| 2728 | UNREACHABLE(); |
| 2729 | } |
| 2730 | __ bind(&done); |
| 2731 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2732 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2733 | __ fldln2(); |
| 2734 | __ fxch(); |
| 2735 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2736 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2740 | // Input: edx, eax are the left and right objects of a bit op. |
| 2741 | // 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] | 2742 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2743 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2744 | MacroAssembler* masm, |
| 2745 | bool use_sse3, |
| 2746 | BinaryOpIC::TypeInfo left_type, |
| 2747 | BinaryOpIC::TypeInfo right_type, |
| 2748 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2749 | // Check float operands. |
| 2750 | Label arg1_is_object, check_undefined_arg1; |
| 2751 | Label arg2_is_object, check_undefined_arg2; |
| 2752 | Label load_arg2, done; |
| 2753 | |
| 2754 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2755 | if (left_type == BinaryOpIC::SMI) { |
| 2756 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2757 | } else { |
| 2758 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2759 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2760 | |
| 2761 | __ SmiUntag(edx); |
| 2762 | __ jmp(&load_arg2); |
| 2763 | |
| 2764 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2765 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2766 | Factory* factory = masm->isolate()->factory(); |
| 2767 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2768 | __ j(not_equal, conversion_failure); |
| 2769 | __ mov(edx, Immediate(0)); |
| 2770 | __ jmp(&load_arg2); |
| 2771 | |
| 2772 | __ bind(&arg1_is_object); |
| 2773 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2774 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2775 | __ j(not_equal, &check_undefined_arg1); |
| 2776 | |
| 2777 | // 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] | 2778 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2779 | CpuFeatures::Scope use_sse2(SSE2); |
| 2780 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2781 | } else { |
| 2782 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2783 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2784 | __ mov(edx, ecx); |
| 2785 | |
| 2786 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2787 | __ bind(&load_arg2); |
| 2788 | |
| 2789 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2790 | if (right_type == BinaryOpIC::SMI) { |
| 2791 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2792 | } else { |
| 2793 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2794 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2795 | |
| 2796 | __ SmiUntag(eax); |
| 2797 | __ mov(ecx, eax); |
| 2798 | __ jmp(&done); |
| 2799 | |
| 2800 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2801 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2802 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2803 | __ j(not_equal, conversion_failure); |
| 2804 | __ mov(ecx, Immediate(0)); |
| 2805 | __ jmp(&done); |
| 2806 | |
| 2807 | __ bind(&arg2_is_object); |
| 2808 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2809 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2810 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2811 | // 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] | 2812 | |
| 2813 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2814 | CpuFeatures::Scope use_sse2(SSE2); |
| 2815 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2816 | } else { |
| 2817 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2818 | } |
| 2819 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2820 | __ bind(&done); |
| 2821 | __ mov(eax, edx); |
| 2822 | } |
| 2823 | |
| 2824 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2825 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2826 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2827 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2828 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2829 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2830 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2831 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2832 | |
| 2833 | __ bind(&load_smi); |
| 2834 | __ SmiUntag(number); |
| 2835 | __ push(number); |
| 2836 | __ fild_s(Operand(esp, 0)); |
| 2837 | __ pop(number); |
| 2838 | |
| 2839 | __ bind(&done); |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2844 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2845 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2846 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2847 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2848 | |
| 2849 | __ bind(&load_eax); |
| 2850 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2851 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2852 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2853 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2854 | |
| 2855 | __ bind(&load_smi_edx); |
| 2856 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2857 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2859 | __ jmp(&load_eax); |
| 2860 | |
| 2861 | __ bind(&load_smi_eax); |
| 2862 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2863 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2864 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2865 | |
| 2866 | __ bind(&done); |
| 2867 | } |
| 2868 | |
| 2869 | |
| 2870 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2871 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2872 | 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] | 2873 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2874 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2875 | Factory* factory = masm->isolate()->factory(); |
| 2876 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2877 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2878 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2879 | __ bind(&load_eax); |
| 2880 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2881 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2882 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2883 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2884 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2885 | __ bind(&load_smi_edx); |
| 2886 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2887 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2888 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2889 | __ jmp(&load_eax); |
| 2890 | __ bind(&load_smi_eax); |
| 2891 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2892 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2893 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2894 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2895 | __ bind(&load_float_eax); |
| 2896 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2897 | __ bind(&done); |
| 2898 | } |
| 2899 | |
| 2900 | |
| 2901 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2902 | Register scratch) { |
| 2903 | const Register left = edx; |
| 2904 | const Register right = eax; |
| 2905 | __ mov(scratch, left); |
| 2906 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2907 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2908 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2909 | |
| 2910 | __ mov(scratch, right); |
| 2911 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2912 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2916 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2917 | Label* non_int32, |
| 2918 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2919 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2920 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2925 | Label* non_int32, |
| 2926 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2927 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2928 | Register scratch, |
| 2929 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2930 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2931 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2932 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2933 | __ movmskps(scratch, xmm_scratch); |
| 2934 | // Two least significant bits should be both set. |
| 2935 | __ not_(scratch); |
| 2936 | __ test(scratch, Immediate(3)); |
| 2937 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2941 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2942 | Register scratch, |
| 2943 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2944 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2945 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2946 | __ mov(scratch, edx); |
| 2947 | } else { |
| 2948 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2949 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2950 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2951 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2952 | __ bind(&done_load_1); |
| 2953 | |
| 2954 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2955 | __ mov(scratch, eax); |
| 2956 | } else { |
| 2957 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2958 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2959 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2960 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2961 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2962 | |
| 2963 | __ bind(&load_smi_1); |
| 2964 | __ SmiUntag(scratch); |
| 2965 | __ push(scratch); |
| 2966 | __ fild_s(Operand(esp, 0)); |
| 2967 | __ pop(scratch); |
| 2968 | __ jmp(&done_load_1); |
| 2969 | |
| 2970 | __ bind(&load_smi_2); |
| 2971 | __ SmiUntag(scratch); |
| 2972 | __ push(scratch); |
| 2973 | __ fild_s(Operand(esp, 0)); |
| 2974 | __ pop(scratch); |
| 2975 | |
| 2976 | __ bind(&done); |
| 2977 | } |
| 2978 | |
| 2979 | |
| 2980 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2981 | Register scratch) { |
| 2982 | const Register left = edx; |
| 2983 | const Register right = eax; |
| 2984 | __ mov(scratch, left); |
| 2985 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2986 | __ SmiUntag(scratch); |
| 2987 | __ push(scratch); |
| 2988 | __ fild_s(Operand(esp, 0)); |
| 2989 | |
| 2990 | __ mov(scratch, right); |
| 2991 | __ SmiUntag(scratch); |
| 2992 | __ mov(Operand(esp, 0), scratch); |
| 2993 | __ fild_s(Operand(esp, 0)); |
| 2994 | __ pop(scratch); |
| 2995 | } |
| 2996 | |
| 2997 | |
| 2998 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2999 | Label* non_float, |
| 3000 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3001 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3002 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 3003 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3004 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3005 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3006 | Factory* factory = masm->isolate()->factory(); |
| 3007 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3008 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 3009 | |
| 3010 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3011 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3012 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3013 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3014 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 3015 | |
| 3016 | // Fall-through: Both operands are numbers. |
| 3017 | __ bind(&done); |
| 3018 | } |
| 3019 | |
| 3020 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3021 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3022 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3023 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3024 | const Register exponent = eax; |
| 3025 | const Register base = edx; |
| 3026 | const Register scratch = ecx; |
| 3027 | const XMMRegister double_result = xmm3; |
| 3028 | const XMMRegister double_base = xmm2; |
| 3029 | const XMMRegister double_exponent = xmm1; |
| 3030 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3031 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3032 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3033 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3034 | // Save 1 in double_result - we need this several times later on. |
| 3035 | __ mov(scratch, Immediate(1)); |
| 3036 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3037 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3038 | if (exponent_type_ == ON_STACK) { |
| 3039 | Label base_is_smi, unpack_exponent; |
| 3040 | // The exponent and base are supplied as arguments on the stack. |
| 3041 | // This can only happen if the stub is called from non-optimized code. |
| 3042 | // Load input parameters from stack. |
| 3043 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3044 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3045 | |
| 3046 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3047 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3048 | factory->heap_number_map()); |
| 3049 | __ j(not_equal, &call_runtime); |
| 3050 | |
| 3051 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3052 | __ jmp(&unpack_exponent, Label::kNear); |
| 3053 | |
| 3054 | __ bind(&base_is_smi); |
| 3055 | __ SmiUntag(base); |
| 3056 | __ cvtsi2sd(double_base, base); |
| 3057 | |
| 3058 | __ bind(&unpack_exponent); |
| 3059 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3060 | __ SmiUntag(exponent); |
| 3061 | __ jmp(&int_exponent); |
| 3062 | |
| 3063 | __ bind(&exponent_not_smi); |
| 3064 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3065 | factory->heap_number_map()); |
| 3066 | __ j(not_equal, &call_runtime); |
| 3067 | __ movdbl(double_exponent, |
| 3068 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3069 | } else if (exponent_type_ == TAGGED) { |
| 3070 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3071 | __ SmiUntag(exponent); |
| 3072 | __ jmp(&int_exponent); |
| 3073 | |
| 3074 | __ bind(&exponent_not_smi); |
| 3075 | __ movdbl(double_exponent, |
| 3076 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3077 | } |
| 3078 | |
| 3079 | if (exponent_type_ != INTEGER) { |
| 3080 | Label fast_power; |
| 3081 | // Detect integer exponents stored as double. |
| 3082 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3083 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3084 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3085 | __ j(equal, &call_runtime); |
| 3086 | __ cvtsi2sd(double_scratch, exponent); |
| 3087 | // Already ruled out NaNs for exponent. |
| 3088 | __ ucomisd(double_exponent, double_scratch); |
| 3089 | __ j(equal, &int_exponent); |
| 3090 | |
| 3091 | if (exponent_type_ == ON_STACK) { |
| 3092 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3093 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3094 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3095 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3096 | // Test for 0.5. |
| 3097 | // Load double_scratch with 0.5. |
| 3098 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3099 | __ movd(double_scratch, scratch); |
| 3100 | __ cvtss2sd(double_scratch, double_scratch); |
| 3101 | // Already ruled out NaNs for exponent. |
| 3102 | __ ucomisd(double_scratch, double_exponent); |
| 3103 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3104 | |
| 3105 | // Calculates square root of base. Check for the special case of |
| 3106 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3107 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3108 | // 9 bits set and the lowest 23 bits cleared. |
| 3109 | __ mov(scratch, 0xFF800000u); |
| 3110 | __ movd(double_scratch, scratch); |
| 3111 | __ cvtss2sd(double_scratch, double_scratch); |
| 3112 | __ ucomisd(double_base, double_scratch); |
| 3113 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3114 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3115 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3116 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3117 | |
| 3118 | // Set result to Infinity in the special case. |
| 3119 | __ xorps(double_result, double_result); |
| 3120 | __ subsd(double_result, double_scratch); |
| 3121 | __ jmp(&done); |
| 3122 | |
| 3123 | __ bind(&continue_sqrt); |
| 3124 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3125 | __ xorps(double_scratch, double_scratch); |
| 3126 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3127 | __ sqrtsd(double_result, double_scratch); |
| 3128 | __ jmp(&done); |
| 3129 | |
| 3130 | // Test for -0.5. |
| 3131 | __ bind(¬_plus_half); |
| 3132 | // Load double_exponent with -0.5 by substracting 1. |
| 3133 | __ subsd(double_scratch, double_result); |
| 3134 | // Already ruled out NaNs for exponent. |
| 3135 | __ ucomisd(double_scratch, double_exponent); |
| 3136 | __ j(not_equal, &fast_power, Label::kNear); |
| 3137 | |
| 3138 | // Calculates reciprocal of square root of base. Check for the special |
| 3139 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3140 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3141 | // 9 bits set and the lowest 23 bits cleared. |
| 3142 | __ mov(scratch, 0xFF800000u); |
| 3143 | __ movd(double_scratch, scratch); |
| 3144 | __ cvtss2sd(double_scratch, double_scratch); |
| 3145 | __ ucomisd(double_base, double_scratch); |
| 3146 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3147 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3148 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3149 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3150 | |
| 3151 | // Set result to 0 in the special case. |
| 3152 | __ xorps(double_result, double_result); |
| 3153 | __ jmp(&done); |
| 3154 | |
| 3155 | __ bind(&continue_rsqrt); |
| 3156 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3157 | __ xorps(double_exponent, double_exponent); |
| 3158 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3159 | __ sqrtsd(double_exponent, double_exponent); |
| 3160 | __ divsd(double_result, double_exponent); |
| 3161 | __ jmp(&done); |
| 3162 | } |
| 3163 | |
| 3164 | // Using FPU instructions to calculate power. |
| 3165 | Label fast_power_failed; |
| 3166 | __ bind(&fast_power); |
| 3167 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3168 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3169 | __ sub(esp, Immediate(kDoubleSize)); |
| 3170 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3171 | __ fld_d(Operand(esp, 0)); // E |
| 3172 | __ movdbl(Operand(esp, 0), double_base); |
| 3173 | __ fld_d(Operand(esp, 0)); // B, E |
| 3174 | |
| 3175 | // Exponent is in st(1) and base is in st(0) |
| 3176 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3177 | // FYL2X calculates st(1) * log2(st(0)) |
| 3178 | __ fyl2x(); // X |
| 3179 | __ fld(0); // X, X |
| 3180 | __ frndint(); // rnd(X), X |
| 3181 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3182 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3183 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3184 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3185 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3186 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3187 | // FSCALE calculates st(0) * 2^st(1) |
| 3188 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3189 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3190 | // Bail out to runtime in case of exceptions in the status word. |
| 3191 | __ fnstsw_ax(); |
| 3192 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3193 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3194 | __ fstp_d(Operand(esp, 0)); |
| 3195 | __ movdbl(double_result, Operand(esp, 0)); |
| 3196 | __ add(esp, Immediate(kDoubleSize)); |
| 3197 | __ jmp(&done); |
| 3198 | |
| 3199 | __ bind(&fast_power_failed); |
| 3200 | __ fninit(); |
| 3201 | __ add(esp, Immediate(kDoubleSize)); |
| 3202 | __ jmp(&call_runtime); |
| 3203 | } |
| 3204 | |
| 3205 | // Calculate power with integer exponent. |
| 3206 | __ bind(&int_exponent); |
| 3207 | const XMMRegister double_scratch2 = double_exponent; |
| 3208 | __ mov(scratch, exponent); // Back up exponent. |
| 3209 | __ movsd(double_scratch, double_base); // Back up base. |
| 3210 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3211 | |
| 3212 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3213 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3214 | __ test(scratch, scratch); |
| 3215 | __ j(positive, &no_neg, Label::kNear); |
| 3216 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3217 | __ bind(&no_neg); |
| 3218 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3219 | __ j(zero, &while_false, Label::kNear); |
| 3220 | __ shr(scratch, 1); |
| 3221 | // Above condition means CF==0 && ZF==0. This means that the |
| 3222 | // bit that has been shifted out is 0 and the result is not 0. |
| 3223 | __ j(above, &while_true, Label::kNear); |
| 3224 | __ movsd(double_result, double_scratch); |
| 3225 | __ j(zero, &while_false, Label::kNear); |
| 3226 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3227 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3228 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3229 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3230 | __ j(above, &while_true, Label::kNear); |
| 3231 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3232 | __ j(not_zero, &while_true); |
| 3233 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3234 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3235 | // scratch has the original value of the exponent - if the exponent is |
| 3236 | // negative, return 1/result. |
| 3237 | __ test(exponent, exponent); |
| 3238 | __ j(positive, &done); |
| 3239 | __ divsd(double_scratch2, double_result); |
| 3240 | __ movsd(double_result, double_scratch2); |
| 3241 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3242 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3243 | __ xorps(double_scratch2, double_scratch2); |
| 3244 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3245 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3246 | // and may not have contained the exponent value in the first place when the |
| 3247 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3248 | __ j(not_equal, &done); |
| 3249 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3250 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3251 | // Returning or bailing out. |
| 3252 | Counters* counters = masm->isolate()->counters(); |
| 3253 | if (exponent_type_ == ON_STACK) { |
| 3254 | // The arguments are still on the stack. |
| 3255 | __ bind(&call_runtime); |
| 3256 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3257 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3258 | // The stub is called from non-optimized code, which expects the result |
| 3259 | // as heap number in exponent. |
| 3260 | __ bind(&done); |
| 3261 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3262 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3263 | __ IncrementCounter(counters->math_pow(), 1); |
| 3264 | __ ret(2 * kPointerSize); |
| 3265 | } else { |
| 3266 | __ bind(&call_runtime); |
| 3267 | { |
| 3268 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3269 | __ PrepareCallCFunction(4, scratch); |
| 3270 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3271 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3272 | __ CallCFunction( |
| 3273 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3274 | } |
| 3275 | // Return value is in st(0) on ia32. |
| 3276 | // Store it into the (fixed) result register. |
| 3277 | __ sub(esp, Immediate(kDoubleSize)); |
| 3278 | __ fstp_d(Operand(esp, 0)); |
| 3279 | __ movdbl(double_result, Operand(esp, 0)); |
| 3280 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3281 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3282 | __ bind(&done); |
| 3283 | __ IncrementCounter(counters->math_pow(), 1); |
| 3284 | __ ret(0); |
| 3285 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3289 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3290 | // ----------- S t a t e ------------- |
| 3291 | // -- ecx : name |
| 3292 | // -- edx : receiver |
| 3293 | // -- esp[0] : return address |
| 3294 | // ----------------------------------- |
| 3295 | Label miss; |
| 3296 | |
| 3297 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3298 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3299 | __ j(not_equal, &miss); |
| 3300 | } |
| 3301 | |
| 3302 | StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss); |
| 3303 | __ bind(&miss); |
| 3304 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3305 | } |
| 3306 | |
| 3307 | |
| 3308 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3309 | // ----------- S t a t e ------------- |
| 3310 | // -- ecx : name |
| 3311 | // -- edx : receiver |
| 3312 | // -- esp[0] : return address |
| 3313 | // ----------------------------------- |
| 3314 | Label miss; |
| 3315 | |
| 3316 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3317 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3318 | __ j(not_equal, &miss); |
| 3319 | } |
| 3320 | |
| 3321 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3322 | __ bind(&miss); |
| 3323 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3328 | // ----------- S t a t e ------------- |
| 3329 | // -- ecx : name |
| 3330 | // -- edx : receiver |
| 3331 | // -- esp[0] : return address |
| 3332 | // ----------------------------------- |
| 3333 | Label miss; |
| 3334 | |
| 3335 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3336 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3337 | __ j(not_equal, &miss); |
| 3338 | } |
| 3339 | |
| 3340 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3341 | support_wrapper_); |
| 3342 | __ bind(&miss); |
| 3343 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3344 | } |
| 3345 | |
| 3346 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3347 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3348 | // ----------- S t a t e ------------- |
| 3349 | // -- eax : value |
| 3350 | // -- ecx : name |
| 3351 | // -- edx : receiver |
| 3352 | // -- esp[0] : return address |
| 3353 | // ----------------------------------- |
| 3354 | // |
| 3355 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3356 | // (currently anything except for external arrays which means anything with |
| 3357 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3358 | // accepted as the most common case. |
| 3359 | |
| 3360 | Label miss; |
| 3361 | |
| 3362 | Register receiver = edx; |
| 3363 | Register value = eax; |
| 3364 | Register scratch = ebx; |
| 3365 | |
| 3366 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3367 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3368 | __ j(not_equal, &miss); |
| 3369 | } |
| 3370 | |
| 3371 | // Check that the receiver isn't a smi. |
| 3372 | __ JumpIfSmi(receiver, &miss); |
| 3373 | |
| 3374 | // Check that the object is a JS array. |
| 3375 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3376 | __ j(not_equal, &miss); |
| 3377 | |
| 3378 | // Check that elements are FixedArray. |
| 3379 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3380 | // fast elements (including COW). |
| 3381 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3382 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3383 | __ j(not_equal, &miss); |
| 3384 | |
| 3385 | // Check that the array has fast properties, otherwise the length |
| 3386 | // property might have been redefined. |
| 3387 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3388 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3389 | Heap::kHashTableMapRootIndex); |
| 3390 | __ j(equal, &miss); |
| 3391 | |
| 3392 | // Check that value is a smi. |
| 3393 | __ JumpIfNotSmi(value, &miss); |
| 3394 | |
| 3395 | // Prepare tail call to StoreIC_ArrayLength. |
| 3396 | __ pop(scratch); |
| 3397 | __ push(receiver); |
| 3398 | __ push(value); |
| 3399 | __ push(scratch); // return address |
| 3400 | |
| 3401 | ExternalReference ref = |
| 3402 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3403 | __ TailCallExternalReference(ref, 2, 1); |
| 3404 | |
| 3405 | __ bind(&miss); |
| 3406 | |
| 3407 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 3408 | } |
| 3409 | |
| 3410 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3411 | void LoadFieldStub::Generate(MacroAssembler* masm) { |
| 3412 | StubCompiler::DoGenerateFastPropertyLoad(masm, eax, reg_, inobject_, index_); |
| 3413 | __ ret(0); |
| 3414 | } |
| 3415 | |
| 3416 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3417 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3418 | // The key is in edx and the parameter count is in eax. |
| 3419 | |
| 3420 | // The displacement is used for skipping the frame pointer on the |
| 3421 | // stack. It is the offset of the last parameter (if any) relative |
| 3422 | // to the frame pointer. |
| 3423 | static const int kDisplacement = 1 * kPointerSize; |
| 3424 | |
| 3425 | // Check that the key is a smi. |
| 3426 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3427 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3428 | |
| 3429 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3430 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3431 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3432 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3433 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3434 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3435 | |
| 3436 | // Check index against formal parameters count limit passed in |
| 3437 | // through register eax. Use unsigned comparison to get negative |
| 3438 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3439 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3440 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3441 | |
| 3442 | // Read the argument from the stack and return it. |
| 3443 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3444 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3445 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3446 | __ neg(edx); |
| 3447 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3448 | __ ret(0); |
| 3449 | |
| 3450 | // Arguments adaptor case: Check index against actual arguments |
| 3451 | // limit found in the arguments adaptor frame. Use unsigned |
| 3452 | // comparison to get negative check for free. |
| 3453 | __ bind(&adaptor); |
| 3454 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3455 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3456 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3457 | |
| 3458 | // Read the argument from the stack and return it. |
| 3459 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3460 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3461 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3462 | __ neg(edx); |
| 3463 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3464 | __ ret(0); |
| 3465 | |
| 3466 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3467 | // by calling the runtime system. |
| 3468 | __ bind(&slow); |
| 3469 | __ pop(ebx); // Return address. |
| 3470 | __ push(edx); |
| 3471 | __ push(ebx); |
| 3472 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3473 | } |
| 3474 | |
| 3475 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3476 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3477 | // esp[0] : return address |
| 3478 | // esp[4] : number of parameters |
| 3479 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3480 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3481 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3482 | // Check if the calling frame is an arguments adaptor frame. |
| 3483 | Label runtime; |
| 3484 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3485 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3486 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3487 | __ j(not_equal, &runtime, Label::kNear); |
| 3488 | |
| 3489 | // Patch the arguments.length and the parameters pointer. |
| 3490 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3491 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3492 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3493 | StandardFrameConstants::kCallerSPOffset)); |
| 3494 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3495 | |
| 3496 | __ bind(&runtime); |
| 3497 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3498 | } |
| 3499 | |
| 3500 | |
| 3501 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3502 | // esp[0] : return address |
| 3503 | // esp[4] : number of parameters (tagged) |
| 3504 | // esp[8] : receiver displacement |
| 3505 | // esp[12] : function |
| 3506 | |
| 3507 | // ebx = parameter count (tagged) |
| 3508 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3509 | |
| 3510 | // Check if the calling frame is an arguments adaptor frame. |
| 3511 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3512 | // Generate* functions. |
| 3513 | Label runtime; |
| 3514 | Label adaptor_frame, try_allocate; |
| 3515 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3516 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3517 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3518 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3519 | |
| 3520 | // No adaptor, parameter count = argument count. |
| 3521 | __ mov(ecx, ebx); |
| 3522 | __ jmp(&try_allocate, Label::kNear); |
| 3523 | |
| 3524 | // We have an adaptor frame. Patch the parameters pointer. |
| 3525 | __ bind(&adaptor_frame); |
| 3526 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3527 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3528 | StandardFrameConstants::kCallerSPOffset)); |
| 3529 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3530 | |
| 3531 | // ebx = parameter count (tagged) |
| 3532 | // ecx = argument count (tagged) |
| 3533 | // esp[4] = parameter count (tagged) |
| 3534 | // esp[8] = address of receiver argument |
| 3535 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3536 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3537 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3538 | __ mov(ebx, ecx); |
| 3539 | |
| 3540 | __ bind(&try_allocate); |
| 3541 | |
| 3542 | // Save mapped parameter count. |
| 3543 | __ push(ebx); |
| 3544 | |
| 3545 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3546 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3547 | const int kParameterMapHeaderSize = |
| 3548 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3549 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3550 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3551 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3552 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3553 | __ bind(&no_parameter_map); |
| 3554 | |
| 3555 | // 2. Backing store. |
| 3556 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3557 | |
| 3558 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3559 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3560 | |
| 3561 | // Do the allocation of all three objects in one go. |
| 3562 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3563 | |
| 3564 | // eax = address of new object(s) (tagged) |
| 3565 | // ecx = argument count (tagged) |
| 3566 | // esp[0] = mapped parameter count (tagged) |
| 3567 | // esp[8] = parameter count (tagged) |
| 3568 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3569 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3570 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3571 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3572 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3573 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3574 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3575 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3576 | __ mov(edi, Operand(edi, |
| 3577 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3578 | __ jmp(©, Label::kNear); |
| 3579 | |
| 3580 | __ bind(&has_mapped_parameters); |
| 3581 | __ mov(edi, Operand(edi, |
| 3582 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3583 | __ bind(©); |
| 3584 | |
| 3585 | // eax = address of new object (tagged) |
| 3586 | // ebx = mapped parameter count (tagged) |
| 3587 | // ecx = argument count (tagged) |
| 3588 | // edi = address of boilerplate object (tagged) |
| 3589 | // esp[0] = mapped parameter count (tagged) |
| 3590 | // esp[8] = parameter count (tagged) |
| 3591 | // esp[12] = address of receiver argument |
| 3592 | // Copy the JS object part. |
| 3593 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3594 | __ mov(edx, FieldOperand(edi, i)); |
| 3595 | __ mov(FieldOperand(eax, i), edx); |
| 3596 | } |
| 3597 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3598 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3599 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3600 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3601 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3602 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3603 | edx); |
| 3604 | |
| 3605 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3606 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3607 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3608 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3609 | ecx); |
| 3610 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3611 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3612 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3613 | // backing store. |
| 3614 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3615 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3616 | |
| 3617 | // eax = address of new object (tagged) |
| 3618 | // ebx = mapped parameter count (tagged) |
| 3619 | // ecx = argument count (tagged) |
| 3620 | // edi = address of parameter map or backing store (tagged) |
| 3621 | // esp[0] = mapped parameter count (tagged) |
| 3622 | // esp[8] = parameter count (tagged) |
| 3623 | // esp[12] = address of receiver argument |
| 3624 | // Free a register. |
| 3625 | __ push(eax); |
| 3626 | |
| 3627 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3628 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3629 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3630 | __ j(zero, &skip_parameter_map); |
| 3631 | |
| 3632 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3633 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3634 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3635 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3636 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3637 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3638 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3639 | |
| 3640 | // Copy the parameter slots and the holes in the arguments. |
| 3641 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3642 | // where parameters are stored in reverse order, at |
| 3643 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3644 | // The mapped parameter thus need to get indices |
| 3645 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3646 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3647 | // We loop from right to left. |
| 3648 | Label parameters_loop, parameters_test; |
| 3649 | __ push(ecx); |
| 3650 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3651 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3652 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3653 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3654 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3655 | __ mov(edx, edi); |
| 3656 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3657 | // eax = loop variable (tagged) |
| 3658 | // ebx = mapping index (tagged) |
| 3659 | // ecx = the hole value |
| 3660 | // edx = address of parameter map (tagged) |
| 3661 | // edi = address of backing store (tagged) |
| 3662 | // esp[0] = argument count (tagged) |
| 3663 | // esp[4] = address of new object (tagged) |
| 3664 | // esp[8] = mapped parameter count (tagged) |
| 3665 | // esp[16] = parameter count (tagged) |
| 3666 | // esp[20] = address of receiver argument |
| 3667 | __ jmp(¶meters_test, Label::kNear); |
| 3668 | |
| 3669 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3670 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3671 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3672 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3673 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3674 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3675 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3676 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3677 | __ pop(ecx); |
| 3678 | |
| 3679 | __ bind(&skip_parameter_map); |
| 3680 | |
| 3681 | // ecx = argument count (tagged) |
| 3682 | // edi = address of backing store (tagged) |
| 3683 | // esp[0] = address of new object (tagged) |
| 3684 | // esp[4] = mapped parameter count (tagged) |
| 3685 | // esp[12] = parameter count (tagged) |
| 3686 | // esp[16] = address of receiver argument |
| 3687 | // Copy arguments header and remaining slots (if there are any). |
| 3688 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3689 | Immediate(FACTORY->fixed_array_map())); |
| 3690 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3691 | |
| 3692 | Label arguments_loop, arguments_test; |
| 3693 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3694 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3695 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3696 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3697 | __ jmp(&arguments_test, Label::kNear); |
| 3698 | |
| 3699 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3700 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3701 | __ mov(eax, Operand(edx, 0)); |
| 3702 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3703 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3704 | |
| 3705 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3706 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3707 | __ j(less, &arguments_loop, Label::kNear); |
| 3708 | |
| 3709 | // Restore. |
| 3710 | __ pop(eax); // Address of arguments object. |
| 3711 | __ pop(ebx); // Parameter count. |
| 3712 | |
| 3713 | // Return and remove the on-stack parameters. |
| 3714 | __ ret(3 * kPointerSize); |
| 3715 | |
| 3716 | // Do the runtime call to allocate the arguments object. |
| 3717 | __ bind(&runtime); |
| 3718 | __ pop(eax); // Remove saved parameter count. |
| 3719 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3720 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | |
| 3724 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3725 | // esp[0] : return address |
| 3726 | // esp[4] : number of parameters |
| 3727 | // esp[8] : receiver displacement |
| 3728 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3729 | |
| 3730 | // Check if the calling frame is an arguments adaptor frame. |
| 3731 | Label adaptor_frame, try_allocate, runtime; |
| 3732 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3733 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3734 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3735 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3736 | |
| 3737 | // Get the length from the frame. |
| 3738 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3739 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3740 | |
| 3741 | // Patch the arguments.length and the parameters pointer. |
| 3742 | __ bind(&adaptor_frame); |
| 3743 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3744 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3745 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3746 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3747 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3748 | |
| 3749 | // Try the new space allocation. Start out with computing the size of |
| 3750 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3751 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3752 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3753 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3754 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3755 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3756 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3757 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3758 | |
| 3759 | // Do the allocation of both objects in one go. |
| 3760 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3761 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3762 | // Get the arguments boilerplate from the current native context. |
| 3763 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3764 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3765 | const int offset = |
| 3766 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3767 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | |
| 3769 | // Copy the JS object part. |
| 3770 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3771 | __ mov(ebx, FieldOperand(edi, i)); |
| 3772 | __ mov(FieldOperand(eax, i), ebx); |
| 3773 | } |
| 3774 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3775 | // 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] | 3776 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3777 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3778 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3779 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3780 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3781 | |
| 3782 | // If there are no actual arguments, we're done. |
| 3783 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3784 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3785 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3786 | |
| 3787 | // Get the parameters pointer from the stack. |
| 3788 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3789 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3790 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3792 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3793 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3794 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3795 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3796 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3797 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3798 | // Untag the length for the loop below. |
| 3799 | __ SmiUntag(ecx); |
| 3800 | |
| 3801 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3802 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3803 | __ bind(&loop); |
| 3804 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3805 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3806 | __ add(edi, Immediate(kPointerSize)); |
| 3807 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3808 | __ dec(ecx); |
| 3809 | __ j(not_zero, &loop); |
| 3810 | |
| 3811 | // Return and remove the on-stack parameters. |
| 3812 | __ bind(&done); |
| 3813 | __ ret(3 * kPointerSize); |
| 3814 | |
| 3815 | // Do the runtime call to allocate the arguments object. |
| 3816 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3817 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | |
| 3821 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3822 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3823 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3824 | // at compilation. |
| 3825 | #ifdef V8_INTERPRETED_REGEXP |
| 3826 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3827 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3828 | |
| 3829 | // Stack frame on entry. |
| 3830 | // esp[0]: return address |
| 3831 | // esp[4]: last_match_info (expected JSArray) |
| 3832 | // esp[8]: previous index |
| 3833 | // esp[12]: subject string |
| 3834 | // esp[16]: JSRegExp object |
| 3835 | |
| 3836 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3837 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3838 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3839 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3840 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3841 | Label runtime; |
| 3842 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3843 | |
| 3844 | // Ensure that a RegExp stack is allocated. |
| 3845 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3846 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3847 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3849 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3850 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3851 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3852 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3853 | |
| 3854 | // Check that the first argument is a JSRegExp object. |
| 3855 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3856 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3857 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3858 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3859 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3860 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3861 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3862 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3863 | if (FLAG_debug_code) { |
| 3864 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3865 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3866 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3867 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3868 | } |
| 3869 | |
| 3870 | // ecx: RegExp data (FixedArray) |
| 3871 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3872 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3873 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3874 | __ j(not_equal, &runtime); |
| 3875 | |
| 3876 | // ecx: RegExp data (FixedArray) |
| 3877 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3878 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3879 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3880 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3881 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3882 | STATIC_ASSERT(kSmiTag == 0); |
| 3883 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3884 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3885 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3886 | __ j(above, &runtime); |
| 3887 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3888 | // Reset offset for possibly sliced string. |
| 3889 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3890 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3891 | __ JumpIfSmi(eax, &runtime); |
| 3892 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3893 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3894 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3895 | |
| 3896 | // eax: subject string |
| 3897 | // edx: subject string |
| 3898 | // ebx: subject string instance type |
| 3899 | // ecx: RegExp data (FixedArray) |
| 3900 | // Handle subject string according to its encoding and representation: |
| 3901 | // (1) Sequential two byte? If yes, go to (9). |
| 3902 | // (2) Sequential one byte? If yes, go to (6). |
| 3903 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3904 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3905 | // Otherwise bailout. |
| 3906 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3907 | // (5b) Is subject external? If yes, go to (8). |
| 3908 | // (6) One byte sequential. Load regexp code for one byte. |
| 3909 | // (E) Carry on. |
| 3910 | /// [...] |
| 3911 | |
| 3912 | // Deferred code at the end of the stub: |
| 3913 | // (7) Not a long external string? If yes, go to (10). |
| 3914 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3915 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3916 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3917 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3918 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3919 | |
| 3920 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3921 | external_string /* 8 */, check_underlying /* 5a */, |
| 3922 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3923 | not_long_external /* 10 */; |
| 3924 | |
| 3925 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3926 | __ and_(ebx, kIsNotStringMask | |
| 3927 | kStringRepresentationMask | |
| 3928 | kStringEncodingMask | |
| 3929 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3930 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3931 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3932 | |
| 3933 | // (2) Sequential one byte? If yes, go to (6). |
| 3934 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3935 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3936 | kStringRepresentationMask | |
| 3937 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3938 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3939 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3940 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3941 | // We check whether the subject string is a cons, since sequential strings |
| 3942 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3943 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3944 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3945 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3946 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3947 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3948 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3949 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3950 | // (4) Cons string. Check that it's flat. |
| 3951 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3952 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3953 | __ j(not_equal, &runtime); |
| 3954 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3955 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3956 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3957 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3958 | |
| 3959 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3960 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3961 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3962 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3963 | // (5b) Is subject external? If yes, go to (8). |
| 3964 | __ test_b(ebx, kStringRepresentationMask); |
| 3965 | // The underlying external string is never a short external string. |
| 3966 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3967 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3968 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3969 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3970 | // eax: sequential subject string (or look-alike, external string) |
| 3971 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3972 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3973 | // (6) One byte sequential. Load regexp code for one byte. |
| 3974 | __ bind(&seq_one_byte_string); |
| 3975 | // Load previous index and check range before edx is overwritten. We have |
| 3976 | // to use edx instead of eax here because it might have been only made to |
| 3977 | // look like a sequential string when it actually is an external string. |
| 3978 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3979 | __ JumpIfNotSmi(ebx, &runtime); |
| 3980 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3981 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3982 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3983 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3984 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3985 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3987 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3988 | // Check that the irregexp code has been generated for the actual string |
| 3989 | // 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] | 3990 | // a smi (code flushing support). |
| 3991 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3992 | |
| 3993 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3994 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3995 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3996 | // 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] | 3997 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3998 | Counters* counters = masm->isolate()->counters(); |
| 3999 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4000 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4001 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4002 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4003 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4004 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4005 | // Argument 9: Pass current isolate address. |
| 4006 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4007 | Immediate(ExternalReference::isolate_address())); |
| 4008 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4009 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 4010 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4011 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4012 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4013 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 4014 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4015 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 4016 | |
| 4017 | // Argument 6: Set the number of capture registers to zero to force global |
| 4018 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 4019 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | |
| 4021 | // Argument 5: static offsets vector buffer. |
| 4022 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4023 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 4024 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4025 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4026 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4027 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4028 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 4029 | |
| 4030 | // Argument 1: Original subject string. |
| 4031 | // The original subject is in the previous stack frame. Therefore we have to |
| 4032 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 4033 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 4034 | // and thereby moves up esp by one kPointerSize.) |
| 4035 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 4036 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 4037 | |
| 4038 | // esi: original subject string |
| 4039 | // eax: underlying subject string |
| 4040 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4041 | // 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] | 4042 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4043 | // Argument 4: End of string data |
| 4044 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4045 | // Prepare start and end index of the input. |
| 4046 | // Load the length from the original sliced string if that is the case. |
| 4047 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4048 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4049 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4050 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4051 | |
| 4052 | // ebx: start index of the input string |
| 4053 | // esi: end index of the input string |
| 4054 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4055 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4056 | __ j(zero, &setup_two_byte, Label::kNear); |
| 4057 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4058 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4059 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4060 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4061 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4062 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4063 | |
| 4064 | __ bind(&setup_two_byte); |
| 4065 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4066 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 4067 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4068 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 4069 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 4070 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 4071 | |
| 4072 | __ bind(&setup_rest); |
| 4073 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4074 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4075 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 4076 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4077 | |
| 4078 | // Drop arguments and come back to JS mode. |
| 4079 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4080 | |
| 4081 | // Check the result. |
| 4082 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4083 | __ cmp(eax, 1); |
| 4084 | // We expect exactly one result since we force the called regexp to behave |
| 4085 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4086 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4087 | Label failure; |
| 4088 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4089 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4090 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 4091 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4092 | __ j(not_equal, &runtime); |
| 4093 | // Result must now be exception. If there is no pending exception already a |
| 4094 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4095 | // haven't created the exception yet. Handle that in the runtime system. |
| 4096 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4097 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4098 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4099 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4100 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4101 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4102 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4103 | // For exception, throw the exception again. |
| 4104 | |
| 4105 | // Clear the pending exception variable. |
| 4106 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4107 | |
| 4108 | // Special handling of termination exceptions which are uncatchable |
| 4109 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4110 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4111 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4112 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4113 | |
| 4114 | // Handle normal exception by following handler chain. |
| 4115 | __ Throw(eax); |
| 4116 | |
| 4117 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4118 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4119 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4120 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4121 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4122 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4123 | __ ret(4 * kPointerSize); |
| 4124 | |
| 4125 | // Load RegExp data. |
| 4126 | __ bind(&success); |
| 4127 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4128 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4129 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4130 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4131 | STATIC_ASSERT(kSmiTag == 0); |
| 4132 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4133 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4134 | |
| 4135 | // edx: Number of capture registers |
| 4136 | // 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] | 4137 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4138 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4139 | __ JumpIfSmi(eax, &runtime); |
| 4140 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 4141 | __ j(not_equal, &runtime); |
| 4142 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4143 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4144 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 4145 | __ cmp(eax, factory->fixed_array_map()); |
| 4146 | __ j(not_equal, &runtime); |
| 4147 | // Check that the last match info has space for the capture registers and the |
| 4148 | // additional information. |
| 4149 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 4150 | __ SmiUntag(eax); |
| 4151 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 4152 | __ cmp(edx, eax); |
| 4153 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4154 | |
| 4155 | // ebx: last_match_info backing store (FixedArray) |
| 4156 | // edx: number of capture registers |
| 4157 | // Store the capture count. |
| 4158 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4159 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4160 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4161 | // Store last subject and last input. |
| 4162 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4163 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4164 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4165 | __ RecordWriteField(ebx, |
| 4166 | RegExpImpl::kLastSubjectOffset, |
| 4167 | eax, |
| 4168 | edi, |
| 4169 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4170 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4172 | __ RecordWriteField(ebx, |
| 4173 | RegExpImpl::kLastInputOffset, |
| 4174 | eax, |
| 4175 | edi, |
| 4176 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4177 | |
| 4178 | // Get the static offsets vector filled by the native regexp code. |
| 4179 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4180 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4182 | |
| 4183 | // ebx: last_match_info backing store (FixedArray) |
| 4184 | // ecx: offsets vector |
| 4185 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4186 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4187 | // Capture register counter starts from number of capture registers and |
| 4188 | // counts down until wraping after zero. |
| 4189 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4190 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4191 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4192 | // Read the value from the static offsets vector buffer. |
| 4193 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4194 | __ SmiTag(edi); |
| 4195 | // Store the smi value in the last match info. |
| 4196 | __ mov(FieldOperand(ebx, |
| 4197 | edx, |
| 4198 | times_pointer_size, |
| 4199 | RegExpImpl::kFirstCaptureOffset), |
| 4200 | edi); |
| 4201 | __ jmp(&next_capture); |
| 4202 | __ bind(&done); |
| 4203 | |
| 4204 | // Return last match info. |
| 4205 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4206 | __ ret(4 * kPointerSize); |
| 4207 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4208 | // Do the runtime call to execute the regexp. |
| 4209 | __ bind(&runtime); |
| 4210 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4211 | |
| 4212 | // Deferred code for string handling. |
| 4213 | // (7) Not a long external string? If yes, go to (10). |
| 4214 | __ bind(¬_seq_nor_cons); |
| 4215 | // Compare flags are still set from (3). |
| 4216 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4217 | |
| 4218 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4219 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4220 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4221 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4222 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4223 | if (FLAG_debug_code) { |
| 4224 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4225 | // Sequential strings have already been ruled out. |
| 4226 | __ test_b(ebx, kIsIndirectStringMask); |
| 4227 | __ Assert(zero, "external string expected, but not found"); |
| 4228 | } |
| 4229 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4230 | // 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] | 4231 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4232 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4233 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4234 | // (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] | 4235 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4236 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4237 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4238 | // eax: sequential subject string (or look-alike, external string) |
| 4239 | // edx: original subject string |
| 4240 | // ecx: RegExp data (FixedArray) |
| 4241 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4242 | __ bind(&seq_two_byte_string); |
| 4243 | // Load previous index and check range before edx is overwritten. We have |
| 4244 | // to use edx instead of eax here because it might have been only made to |
| 4245 | // look like a sequential string when it actually is an external string. |
| 4246 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4247 | __ JumpIfNotSmi(ebx, &runtime); |
| 4248 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4249 | __ j(above_equal, &runtime); |
| 4250 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4251 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4252 | __ jmp(&check_code); // Go to (E). |
| 4253 | |
| 4254 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4255 | __ bind(¬_long_external); |
| 4256 | // Catch non-string subject or short external string. |
| 4257 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4258 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4259 | __ j(not_zero, &runtime); |
| 4260 | |
| 4261 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4262 | // Load offset into edi and replace subject string with parent. |
| 4263 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4264 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4265 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4266 | #endif // V8_INTERPRETED_REGEXP |
| 4267 | } |
| 4268 | |
| 4269 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4270 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4271 | const int kMaxInlineLength = 100; |
| 4272 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4273 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4274 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4275 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4276 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4277 | __ j(above, &slowcase); |
| 4278 | // Smi-tagging is equivalent to multiplying by 2. |
| 4279 | STATIC_ASSERT(kSmiTag == 0); |
| 4280 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4281 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4282 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4283 | // Elements: [Map][Length][..elements..] |
| 4284 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4285 | times_pointer_size, |
| 4286 | ebx, // In: Number of elements as a smi |
| 4287 | REGISTER_VALUE_IS_SMI, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4288 | eax, // Out: Start of allocation (tagged). |
| 4289 | ecx, // Out: End of allocation. |
| 4290 | edx, // Scratch register |
| 4291 | &slowcase, |
| 4292 | TAG_OBJECT); |
| 4293 | // eax: Start of allocated area, object-tagged. |
| 4294 | |
| 4295 | // Set JSArray map to global.regexp_result_map(). |
| 4296 | // Set empty properties FixedArray. |
| 4297 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4298 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4299 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4300 | Factory* factory = masm->isolate()->factory(); |
| 4301 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4302 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4303 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4304 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4305 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4306 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4307 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4308 | |
| 4309 | // Set input, index and length fields from arguments. |
| 4310 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4311 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4312 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4313 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4314 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4315 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4316 | |
| 4317 | // Fill out the elements FixedArray. |
| 4318 | // eax: JSArray. |
| 4319 | // ebx: FixedArray. |
| 4320 | // ecx: Number of elements in array, as smi. |
| 4321 | |
| 4322 | // Set map. |
| 4323 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4324 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4325 | // Set length. |
| 4326 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4327 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4328 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4329 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4330 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4331 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4332 | // eax: JSArray. |
| 4333 | // ecx: Number of elements to fill. |
| 4334 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4335 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4336 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4337 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4338 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4339 | __ 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] | 4340 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4341 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4342 | __ jmp(&loop); |
| 4343 | |
| 4344 | __ bind(&done); |
| 4345 | __ ret(3 * kPointerSize); |
| 4346 | |
| 4347 | __ bind(&slowcase); |
| 4348 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4349 | } |
| 4350 | |
| 4351 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4352 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4353 | Register object, |
| 4354 | Register result, |
| 4355 | Register scratch1, |
| 4356 | Register scratch2, |
| 4357 | bool object_is_smi, |
| 4358 | Label* not_found) { |
| 4359 | // Use of registers. Register result is used as a temporary. |
| 4360 | Register number_string_cache = result; |
| 4361 | Register mask = scratch1; |
| 4362 | Register scratch = scratch2; |
| 4363 | |
| 4364 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4365 | ExternalReference roots_array_start = |
| 4366 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4367 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4368 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4369 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4370 | // Make the hash mask from the length of the number string cache. It |
| 4371 | // contains two elements (number and string) for each cache entry. |
| 4372 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4373 | __ 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] | 4374 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4375 | |
| 4376 | // Calculate the entry in the number string cache. The hash value in the |
| 4377 | // number string cache for smis is just the smi value, and the hash for |
| 4378 | // doubles is the xor of the upper and lower words. See |
| 4379 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4380 | Label smi_hash_calculated; |
| 4381 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4382 | if (object_is_smi) { |
| 4383 | __ mov(scratch, object); |
| 4384 | __ SmiUntag(scratch); |
| 4385 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4386 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4387 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4388 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4389 | __ mov(scratch, object); |
| 4390 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4391 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4392 | __ bind(¬_smi); |
| 4393 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4394 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4395 | __ j(not_equal, not_found); |
| 4396 | STATIC_ASSERT(8 == kDoubleSize); |
| 4397 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4398 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4399 | // 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] | 4400 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4401 | Register index = scratch; |
| 4402 | Register probe = mask; |
| 4403 | __ mov(probe, |
| 4404 | FieldOperand(number_string_cache, |
| 4405 | index, |
| 4406 | times_twice_pointer_size, |
| 4407 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4408 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4409 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4410 | CpuFeatures::Scope fscope(SSE2); |
| 4411 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4412 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4413 | __ ucomisd(xmm0, xmm1); |
| 4414 | } else { |
| 4415 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4416 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4417 | __ FCmp(); |
| 4418 | } |
| 4419 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4420 | __ 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] | 4421 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | __ bind(&smi_hash_calculated); |
| 4425 | // 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] | 4426 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4427 | Register index = scratch; |
| 4428 | // Check if the entry is the smi we are looking for. |
| 4429 | __ cmp(object, |
| 4430 | FieldOperand(number_string_cache, |
| 4431 | index, |
| 4432 | times_twice_pointer_size, |
| 4433 | FixedArray::kHeaderSize)); |
| 4434 | __ j(not_equal, not_found); |
| 4435 | |
| 4436 | // Get the result from the cache. |
| 4437 | __ bind(&load_result_from_cache); |
| 4438 | __ mov(result, |
| 4439 | FieldOperand(number_string_cache, |
| 4440 | index, |
| 4441 | times_twice_pointer_size, |
| 4442 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4443 | Counters* counters = masm->isolate()->counters(); |
| 4444 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | |
| 4448 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4449 | Label runtime; |
| 4450 | |
| 4451 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4452 | |
| 4453 | // Generate code to lookup number in the number string cache. |
| 4454 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4455 | __ ret(1 * kPointerSize); |
| 4456 | |
| 4457 | __ bind(&runtime); |
| 4458 | // Handle number to string in the runtime system if not found in the cache. |
| 4459 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4460 | } |
| 4461 | |
| 4462 | |
| 4463 | static int NegativeComparisonResult(Condition cc) { |
| 4464 | ASSERT(cc != equal); |
| 4465 | ASSERT((cc == less) || (cc == less_equal) |
| 4466 | || (cc == greater) || (cc == greater_equal)); |
| 4467 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4468 | } |
| 4469 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4470 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4471 | static void CheckInputType(MacroAssembler* masm, |
| 4472 | Register input, |
| 4473 | CompareIC::State expected, |
| 4474 | Label* fail) { |
| 4475 | Label ok; |
| 4476 | if (expected == CompareIC::SMI) { |
| 4477 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4478 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4479 | __ JumpIfSmi(input, &ok); |
| 4480 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4481 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4482 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4483 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4484 | // 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] | 4485 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4486 | __ bind(&ok); |
| 4487 | } |
| 4488 | |
| 4489 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4490 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4491 | Label* label, |
| 4492 | Register object, |
| 4493 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4494 | __ JumpIfSmi(object, label); |
| 4495 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4496 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4497 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4498 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4499 | __ j(not_equal, label); |
| 4500 | } |
| 4501 | |
| 4502 | |
| 4503 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4504 | Label check_unequal_objects; |
| 4505 | Condition cc = GetCondition(); |
| 4506 | |
| 4507 | Label miss; |
| 4508 | CheckInputType(masm, edx, left_, &miss); |
| 4509 | CheckInputType(masm, eax, right_, &miss); |
| 4510 | |
| 4511 | // Compare two smis. |
| 4512 | Label non_smi, smi_done; |
| 4513 | __ mov(ecx, edx); |
| 4514 | __ or_(ecx, eax); |
| 4515 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4516 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4517 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4518 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4519 | __ bind(&smi_done); |
| 4520 | __ mov(eax, edx); |
| 4521 | __ ret(0); |
| 4522 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4523 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4524 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4525 | // it is certain that at least one operand isn't a smi. |
| 4526 | |
| 4527 | // Identical objects can be compared fast, but there are some tricky cases |
| 4528 | // for NaN and undefined. |
| 4529 | { |
| 4530 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4531 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4532 | __ j(not_equal, ¬_identical); |
| 4533 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4534 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | // Check for undefined. undefined OP undefined is false even though |
| 4536 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4537 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4538 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4539 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4540 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4541 | __ ret(0); |
| 4542 | __ bind(&check_for_nan); |
| 4543 | } |
| 4544 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4545 | // Test for NaN. Sadly, we can't just compare to factory->nan_value(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4546 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4547 | Label heap_number; |
| 4548 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4549 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4550 | __ j(equal, &heap_number, Label::kNear); |
| 4551 | if (cc != equal) { |
| 4552 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4553 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4554 | __ j(above_equal, ¬_identical); |
| 4555 | } |
| 4556 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4557 | __ ret(0); |
| 4558 | |
| 4559 | __ bind(&heap_number); |
| 4560 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4561 | // it's not NaN. |
| 4562 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4563 | // and not all mantissa bits (0..51) clear. |
| 4564 | // We only accept QNaNs, which have bit 51 set. |
| 4565 | // Read top bits of double representation (second word of value). |
| 4566 | |
| 4567 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4568 | // all bits in the mask are set. We only need to check the word |
| 4569 | // that contains the exponent and high bit of the mantissa. |
| 4570 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4571 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 4572 | __ Set(eax, Immediate(0)); |
| 4573 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4574 | // bits. |
| 4575 | __ add(edx, edx); |
| 4576 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4577 | if (cc == equal) { |
| 4578 | STATIC_ASSERT(EQUAL != 1); |
| 4579 | __ setcc(above_equal, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4580 | __ ret(0); |
| 4581 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4582 | Label nan; |
| 4583 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4584 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4585 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4586 | __ bind(&nan); |
| 4587 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 4588 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | __ bind(¬_identical); |
| 4592 | } |
| 4593 | |
| 4594 | // Strict equality can quickly decide whether objects are equal. |
| 4595 | // 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] | 4596 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4597 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4598 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4599 | // If we're doing a strict equality comparison, we don't have to do |
| 4600 | // type conversion, so we generate code to do fast comparison for objects |
| 4601 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4602 | // slow-case code. |
| 4603 | // If either is a Smi (we know that not both are), then they can only |
| 4604 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4605 | STATIC_ASSERT(kSmiTag == 0); |
| 4606 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4607 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4608 | __ and_(ecx, eax); |
| 4609 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4610 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4611 | // One operand is a smi. |
| 4612 | |
| 4613 | // Check whether the non-smi is a heap number. |
| 4614 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4615 | // 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] | 4616 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4617 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4618 | __ xor_(ebx, eax); |
| 4619 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4620 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4621 | // if eax was smi, ebx is now edx, else eax. |
| 4622 | |
| 4623 | // Check if the non-smi operand is a heap number. |
| 4624 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4625 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4626 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4627 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4628 | // Return non-equal (ebx is not zero) |
| 4629 | __ mov(eax, ebx); |
| 4630 | __ ret(0); |
| 4631 | |
| 4632 | __ bind(¬_smis); |
| 4633 | // If either operand is a JSObject or an oddball value, then they are not |
| 4634 | // equal since their pointers are different |
| 4635 | // There is no test for undetectability in strict equality. |
| 4636 | |
| 4637 | // Get the type of the first operand. |
| 4638 | // 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] | 4639 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4640 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4641 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4642 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4643 | |
| 4644 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4645 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4646 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4647 | __ bind(&return_not_equal); |
| 4648 | __ ret(0); |
| 4649 | |
| 4650 | __ bind(&first_non_object); |
| 4651 | // Check for oddballs: true, false, null, undefined. |
| 4652 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4653 | __ j(equal, &return_not_equal); |
| 4654 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4655 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4656 | __ j(above_equal, &return_not_equal); |
| 4657 | |
| 4658 | // Check for oddballs: true, false, null, undefined. |
| 4659 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4660 | __ j(equal, &return_not_equal); |
| 4661 | |
| 4662 | // Fall through to the general case. |
| 4663 | __ bind(&slow); |
| 4664 | } |
| 4665 | |
| 4666 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4667 | Label non_number_comparison; |
| 4668 | Label unordered; |
| 4669 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4670 | CpuFeatures::Scope use_sse2(SSE2); |
| 4671 | CpuFeatures::Scope use_cmov(CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4672 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4673 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4674 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4675 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4676 | // Don't base result on EFLAGS when a NaN is involved. |
| 4677 | __ j(parity_even, &unordered, Label::kNear); |
| 4678 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4679 | __ mov(eax, 0); // equal |
| 4680 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4681 | __ cmov(above, eax, ecx); |
| 4682 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4683 | __ cmov(below, eax, ecx); |
| 4684 | __ ret(0); |
| 4685 | } else { |
| 4686 | FloatingPointHelper::CheckFloatOperands( |
| 4687 | masm, &non_number_comparison, ebx); |
| 4688 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4689 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4690 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4691 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4692 | // Don't base result on EFLAGS when a NaN is involved. |
| 4693 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4694 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4695 | Label below_label, above_label; |
| 4696 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4697 | __ j(below, &below_label, Label::kNear); |
| 4698 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4699 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4700 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4701 | __ ret(0); |
| 4702 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4703 | __ bind(&below_label); |
| 4704 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4705 | __ ret(0); |
| 4706 | |
| 4707 | __ bind(&above_label); |
| 4708 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4709 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4712 | // If one of the numbers was NaN, then the result is always false. |
| 4713 | // The cc is never not-equal. |
| 4714 | __ bind(&unordered); |
| 4715 | ASSERT(cc != not_equal); |
| 4716 | if (cc == less || cc == less_equal) { |
| 4717 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4718 | } else { |
| 4719 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4720 | } |
| 4721 | __ ret(0); |
| 4722 | |
| 4723 | // The number comparison code did not provide a valid result. |
| 4724 | __ bind(&non_number_comparison); |
| 4725 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4726 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4727 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4728 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4729 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4730 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4731 | |
| 4732 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4733 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4734 | // non-zero value, which indicates not equal, so just return. |
| 4735 | __ ret(0); |
| 4736 | } |
| 4737 | |
| 4738 | __ bind(&check_for_strings); |
| 4739 | |
| 4740 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4741 | &check_unequal_objects); |
| 4742 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4743 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4744 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4745 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4746 | edx, |
| 4747 | eax, |
| 4748 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4749 | ebx); |
| 4750 | } else { |
| 4751 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4752 | edx, |
| 4753 | eax, |
| 4754 | ecx, |
| 4755 | ebx, |
| 4756 | edi); |
| 4757 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4758 | #ifdef DEBUG |
| 4759 | __ Abort("Unexpected fall-through from string comparison"); |
| 4760 | #endif |
| 4761 | |
| 4762 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4763 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4764 | // Non-strict equality. Objects are unequal if |
| 4765 | // they are both JSObjects and not undetectable, |
| 4766 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4767 | Label not_both_objects; |
| 4768 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4769 | // At most one is a smi, so we can test for smi by adding the two. |
| 4770 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4771 | // a heap object has the low bit clear. |
| 4772 | STATIC_ASSERT(kSmiTag == 0); |
| 4773 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4774 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4775 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4776 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4777 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4778 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4779 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4780 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4781 | // We do not bail out after this point. Both are JSObjects, and |
| 4782 | // they are equal if and only if both are undetectable. |
| 4783 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4784 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4785 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4786 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4787 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4788 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4789 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4790 | // The objects are both undetectable, so they both compare as the value |
| 4791 | // undefined, and are equal. |
| 4792 | __ Set(eax, Immediate(EQUAL)); |
| 4793 | __ bind(&return_unequal); |
| 4794 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4795 | // or return equal if we fell through to here. |
| 4796 | __ ret(0); // rax, rdx were pushed |
| 4797 | __ bind(¬_both_objects); |
| 4798 | } |
| 4799 | |
| 4800 | // Push arguments below the return address. |
| 4801 | __ pop(ecx); |
| 4802 | __ push(edx); |
| 4803 | __ push(eax); |
| 4804 | |
| 4805 | // Figure out which native to call and setup the arguments. |
| 4806 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4807 | if (cc == equal) { |
| 4808 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4809 | } else { |
| 4810 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4811 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | // Restore return address on the stack. |
| 4815 | __ push(ecx); |
| 4816 | |
| 4817 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4818 | // tagged as a small integer. |
| 4819 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4820 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4821 | __ bind(&miss); |
| 4822 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | |
| 4826 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4827 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4831 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4832 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4833 | } |
| 4834 | |
| 4835 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4836 | static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4837 | // Cache the called function in a global property cell. Cache states |
| 4838 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4839 | // megamorphic. |
| 4840 | // ebx : cache cell for call target |
| 4841 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4842 | ASSERT(!FLAG_optimize_constructed_arrays); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4843 | Isolate* isolate = masm->isolate(); |
| 4844 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4845 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4846 | // Load the cache state into ecx. |
| 4847 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4848 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4849 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4850 | // function without changing the state. |
| 4851 | __ cmp(ecx, edi); |
| 4852 | __ j(equal, &done, Label::kNear); |
| 4853 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4854 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4855 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4856 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4857 | // megamorphic. |
| 4858 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4859 | __ j(equal, &initialize, Label::kNear); |
| 4860 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4861 | // write-barrier is needed. |
| 4862 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4863 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4864 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4865 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4866 | // An uninitialized cache is patched with the function. |
| 4867 | __ bind(&initialize); |
| 4868 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4869 | // No need for a write barrier here - cells are rescanned. |
| 4870 | |
| 4871 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4875 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4876 | // Cache the called function in a global property cell. Cache states |
| 4877 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4878 | // megamorphic. |
| 4879 | // ebx : cache cell for call target |
| 4880 | // edi : the function to call |
| 4881 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4882 | Isolate* isolate = masm->isolate(); |
| 4883 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4884 | |
| 4885 | // Load the cache state into ecx. |
| 4886 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 4887 | |
| 4888 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4889 | // function without changing the state. |
| 4890 | __ cmp(ecx, edi); |
| 4891 | __ j(equal, &done); |
| 4892 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4893 | __ j(equal, &done); |
| 4894 | |
| 4895 | // Special handling of the Array() function, which caches not only the |
| 4896 | // monomorphic Array function but the initial ElementsKind with special |
| 4897 | // sentinels |
| 4898 | Handle<Object> terminal_kind_sentinel = |
| 4899 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4900 | LAST_FAST_ELEMENTS_KIND); |
| 4901 | __ cmp(ecx, Immediate(terminal_kind_sentinel)); |
| 4902 | __ j(above, &miss); |
| 4903 | // Load the global or builtins object from the current context |
| 4904 | __ LoadGlobalContext(ecx); |
| 4905 | // Make sure the function is the Array() function |
| 4906 | __ cmp(edi, Operand(ecx, |
| 4907 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4908 | __ j(not_equal, &megamorphic); |
| 4909 | __ jmp(&done); |
| 4910 | |
| 4911 | __ bind(&miss); |
| 4912 | |
| 4913 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4914 | // megamorphic. |
| 4915 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4916 | __ j(equal, &initialize); |
| 4917 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4918 | // write-barrier is needed. |
| 4919 | __ bind(&megamorphic); |
| 4920 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4921 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4922 | __ jmp(&done, Label::kNear); |
| 4923 | |
| 4924 | // An uninitialized cache is patched with the function or sentinel to |
| 4925 | // indicate the ElementsKind if function is the Array constructor. |
| 4926 | __ bind(&initialize); |
| 4927 | __ LoadGlobalContext(ecx); |
| 4928 | // Make sure the function is the Array() function |
| 4929 | __ cmp(edi, Operand(ecx, |
| 4930 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4931 | __ j(not_equal, ¬_array_function); |
| 4932 | |
| 4933 | // The target function is the Array constructor, install a sentinel value in |
| 4934 | // the constructor's type info cell that will track the initial ElementsKind |
| 4935 | // that should be used for the array when its constructed. |
| 4936 | Handle<Object> initial_kind_sentinel = |
| 4937 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4938 | GetInitialFastElementsKind()); |
| 4939 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4940 | Immediate(initial_kind_sentinel)); |
| 4941 | __ jmp(&done); |
| 4942 | |
| 4943 | __ bind(¬_array_function); |
| 4944 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4945 | // No need for a write barrier here - cells are rescanned. |
| 4946 | |
| 4947 | __ bind(&done); |
| 4948 | } |
| 4949 | |
| 4950 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4951 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4952 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4953 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4954 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4955 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4956 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4957 | // The receiver might implicitly be the global object. This is |
| 4958 | // indicated by passing the hole as the receiver to the call |
| 4959 | // function stub. |
| 4960 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4961 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4962 | // Get the receiver from the stack. |
| 4963 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4964 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4965 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4966 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4967 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4968 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4969 | __ mov(ecx, GlobalObjectOperand()); |
| 4970 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4971 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4972 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4975 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4976 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4977 | // Goto slow case if we do not have a function. |
| 4978 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4979 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4980 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4981 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4982 | if (FLAG_optimize_constructed_arrays) { |
| 4983 | GenerateRecordCallTarget(masm); |
| 4984 | } else { |
| 4985 | GenerateRecordCallTargetNoArray(masm); |
| 4986 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4989 | // Fast-case: Just invoke the function. |
| 4990 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4991 | |
| 4992 | if (ReceiverMightBeImplicit()) { |
| 4993 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4994 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4995 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4996 | __ InvokeFunction(edi, |
| 4997 | actual, |
| 4998 | JUMP_FUNCTION, |
| 4999 | NullCallWrapper(), |
| 5000 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5001 | __ bind(&call_as_function); |
| 5002 | } |
| 5003 | __ InvokeFunction(edi, |
| 5004 | actual, |
| 5005 | JUMP_FUNCTION, |
| 5006 | NullCallWrapper(), |
| 5007 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5008 | |
| 5009 | // Slow-case: Non-function called. |
| 5010 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5011 | if (RecordCallTarget()) { |
| 5012 | // 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] | 5013 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 5014 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5015 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5016 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5017 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5018 | // Check for function proxy. |
| 5019 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 5020 | __ j(not_equal, &non_function); |
| 5021 | __ pop(ecx); |
| 5022 | __ push(edi); // put proxy as additional argument under return address |
| 5023 | __ push(ecx); |
| 5024 | __ Set(eax, Immediate(argc_ + 1)); |
| 5025 | __ Set(ebx, Immediate(0)); |
| 5026 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 5027 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 5028 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5029 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5030 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 5031 | } |
| 5032 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5033 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 5034 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5035 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5036 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 5037 | __ Set(eax, Immediate(argc_)); |
| 5038 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5039 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5040 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5041 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5042 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 5043 | } |
| 5044 | |
| 5045 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5046 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 5047 | // eax : number of arguments |
| 5048 | // ebx : cache cell for call target |
| 5049 | // edi : constructor function |
| 5050 | Label slow, non_function_call; |
| 5051 | |
| 5052 | // Check that function is not a smi. |
| 5053 | __ JumpIfSmi(edi, &non_function_call); |
| 5054 | // Check that function is a JSFunction. |
| 5055 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 5056 | __ j(not_equal, &slow); |
| 5057 | |
| 5058 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5059 | if (FLAG_optimize_constructed_arrays) { |
| 5060 | GenerateRecordCallTarget(masm); |
| 5061 | } else { |
| 5062 | GenerateRecordCallTargetNoArray(masm); |
| 5063 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | // Jump to the function-specific construct stub. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5067 | Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; |
| 5068 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 5069 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 5070 | SharedFunctionInfo::kConstructStubOffset)); |
| 5071 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 5072 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5073 | |
| 5074 | // edi: called object |
| 5075 | // eax: number of arguments |
| 5076 | // ecx: object map |
| 5077 | Label do_call; |
| 5078 | __ bind(&slow); |
| 5079 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 5080 | __ j(not_equal, &non_function_call); |
| 5081 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 5082 | __ jmp(&do_call); |
| 5083 | |
| 5084 | __ bind(&non_function_call); |
| 5085 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 5086 | __ bind(&do_call); |
| 5087 | // Set expected number of arguments to zero (not changing eax). |
| 5088 | __ Set(ebx, Immediate(0)); |
| 5089 | Handle<Code> arguments_adaptor = |
| 5090 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 5091 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 5092 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 5093 | } |
| 5094 | |
| 5095 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 5096 | bool CEntryStub::NeedsImmovableCode() { |
| 5097 | return false; |
| 5098 | } |
| 5099 | |
| 5100 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5101 | bool CEntryStub::IsPregenerated() { |
| 5102 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 5103 | result_size_ == 1; |
| 5104 | } |
| 5105 | |
| 5106 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5107 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5108 | CEntryStub::GenerateAheadOfTime(isolate); |
| 5109 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5110 | // 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] | 5111 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5115 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5116 | if (CpuFeatures::IsSupported(SSE2)) { |
| 5117 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 5118 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 5119 | // which would lead to code stub initialization state being messed up. |
| 5120 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5121 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 5122 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5123 | } |
| 5124 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5125 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5126 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5130 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5131 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5132 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5133 | code->set_is_pregenerated(true); |
| 5134 | } |
| 5135 | |
| 5136 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5137 | static void JumpIfOOM(MacroAssembler* masm, |
| 5138 | Register value, |
| 5139 | Register scratch, |
| 5140 | Label* oom_label) { |
| 5141 | __ mov(scratch, value); |
| 5142 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 5143 | STATIC_ASSERT(kFailureTag == 3); |
| 5144 | __ and_(scratch, 0xf); |
| 5145 | __ cmp(scratch, 0xf); |
| 5146 | __ j(equal, oom_label); |
| 5147 | } |
| 5148 | |
| 5149 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5150 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5151 | Label* throw_normal_exception, |
| 5152 | Label* throw_termination_exception, |
| 5153 | Label* throw_out_of_memory_exception, |
| 5154 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5155 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5156 | // eax: result parameter for PerformGC, if any |
| 5157 | // ebx: pointer to C function (C callee-saved) |
| 5158 | // ebp: frame pointer (restored after C call) |
| 5159 | // esp: stack pointer (restored after C call) |
| 5160 | // edi: number of arguments including receiver (C callee-saved) |
| 5161 | // esi: pointer to the first argument (C callee-saved) |
| 5162 | |
| 5163 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5164 | |
| 5165 | // Check stack alignment. |
| 5166 | if (FLAG_debug_code) { |
| 5167 | __ CheckStackAlignment(); |
| 5168 | } |
| 5169 | |
| 5170 | if (do_gc) { |
| 5171 | // Pass failure code returned from last attempt as first argument to |
| 5172 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5173 | // stack alignment is known to be correct. This function takes one argument |
| 5174 | // which is passed on the stack, and we know that the stack has been |
| 5175 | // prepared to pass at least one argument. |
| 5176 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5177 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5178 | } |
| 5179 | |
| 5180 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5181 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5182 | if (always_allocate_scope) { |
| 5183 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5184 | } |
| 5185 | |
| 5186 | // Call C function. |
| 5187 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5188 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5189 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5190 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5191 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5192 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5193 | |
| 5194 | if (always_allocate_scope) { |
| 5195 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5196 | } |
| 5197 | |
| 5198 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5199 | // call as this may lead to crashes in the IC code later. |
| 5200 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5201 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5202 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5203 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5204 | __ int3(); |
| 5205 | __ bind(&okay); |
| 5206 | } |
| 5207 | |
| 5208 | // Check for failure result. |
| 5209 | Label failure_returned; |
| 5210 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5211 | __ lea(ecx, Operand(eax, 1)); |
| 5212 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5213 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5214 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5215 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5216 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5217 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5218 | |
| 5219 | // Check that there is no pending exception, otherwise we |
| 5220 | // should have returned some failure value. |
| 5221 | if (FLAG_debug_code) { |
| 5222 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5223 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5224 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5225 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5226 | // 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] | 5227 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5228 | __ int3(); |
| 5229 | __ bind(&okay); |
| 5230 | __ pop(edx); |
| 5231 | } |
| 5232 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5233 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5234 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5235 | __ ret(0); |
| 5236 | |
| 5237 | // Handling of failure. |
| 5238 | __ bind(&failure_returned); |
| 5239 | |
| 5240 | Label retry; |
| 5241 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5242 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5243 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5244 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5245 | |
| 5246 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5247 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5248 | |
| 5249 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5250 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5251 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5252 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5253 | |
| 5254 | // Special handling of termination exceptions which are uncatchable |
| 5255 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5256 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5257 | __ j(equal, throw_termination_exception); |
| 5258 | |
| 5259 | // Handle normal exception. |
| 5260 | __ jmp(throw_normal_exception); |
| 5261 | |
| 5262 | // Retry. |
| 5263 | __ bind(&retry); |
| 5264 | } |
| 5265 | |
| 5266 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5267 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5268 | // eax: number of arguments including receiver |
| 5269 | // ebx: pointer to C function (C callee-saved) |
| 5270 | // ebp: frame pointer (restored after C call) |
| 5271 | // esp: stack pointer (restored after C call) |
| 5272 | // esi: current context (C callee-saved) |
| 5273 | // edi: JS function of the caller (C callee-saved) |
| 5274 | |
| 5275 | // NOTE: Invocations of builtins may return failure objects instead |
| 5276 | // of a proper result. The builtin entry handles this by performing |
| 5277 | // a garbage collection and retrying the builtin (twice). |
| 5278 | |
| 5279 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5280 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5281 | |
| 5282 | // eax: result parameter for PerformGC, if any (setup below) |
| 5283 | // ebx: pointer to builtin function (C callee-saved) |
| 5284 | // ebp: frame pointer (restored after C call) |
| 5285 | // esp: stack pointer (restored after C call) |
| 5286 | // edi: number of arguments including receiver (C callee-saved) |
| 5287 | // esi: argv pointer (C callee-saved) |
| 5288 | |
| 5289 | Label throw_normal_exception; |
| 5290 | Label throw_termination_exception; |
| 5291 | Label throw_out_of_memory_exception; |
| 5292 | |
| 5293 | // Call into the runtime system. |
| 5294 | GenerateCore(masm, |
| 5295 | &throw_normal_exception, |
| 5296 | &throw_termination_exception, |
| 5297 | &throw_out_of_memory_exception, |
| 5298 | false, |
| 5299 | false); |
| 5300 | |
| 5301 | // Do space-specific GC and retry runtime call. |
| 5302 | GenerateCore(masm, |
| 5303 | &throw_normal_exception, |
| 5304 | &throw_termination_exception, |
| 5305 | &throw_out_of_memory_exception, |
| 5306 | true, |
| 5307 | false); |
| 5308 | |
| 5309 | // Do full GC and retry runtime call one final time. |
| 5310 | Failure* failure = Failure::InternalError(); |
| 5311 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5312 | GenerateCore(masm, |
| 5313 | &throw_normal_exception, |
| 5314 | &throw_termination_exception, |
| 5315 | &throw_out_of_memory_exception, |
| 5316 | true, |
| 5317 | true); |
| 5318 | |
| 5319 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5320 | // Set external caught exception to false. |
| 5321 | Isolate* isolate = masm->isolate(); |
| 5322 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5323 | isolate); |
| 5324 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5325 | |
| 5326 | // Set pending exception and eax to out of memory exception. |
| 5327 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5328 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5329 | Label already_have_failure; |
| 5330 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5331 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5332 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5333 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5334 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5335 | |
| 5336 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5337 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5338 | |
| 5339 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5340 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | |
| 5344 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5345 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5346 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5347 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5348 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5349 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5350 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5351 | |
| 5352 | // Push marker in two places. |
| 5353 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5354 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5355 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5356 | // Save callee-saved registers (C calling conventions). |
| 5357 | __ push(edi); |
| 5358 | __ push(esi); |
| 5359 | __ push(ebx); |
| 5360 | |
| 5361 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5362 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5364 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5365 | // 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] | 5366 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5367 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5368 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5369 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5370 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5371 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5372 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5373 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5374 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5375 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5376 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5377 | // block that sets the pending exception. |
| 5378 | __ jmp(&invoke); |
| 5379 | __ bind(&handler_entry); |
| 5380 | handler_offset_ = handler_entry.pos(); |
| 5381 | // Caught exception: Store result (exception) in the pending exception |
| 5382 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5383 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5384 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5385 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5386 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5387 | __ jmp(&exit); |
| 5388 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5389 | // Invoke: Link this frame into the handler chain. There's only one |
| 5390 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5391 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5392 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5393 | |
| 5394 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5395 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5396 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5397 | |
| 5398 | // Fake a receiver (NULL). |
| 5399 | __ push(Immediate(0)); // receiver |
| 5400 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5401 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5402 | // pop the faked function when we return. Notice that we cannot store a |
| 5403 | // reference to the trampoline code directly in this stub, because the |
| 5404 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5406 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5407 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5408 | __ mov(edx, Immediate(construct_entry)); |
| 5409 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5410 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5411 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5412 | __ mov(edx, Immediate(entry)); |
| 5413 | } |
| 5414 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5415 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5416 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5417 | |
| 5418 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5419 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5420 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5421 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5422 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5423 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5424 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5425 | __ j(not_equal, ¬_outermost_js_2); |
| 5426 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5427 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5428 | |
| 5429 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5430 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5431 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5432 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5433 | |
| 5434 | // Restore callee-saved registers (C calling conventions). |
| 5435 | __ pop(ebx); |
| 5436 | __ pop(esi); |
| 5437 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5438 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5439 | |
| 5440 | // Restore frame pointer and return. |
| 5441 | __ pop(ebp); |
| 5442 | __ ret(0); |
| 5443 | } |
| 5444 | |
| 5445 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5446 | // Generate stub code for instanceof. |
| 5447 | // This code can patch a call site inlined cache of the instance of check, |
| 5448 | // which looks like this. |
| 5449 | // |
| 5450 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5451 | // 75 0a jne <some near label> |
| 5452 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5453 | // |
| 5454 | // If call site patching is requested the stack will have the delta from the |
| 5455 | // return address to the cmp instruction just below the return address. This |
| 5456 | // also means that call site patching can only take place with arguments in |
| 5457 | // registers. TOS looks like this when call site patching is requested |
| 5458 | // |
| 5459 | // esp[0] : return address |
| 5460 | // esp[4] : delta from return address to cmp instruction |
| 5461 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5462 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5463 | // Call site inlining and patching implies arguments in registers. |
| 5464 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5465 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5466 | // Fixed register usage throughout the stub. |
| 5467 | Register object = eax; // Object (lhs). |
| 5468 | Register map = ebx; // Map of the object. |
| 5469 | Register function = edx; // Function (rhs). |
| 5470 | Register prototype = edi; // Prototype of the function. |
| 5471 | Register scratch = ecx; |
| 5472 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5473 | // Constants describing the call site code to patch. |
| 5474 | static const int kDeltaToCmpImmediate = 2; |
| 5475 | static const int kDeltaToMov = 8; |
| 5476 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5477 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5478 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5479 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5480 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5481 | ExternalReference roots_array_start = |
| 5482 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5483 | |
| 5484 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5485 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5486 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5487 | // Get the object and function - they are always both needed. |
| 5488 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5489 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5490 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5491 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5492 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5493 | |
| 5494 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5495 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5496 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5497 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5498 | // If there is a call site cache don't look in the global cache, but do the |
| 5499 | // real lookup and update the call site cache. |
| 5500 | if (!HasCallSiteInlineCheck()) { |
| 5501 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5502 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5503 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5504 | __ cmp(function, Operand::StaticArray(scratch, |
| 5505 | times_pointer_size, |
| 5506 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5507 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5508 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5509 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5510 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5511 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5512 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5513 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5514 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5515 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5516 | __ bind(&miss); |
| 5517 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5519 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5520 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5521 | |
| 5522 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5523 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5524 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5525 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5526 | // Update the global instanceof or call site inlined cache with the current |
| 5527 | // map and function. The cached answer will be set when it is known below. |
| 5528 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5529 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5530 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5531 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5532 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5533 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5534 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5535 | } else { |
| 5536 | // The constants for the code patching are based on no push instructions |
| 5537 | // at the call site. |
| 5538 | ASSERT(HasArgsInRegisters()); |
| 5539 | // Get return address and delta to inlined map check. |
| 5540 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5541 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5542 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5543 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5544 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5545 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5546 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5547 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5548 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5549 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5550 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5551 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5552 | // Loop through the prototype chain of the object looking for the function |
| 5553 | // prototype. |
| 5554 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5555 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5556 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5557 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5558 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5559 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5560 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5561 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5562 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5563 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5564 | __ jmp(&loop); |
| 5565 | |
| 5566 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5567 | if (!HasCallSiteInlineCheck()) { |
| 5568 | __ Set(eax, Immediate(0)); |
| 5569 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5570 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5571 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5572 | } else { |
| 5573 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5574 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5575 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5576 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5577 | if (FLAG_debug_code) { |
| 5578 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5579 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5580 | } |
| 5581 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5582 | if (!ReturnTrueFalseObject()) { |
| 5583 | __ Set(eax, Immediate(0)); |
| 5584 | } |
| 5585 | } |
| 5586 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5587 | |
| 5588 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5589 | if (!HasCallSiteInlineCheck()) { |
| 5590 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5591 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5592 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5593 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5594 | } else { |
| 5595 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5596 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5597 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5598 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5599 | if (FLAG_debug_code) { |
| 5600 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5601 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5602 | } |
| 5603 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5604 | if (!ReturnTrueFalseObject()) { |
| 5605 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5606 | } |
| 5607 | } |
| 5608 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5609 | |
| 5610 | Label object_not_null, object_not_null_or_smi; |
| 5611 | __ bind(¬_js_object); |
| 5612 | // Before null, smi and string value checks, check that the rhs is a function |
| 5613 | // 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] | 5614 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5615 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5616 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5617 | |
| 5618 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5619 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5620 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5621 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5622 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5623 | |
| 5624 | __ bind(&object_not_null); |
| 5625 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5626 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5627 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5628 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5629 | |
| 5630 | __ bind(&object_not_null_or_smi); |
| 5631 | // String values is not instance of anything. |
| 5632 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5633 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5634 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5635 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5636 | |
| 5637 | // Slow-case: Go through the JavaScript implementation. |
| 5638 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5639 | if (!ReturnTrueFalseObject()) { |
| 5640 | // Tail call the builtin which returns 0 or 1. |
| 5641 | if (HasArgsInRegisters()) { |
| 5642 | // Push arguments below return address. |
| 5643 | __ pop(scratch); |
| 5644 | __ push(object); |
| 5645 | __ push(function); |
| 5646 | __ push(scratch); |
| 5647 | } |
| 5648 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5649 | } else { |
| 5650 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5651 | { |
| 5652 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5653 | __ push(object); |
| 5654 | __ push(function); |
| 5655 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5656 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5657 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5658 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5659 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5660 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5661 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5662 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5663 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5664 | __ bind(&done); |
| 5665 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5666 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5670 | Register InstanceofStub::left() { return eax; } |
| 5671 | |
| 5672 | |
| 5673 | Register InstanceofStub::right() { return edx; } |
| 5674 | |
| 5675 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5676 | // ------------------------------------------------------------------------- |
| 5677 | // StringCharCodeAtGenerator |
| 5678 | |
| 5679 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5680 | // If the receiver is a smi trigger the non-string case. |
| 5681 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5682 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5683 | |
| 5684 | // Fetch the instance type of the receiver into result register. |
| 5685 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5686 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5687 | // If the receiver is not a string trigger the non-string case. |
| 5688 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5689 | __ j(not_zero, receiver_not_string_); |
| 5690 | |
| 5691 | // If the index is non-smi trigger the non-smi case. |
| 5692 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5693 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5694 | __ bind(&got_smi_index_); |
| 5695 | |
| 5696 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5697 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5698 | __ j(above_equal, index_out_of_range_); |
| 5699 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5700 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5701 | |
| 5702 | Factory* factory = masm->isolate()->factory(); |
| 5703 | StringCharLoadGenerator::Generate( |
| 5704 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5705 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5706 | __ SmiTag(result_); |
| 5707 | __ bind(&exit_); |
| 5708 | } |
| 5709 | |
| 5710 | |
| 5711 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5712 | MacroAssembler* masm, |
| 5713 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5714 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5715 | |
| 5716 | // Index is not a smi. |
| 5717 | __ bind(&index_not_smi_); |
| 5718 | // 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] | 5719 | __ CheckMap(index_, |
| 5720 | masm->isolate()->factory()->heap_number_map(), |
| 5721 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5722 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5723 | call_helper.BeforeCall(masm); |
| 5724 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5725 | __ push(index_); // Consumed by runtime conversion function. |
| 5726 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5727 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5728 | } else { |
| 5729 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5730 | // NumberToSmi discards numbers that are not exact integers. |
| 5731 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5732 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5733 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5734 | // Save the conversion result before the pop instructions below |
| 5735 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5736 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5737 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5738 | __ pop(object_); |
| 5739 | // Reload the instance type. |
| 5740 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5741 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5742 | call_helper.AfterCall(masm); |
| 5743 | // If index is still not a smi, it must be out of range. |
| 5744 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5745 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5746 | // Otherwise, return to the fast path. |
| 5747 | __ jmp(&got_smi_index_); |
| 5748 | |
| 5749 | // Call runtime. We get here when the receiver is a string and the |
| 5750 | // index is a number, but the code of getting the actual character |
| 5751 | // is too complex (e.g., when the string needs to be flattened). |
| 5752 | __ bind(&call_runtime_); |
| 5753 | call_helper.BeforeCall(masm); |
| 5754 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5755 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5756 | __ push(index_); |
| 5757 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5758 | if (!result_.is(eax)) { |
| 5759 | __ mov(result_, eax); |
| 5760 | } |
| 5761 | call_helper.AfterCall(masm); |
| 5762 | __ jmp(&exit_); |
| 5763 | |
| 5764 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5765 | } |
| 5766 | |
| 5767 | |
| 5768 | // ------------------------------------------------------------------------- |
| 5769 | // StringCharFromCodeGenerator |
| 5770 | |
| 5771 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5772 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5773 | STATIC_ASSERT(kSmiTag == 0); |
| 5774 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5775 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5776 | __ test(code_, |
| 5777 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5778 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5779 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5780 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5781 | Factory* factory = masm->isolate()->factory(); |
| 5782 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5783 | STATIC_ASSERT(kSmiTag == 0); |
| 5784 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5785 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5786 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5787 | __ mov(result_, FieldOperand(result_, |
| 5788 | code_, times_half_pointer_size, |
| 5789 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5790 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5791 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5792 | __ bind(&exit_); |
| 5793 | } |
| 5794 | |
| 5795 | |
| 5796 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5797 | MacroAssembler* masm, |
| 5798 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5799 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5800 | |
| 5801 | __ bind(&slow_case_); |
| 5802 | call_helper.BeforeCall(masm); |
| 5803 | __ push(code_); |
| 5804 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5805 | if (!result_.is(eax)) { |
| 5806 | __ mov(result_, eax); |
| 5807 | } |
| 5808 | call_helper.AfterCall(masm); |
| 5809 | __ jmp(&exit_); |
| 5810 | |
| 5811 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5812 | } |
| 5813 | |
| 5814 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5815 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5816 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5817 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5818 | |
| 5819 | // Load the two arguments. |
| 5820 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5821 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5822 | |
| 5823 | // 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] | 5824 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5825 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5826 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5827 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5828 | |
| 5829 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5830 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5831 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5832 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5833 | } else { |
| 5834 | // Here at least one of the arguments is definitely a string. |
| 5835 | // We convert the one that is not known to be a string. |
| 5836 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5837 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5838 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5839 | &call_builtin); |
| 5840 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5841 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5842 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5843 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5844 | &call_builtin); |
| 5845 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5846 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | // Both arguments are strings. |
| 5850 | // eax: first string |
| 5851 | // edx: second string |
| 5852 | // 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] | 5853 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5854 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5855 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5856 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5857 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5858 | // 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] | 5859 | Counters* counters = masm->isolate()->counters(); |
| 5860 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5861 | __ ret(2 * kPointerSize); |
| 5862 | __ bind(&second_not_zero_length); |
| 5863 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5864 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5865 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5866 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5867 | // First string is empty, result is second string which is in edx. |
| 5868 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5869 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5870 | __ ret(2 * kPointerSize); |
| 5871 | |
| 5872 | // Both strings are non-empty. |
| 5873 | // eax: first string |
| 5874 | // ebx: length of first string as a smi |
| 5875 | // ecx: length of second string as a smi |
| 5876 | // edx: second string |
| 5877 | // Look at the length of the result of adding the two strings. |
| 5878 | Label string_add_flat_result, longer_than_two; |
| 5879 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5880 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5882 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5883 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5884 | // Use the string table when adding two one character strings, as it |
| 5885 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5886 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5887 | __ j(not_equal, &longer_than_two); |
| 5888 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5889 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5890 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5891 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5892 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5893 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5894 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5896 | // 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] | 5897 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5898 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5899 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5900 | masm, ebx, ecx, eax, edx, edi, |
| 5901 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5902 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5903 | __ ret(2 * kPointerSize); |
| 5904 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5905 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5906 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5907 | // Reload the arguments. |
| 5908 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5909 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5910 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5911 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5912 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5913 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5914 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5915 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5916 | // Pack both characters in ebx. |
| 5917 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5918 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5919 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5920 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5921 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5922 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5923 | |
| 5924 | __ bind(&longer_than_two); |
| 5925 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5926 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5927 | __ j(below, &string_add_flat_result); |
| 5928 | |
| 5929 | // 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] | 5930 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5931 | Label non_ascii, allocated, ascii_data; |
| 5932 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5933 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5934 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5935 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5936 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5937 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5938 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5939 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5940 | __ j(zero, &non_ascii); |
| 5941 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5942 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5943 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5944 | __ bind(&allocated); |
| 5945 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5946 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5947 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5948 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5949 | Immediate(String::kEmptyHashField)); |
| 5950 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5951 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5952 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5953 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5954 | __ ret(2 * kPointerSize); |
| 5955 | __ bind(&non_ascii); |
| 5956 | // 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] | 5957 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5958 | // ecx: first instance type AND second instance type. |
| 5959 | // edi: second instance type. |
| 5960 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5961 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5962 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5963 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5964 | __ xor_(edi, ecx); |
| 5965 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5966 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5967 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5968 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5969 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5970 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5971 | __ jmp(&allocated); |
| 5972 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5973 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5974 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5975 | // Handle creating a flat result from either external or sequential strings. |
| 5976 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5977 | // eax: first string |
| 5978 | // ebx: length of resulting flat string as a smi |
| 5979 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5980 | Label first_prepared, second_prepared; |
| 5981 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5982 | __ bind(&string_add_flat_result); |
| 5983 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5984 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5985 | // ecx: instance type of first string |
| 5986 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5987 | __ test_b(ecx, kStringRepresentationMask); |
| 5988 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5989 | // Rule out short external string and load string resource. |
| 5990 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5991 | __ test_b(ecx, kShortExternalStringMask); |
| 5992 | __ j(not_zero, &call_runtime); |
| 5993 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5994 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5995 | __ jmp(&first_prepared, Label::kNear); |
| 5996 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5997 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5998 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5999 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6000 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6001 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 6002 | // Check whether both strings have same encoding. |
| 6003 | // edi: instance type of second string |
| 6004 | __ xor_(ecx, edi); |
| 6005 | __ test_b(ecx, kStringEncodingMask); |
| 6006 | __ j(not_zero, &call_runtime); |
| 6007 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6008 | __ test_b(edi, kStringRepresentationMask); |
| 6009 | __ j(zero, &second_is_sequential, Label::kNear); |
| 6010 | // Rule out short external string and load string resource. |
| 6011 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6012 | __ test_b(edi, kShortExternalStringMask); |
| 6013 | __ j(not_zero, &call_runtime); |
| 6014 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6015 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6016 | __ jmp(&second_prepared, Label::kNear); |
| 6017 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6018 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6019 | __ bind(&second_prepared); |
| 6020 | |
| 6021 | // Push the addresses of both strings' first characters onto the stack. |
| 6022 | __ push(edx); |
| 6023 | __ push(eax); |
| 6024 | |
| 6025 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 6026 | // edi: instance type of second string |
| 6027 | // First string and second string have the same encoding. |
| 6028 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6029 | __ test_b(edi, kStringEncodingMask); |
| 6030 | __ j(zero, &non_ascii_string_add_flat_result); |
| 6031 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6032 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6033 | // ebx: length of resulting flat string as a smi |
| 6034 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6035 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6036 | // eax: result string |
| 6037 | __ mov(ecx, eax); |
| 6038 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6039 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6040 | // Load first argument's length and first character location. Account for |
| 6041 | // values currently on the stack when fetching arguments from it. |
| 6042 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6043 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6044 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6045 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6046 | // eax: result string |
| 6047 | // ecx: first character of result |
| 6048 | // edx: first char of first argument |
| 6049 | // edi: length of first argument |
| 6050 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6051 | // Load second argument's length and first character location. Account for |
| 6052 | // values currently on the stack when fetching arguments from it. |
| 6053 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6054 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6055 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6056 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6057 | // eax: result string |
| 6058 | // ecx: next character of result |
| 6059 | // edx: first char of second argument |
| 6060 | // edi: length of second argument |
| 6061 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6062 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | __ ret(2 * kPointerSize); |
| 6064 | |
| 6065 | // Handle creating a flat two byte result. |
| 6066 | // eax: first string - known to be two byte |
| 6067 | // ebx: length of resulting flat string as a smi |
| 6068 | // edx: second string |
| 6069 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6070 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6071 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6072 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6073 | // eax: result string |
| 6074 | __ mov(ecx, eax); |
| 6075 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6076 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6077 | // Load second argument's length and first character location. Account for |
| 6078 | // values currently on the stack when fetching arguments from it. |
| 6079 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6080 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6081 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6082 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6083 | // eax: result string |
| 6084 | // ecx: first character of result |
| 6085 | // edx: first char of first argument |
| 6086 | // edi: length of first argument |
| 6087 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6088 | // Load second argument's length and first character location. Account for |
| 6089 | // values currently on the stack when fetching arguments from it. |
| 6090 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6091 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6092 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6093 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6094 | // eax: result string |
| 6095 | // ecx: next character of result |
| 6096 | // edx: first char of second argument |
| 6097 | // edi: length of second argument |
| 6098 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6099 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6100 | __ ret(2 * kPointerSize); |
| 6101 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6102 | // Recover stack pointer before jumping to runtime. |
| 6103 | __ bind(&call_runtime_drop_two); |
| 6104 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6105 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6106 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6107 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6108 | |
| 6109 | if (call_builtin.is_linked()) { |
| 6110 | __ bind(&call_builtin); |
| 6111 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 6112 | } |
| 6113 | } |
| 6114 | |
| 6115 | |
| 6116 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6117 | int stack_offset, |
| 6118 | Register arg, |
| 6119 | Register scratch1, |
| 6120 | Register scratch2, |
| 6121 | Register scratch3, |
| 6122 | Label* slow) { |
| 6123 | // First check if the argument is already a string. |
| 6124 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6125 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6126 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6127 | __ j(below, &done); |
| 6128 | |
| 6129 | // Check the number to string cache. |
| 6130 | Label not_cached; |
| 6131 | __ bind(¬_string); |
| 6132 | // Puts the cached result into scratch1. |
| 6133 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6134 | arg, |
| 6135 | scratch1, |
| 6136 | scratch2, |
| 6137 | scratch3, |
| 6138 | false, |
| 6139 | ¬_cached); |
| 6140 | __ mov(arg, scratch1); |
| 6141 | __ mov(Operand(esp, stack_offset), arg); |
| 6142 | __ jmp(&done); |
| 6143 | |
| 6144 | // Check if the argument is a safe string wrapper. |
| 6145 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6146 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6147 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6148 | __ j(not_equal, slow); |
| 6149 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6150 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6151 | __ j(zero, slow); |
| 6152 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6153 | __ mov(Operand(esp, stack_offset), arg); |
| 6154 | |
| 6155 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | |
| 6159 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6160 | Register dest, |
| 6161 | Register src, |
| 6162 | Register count, |
| 6163 | Register scratch, |
| 6164 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6165 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6166 | __ bind(&loop); |
| 6167 | // This loop just copies one character at a time, as it is only used for very |
| 6168 | // short strings. |
| 6169 | if (ascii) { |
| 6170 | __ mov_b(scratch, Operand(src, 0)); |
| 6171 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6172 | __ add(src, Immediate(1)); |
| 6173 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6174 | } else { |
| 6175 | __ mov_w(scratch, Operand(src, 0)); |
| 6176 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6177 | __ add(src, Immediate(2)); |
| 6178 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6179 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6180 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6181 | __ j(not_zero, &loop); |
| 6182 | } |
| 6183 | |
| 6184 | |
| 6185 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6186 | Register dest, |
| 6187 | Register src, |
| 6188 | Register count, |
| 6189 | Register scratch, |
| 6190 | bool ascii) { |
| 6191 | // Copy characters using rep movs of doublewords. |
| 6192 | // The destination is aligned on a 4 byte boundary because we are |
| 6193 | // copying to the beginning of a newly allocated string. |
| 6194 | ASSERT(dest.is(edi)); // rep movs destination |
| 6195 | ASSERT(src.is(esi)); // rep movs source |
| 6196 | ASSERT(count.is(ecx)); // rep movs count |
| 6197 | ASSERT(!scratch.is(dest)); |
| 6198 | ASSERT(!scratch.is(src)); |
| 6199 | ASSERT(!scratch.is(count)); |
| 6200 | |
| 6201 | // Nothing to do for zero characters. |
| 6202 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6203 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6204 | __ j(zero, &done); |
| 6205 | |
| 6206 | // Make count the number of bytes to copy. |
| 6207 | if (!ascii) { |
| 6208 | __ shl(count, 1); |
| 6209 | } |
| 6210 | |
| 6211 | // 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] | 6212 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6213 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6214 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6215 | |
| 6216 | // Copy from edi to esi using rep movs instruction. |
| 6217 | __ mov(scratch, count); |
| 6218 | __ sar(count, 2); // Number of doublewords to copy. |
| 6219 | __ cld(); |
| 6220 | __ rep_movs(); |
| 6221 | |
| 6222 | // Find number of bytes left. |
| 6223 | __ mov(count, scratch); |
| 6224 | __ and_(count, 3); |
| 6225 | |
| 6226 | // Check if there are more bytes to copy. |
| 6227 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6228 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6229 | __ j(zero, &done); |
| 6230 | |
| 6231 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6232 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6233 | __ bind(&loop); |
| 6234 | __ mov_b(scratch, Operand(src, 0)); |
| 6235 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6236 | __ add(src, Immediate(1)); |
| 6237 | __ add(dest, Immediate(1)); |
| 6238 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6239 | __ j(not_zero, &loop); |
| 6240 | |
| 6241 | __ bind(&done); |
| 6242 | } |
| 6243 | |
| 6244 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6245 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6246 | Register c1, |
| 6247 | Register c2, |
| 6248 | Register scratch1, |
| 6249 | Register scratch2, |
| 6250 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6251 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6252 | Label* not_found) { |
| 6253 | // Register scratch3 is the general scratch register in this function. |
| 6254 | Register scratch = scratch3; |
| 6255 | |
| 6256 | // 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^] | 6257 | // 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] | 6258 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6259 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6260 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6261 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6262 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6263 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6264 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6265 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6266 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6267 | |
| 6268 | __ bind(¬_array_index); |
| 6269 | // Calculate the two character string hash. |
| 6270 | Register hash = scratch1; |
| 6271 | GenerateHashInit(masm, hash, c1, scratch); |
| 6272 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6273 | GenerateHashGetHash(masm, hash, scratch); |
| 6274 | |
| 6275 | // Collect the two characters in a register. |
| 6276 | Register chars = c1; |
| 6277 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6278 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6279 | |
| 6280 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6281 | // hash: hash of two character string. |
| 6282 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6283 | // Load the string table. |
| 6284 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6285 | ExternalReference roots_array_start = |
| 6286 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6287 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 6288 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6289 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6290 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6291 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6292 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6293 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6294 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6295 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6296 | |
| 6297 | // Registers |
| 6298 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6299 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6300 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6301 | // mask: capacity mask |
| 6302 | // scratch: - |
| 6303 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6304 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6305 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6306 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6307 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6308 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6309 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6310 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6311 | __ mov(scratch, hash); |
| 6312 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6313 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6314 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6315 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6316 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6317 | // Load the entry from the string table. |
| 6318 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6319 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6320 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6321 | scratch, |
| 6322 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6323 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6324 | |
| 6325 | // 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] | 6326 | Factory* factory = masm->isolate()->factory(); |
| 6327 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6328 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6329 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6330 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6331 | |
| 6332 | // If length is not 2 the string is not a candidate. |
| 6333 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6334 | Immediate(Smi::FromInt(2))); |
| 6335 | __ j(not_equal, &next_probe[i]); |
| 6336 | |
| 6337 | // As we are out of registers save the mask on the stack and use that |
| 6338 | // register as a temporary. |
| 6339 | __ push(mask); |
| 6340 | Register temp = mask; |
| 6341 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6342 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6343 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6344 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6345 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6346 | temp, temp, &next_probe_pop_mask[i]); |
| 6347 | |
| 6348 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6349 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6350 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6351 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6352 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6353 | __ bind(&next_probe_pop_mask[i]); |
| 6354 | __ pop(mask); |
| 6355 | __ bind(&next_probe[i]); |
| 6356 | } |
| 6357 | |
| 6358 | // No matching 2 character string found by probing. |
| 6359 | __ jmp(not_found); |
| 6360 | |
| 6361 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6362 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6363 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6364 | __ pop(mask); // Pop saved mask from the stack. |
| 6365 | if (!result.is(eax)) { |
| 6366 | __ mov(eax, result); |
| 6367 | } |
| 6368 | } |
| 6369 | |
| 6370 | |
| 6371 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6372 | Register hash, |
| 6373 | Register character, |
| 6374 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6375 | // hash = (seed + character) + ((seed + character) << 10); |
| 6376 | if (Serializer::enabled()) { |
| 6377 | ExternalReference roots_array_start = |
| 6378 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6379 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6380 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6381 | times_pointer_size, |
| 6382 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6383 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6384 | __ add(scratch, character); |
| 6385 | __ mov(hash, scratch); |
| 6386 | __ shl(scratch, 10); |
| 6387 | __ add(hash, scratch); |
| 6388 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6389 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6390 | __ lea(scratch, Operand(character, seed)); |
| 6391 | __ shl(scratch, 10); |
| 6392 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6393 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6394 | // hash ^= hash >> 6; |
| 6395 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6396 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6397 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | |
| 6401 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6402 | Register hash, |
| 6403 | Register character, |
| 6404 | Register scratch) { |
| 6405 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6406 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6407 | // hash += hash << 10; |
| 6408 | __ mov(scratch, hash); |
| 6409 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6410 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6411 | // hash ^= hash >> 6; |
| 6412 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6413 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6414 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | |
| 6418 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6419 | Register hash, |
| 6420 | Register scratch) { |
| 6421 | // hash += hash << 3; |
| 6422 | __ mov(scratch, hash); |
| 6423 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6424 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6425 | // hash ^= hash >> 11; |
| 6426 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6427 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6428 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6429 | // hash += hash << 15; |
| 6430 | __ mov(scratch, hash); |
| 6431 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6432 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6433 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6434 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6435 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6436 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6437 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6438 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6439 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6440 | __ bind(&hash_not_zero); |
| 6441 | } |
| 6442 | |
| 6443 | |
| 6444 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6445 | Label runtime; |
| 6446 | |
| 6447 | // Stack frame on entry. |
| 6448 | // esp[0]: return address |
| 6449 | // esp[4]: to |
| 6450 | // esp[8]: from |
| 6451 | // esp[12]: string |
| 6452 | |
| 6453 | // Make sure first argument is a string. |
| 6454 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6455 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6456 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6457 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6458 | __ j(NegateCondition(is_string), &runtime); |
| 6459 | |
| 6460 | // eax: string |
| 6461 | // ebx: instance type |
| 6462 | |
| 6463 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6464 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6465 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6466 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6467 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6468 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6469 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6470 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6471 | // Shorter than original string's length: an actual substring. |
| 6472 | __ j(below, ¬_original_string, Label::kNear); |
| 6473 | // Longer than original string's length or negative: unsafe arguments. |
| 6474 | __ j(above, &runtime); |
| 6475 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6476 | Counters* counters = masm->isolate()->counters(); |
| 6477 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6478 | __ ret(3 * kPointerSize); |
| 6479 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6480 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6481 | Label single_char; |
| 6482 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6483 | __ j(equal, &single_char); |
| 6484 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6485 | // eax: string |
| 6486 | // ebx: instance type |
| 6487 | // ecx: sub string length (smi) |
| 6488 | // edx: from index (smi) |
| 6489 | // Deal with different string types: update the index if necessary |
| 6490 | // and put the underlying string into edi. |
| 6491 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6492 | // If the string is not indirect, it can only be sequential or external. |
| 6493 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6494 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6495 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6496 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6497 | |
| 6498 | Factory* factory = masm->isolate()->factory(); |
| 6499 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6500 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6501 | // Cons string. Check whether it is flat, then fetch first part. |
| 6502 | // Flat cons strings have an empty second part. |
| 6503 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6504 | factory->empty_string()); |
| 6505 | __ j(not_equal, &runtime); |
| 6506 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6507 | // Update instance type. |
| 6508 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6509 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6510 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6511 | |
| 6512 | __ bind(&sliced_string); |
| 6513 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6514 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6515 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6516 | // Update instance type. |
| 6517 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6518 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6519 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6520 | |
| 6521 | __ bind(&seq_or_external_string); |
| 6522 | // Sequential or external string. Just move string to the expected register. |
| 6523 | __ mov(edi, eax); |
| 6524 | |
| 6525 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6526 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6527 | if (FLAG_string_slices) { |
| 6528 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6529 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6530 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6531 | // edx: adjusted start index (smi) |
| 6532 | // ecx: length (smi) |
| 6533 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6534 | // Short slice. Copy instead of slicing. |
| 6535 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6536 | // Allocate new sliced string. At this point we do not reload the instance |
| 6537 | // type including the string encoding because we simply rely on the info |
| 6538 | // provided by the original string. It does not matter if the original |
| 6539 | // string's encoding is wrong because we always have to recheck encoding of |
| 6540 | // the newly created string's parent anyways due to externalized strings. |
| 6541 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6542 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6543 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6544 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6545 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6546 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6547 | __ jmp(&set_slice_header, Label::kNear); |
| 6548 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6549 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6550 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6551 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6552 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6553 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6554 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6555 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6556 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6557 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6558 | |
| 6559 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6562 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6563 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6564 | // edx: adjusted start index (smi) |
| 6565 | // ecx: length (smi) |
| 6566 | // The subject string can only be external or sequential string of either |
| 6567 | // encoding at this point. |
| 6568 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6569 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6570 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6571 | __ test_b(ebx, kExternalStringTag); |
| 6572 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6573 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6574 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6575 | // Rule out short external strings. |
| 6576 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6577 | __ test_b(ebx, kShortExternalStringMask); |
| 6578 | __ j(not_zero, &runtime); |
| 6579 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6580 | // 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] | 6581 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6582 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6583 | |
| 6584 | __ bind(&sequential_string); |
| 6585 | // Stash away (adjusted) index and (underlying) string. |
| 6586 | __ push(edx); |
| 6587 | __ push(edi); |
| 6588 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6589 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6590 | __ test_b(ebx, kStringEncodingMask); |
| 6591 | __ j(zero, &two_byte_sequential); |
| 6592 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6593 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6594 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6595 | |
| 6596 | // eax: result string |
| 6597 | // ecx: result string length |
| 6598 | __ mov(edx, esi); // esi used by following code. |
| 6599 | // Locate first character of result. |
| 6600 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6601 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6602 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6603 | __ pop(esi); |
| 6604 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6605 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6606 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6607 | |
| 6608 | // eax: result string |
| 6609 | // ecx: result length |
| 6610 | // edx: original value of esi |
| 6611 | // edi: first character of result |
| 6612 | // esi: character of sub string start |
| 6613 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6614 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6615 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6616 | __ ret(3 * kPointerSize); |
| 6617 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6618 | __ bind(&two_byte_sequential); |
| 6619 | // Sequential two-byte string. Allocate the result. |
| 6620 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6621 | |
| 6622 | // eax: result string |
| 6623 | // ecx: result string length |
| 6624 | __ mov(edx, esi); // esi used by following code. |
| 6625 | // Locate first character of result. |
| 6626 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6627 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6628 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6629 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6630 | __ pop(esi); |
| 6631 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6632 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6633 | // byte character. |
| 6634 | STATIC_ASSERT(kSmiTag == 0); |
| 6635 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6636 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6637 | |
| 6638 | // eax: result string |
| 6639 | // ecx: result length |
| 6640 | // edx: original value of esi |
| 6641 | // edi: first character of result |
| 6642 | // esi: character of sub string start |
| 6643 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6644 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6645 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6646 | __ ret(3 * kPointerSize); |
| 6647 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6648 | // Drop pushed values on the stack before tail call. |
| 6649 | __ bind(&runtime_drop_two); |
| 6650 | __ Drop(2); |
| 6651 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6652 | // Just jump to runtime to create the sub string. |
| 6653 | __ bind(&runtime); |
| 6654 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6655 | |
| 6656 | __ bind(&single_char); |
| 6657 | // eax: string |
| 6658 | // ebx: instance type |
| 6659 | // ecx: sub string length (smi) |
| 6660 | // edx: from index (smi) |
| 6661 | StringCharAtGenerator generator( |
| 6662 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6663 | generator.GenerateFast(masm); |
| 6664 | __ ret(3 * kPointerSize); |
| 6665 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6666 | } |
| 6667 | |
| 6668 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6669 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6670 | Register left, |
| 6671 | Register right, |
| 6672 | Register scratch1, |
| 6673 | Register scratch2) { |
| 6674 | Register length = scratch1; |
| 6675 | |
| 6676 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6677 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6678 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6679 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6680 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6681 | __ bind(&strings_not_equal); |
| 6682 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6683 | __ ret(0); |
| 6684 | |
| 6685 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6686 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6687 | __ bind(&check_zero_length); |
| 6688 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6689 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6690 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6691 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6692 | __ ret(0); |
| 6693 | |
| 6694 | // Compare characters. |
| 6695 | __ bind(&compare_chars); |
| 6696 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6697 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6698 | |
| 6699 | // Characters are equal. |
| 6700 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6701 | __ ret(0); |
| 6702 | } |
| 6703 | |
| 6704 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6705 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6706 | Register left, |
| 6707 | Register right, |
| 6708 | Register scratch1, |
| 6709 | Register scratch2, |
| 6710 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6711 | Counters* counters = masm->isolate()->counters(); |
| 6712 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6713 | |
| 6714 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6715 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6716 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6717 | __ mov(scratch3, scratch1); |
| 6718 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6719 | |
| 6720 | Register length_delta = scratch3; |
| 6721 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6722 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6723 | // 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] | 6724 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6725 | __ bind(&left_shorter); |
| 6726 | |
| 6727 | Register min_length = scratch1; |
| 6728 | |
| 6729 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6730 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6731 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6732 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6733 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6734 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6735 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6736 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6737 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6738 | |
| 6739 | // Compare lengths - strings up to min-length are equal. |
| 6740 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6741 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6742 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6743 | __ j(not_zero, &result_not_equal, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6744 | #else |
| 6745 | Label length_not_equal; |
| 6746 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 6747 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6748 | |
| 6749 | // Result is EQUAL. |
| 6750 | STATIC_ASSERT(EQUAL == 0); |
| 6751 | STATIC_ASSERT(kSmiTag == 0); |
| 6752 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6753 | __ ret(0); |
| 6754 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6755 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6756 | #ifdef ENABLE_LATIN_1 |
| 6757 | Label result_less; |
| 6758 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6759 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6760 | __ jmp(&result_less, Label::kNear); |
| 6761 | #endif |
| 6762 | __ bind(&result_not_equal); |
| 6763 | #ifndef ENABLE_LATIN_1 |
| 6764 | __ j(greater, &result_greater, Label::kNear); |
| 6765 | #else |
| 6766 | __ j(above, &result_greater, Label::kNear); |
| 6767 | __ bind(&result_less); |
| 6768 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6769 | |
| 6770 | // Result is LESS. |
| 6771 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6772 | __ ret(0); |
| 6773 | |
| 6774 | // Result is GREATER. |
| 6775 | __ bind(&result_greater); |
| 6776 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6777 | __ ret(0); |
| 6778 | } |
| 6779 | |
| 6780 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6781 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6782 | MacroAssembler* masm, |
| 6783 | Register left, |
| 6784 | Register right, |
| 6785 | Register length, |
| 6786 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6787 | Label* chars_not_equal, |
| 6788 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6789 | // Change index to run from -length to -1 by adding length to string |
| 6790 | // start. This means that loop ends when index reaches zero, which |
| 6791 | // doesn't need an additional compare. |
| 6792 | __ SmiUntag(length); |
| 6793 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6794 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6795 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6796 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6797 | __ neg(length); |
| 6798 | Register index = length; // index = -length; |
| 6799 | |
| 6800 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6801 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6802 | __ bind(&loop); |
| 6803 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6804 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6805 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6806 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6807 | __ j(not_zero, &loop); |
| 6808 | } |
| 6809 | |
| 6810 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6811 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6812 | Label runtime; |
| 6813 | |
| 6814 | // Stack frame on entry. |
| 6815 | // esp[0]: return address |
| 6816 | // esp[4]: right string |
| 6817 | // esp[8]: left string |
| 6818 | |
| 6819 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6820 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6821 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6822 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6823 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6824 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6825 | STATIC_ASSERT(EQUAL == 0); |
| 6826 | STATIC_ASSERT(kSmiTag == 0); |
| 6827 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6828 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6829 | __ ret(2 * kPointerSize); |
| 6830 | |
| 6831 | __ bind(¬_same); |
| 6832 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6833 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6834 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6835 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6836 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6837 | // Drop arguments from the stack. |
| 6838 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6839 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6840 | __ push(ecx); |
| 6841 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6842 | |
| 6843 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6844 | // tagged as a small integer. |
| 6845 | __ bind(&runtime); |
| 6846 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6847 | } |
| 6848 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6849 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6850 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6851 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6852 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6853 | __ mov(ecx, edx); |
| 6854 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6855 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6856 | |
| 6857 | if (GetCondition() == equal) { |
| 6858 | // 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] | 6859 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6860 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6861 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6862 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6863 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6864 | // Correct sign of result in case of overflow. |
| 6865 | __ not_(edx); |
| 6866 | __ bind(&done); |
| 6867 | __ mov(eax, edx); |
| 6868 | } |
| 6869 | __ ret(0); |
| 6870 | |
| 6871 | __ bind(&miss); |
| 6872 | GenerateMiss(masm); |
| 6873 | } |
| 6874 | |
| 6875 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6876 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6877 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6878 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6879 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6880 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6881 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6882 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6883 | if (left_ == CompareIC::SMI) { |
| 6884 | __ JumpIfNotSmi(edx, &miss); |
| 6885 | } |
| 6886 | if (right_ == CompareIC::SMI) { |
| 6887 | __ JumpIfNotSmi(eax, &miss); |
| 6888 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6889 | |
| 6890 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6891 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6892 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6893 | CpuFeatures::Scope scope1(SSE2); |
| 6894 | CpuFeatures::Scope scope2(CMOV); |
| 6895 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6896 | // Load left and right operand. |
| 6897 | Label done, left, left_smi, right_smi; |
| 6898 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6899 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6900 | masm->isolate()->factory()->heap_number_map()); |
| 6901 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6902 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6903 | __ jmp(&left, Label::kNear); |
| 6904 | __ bind(&right_smi); |
| 6905 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6906 | __ SmiUntag(ecx); |
| 6907 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6908 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6909 | __ bind(&left); |
| 6910 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6911 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6912 | masm->isolate()->factory()->heap_number_map()); |
| 6913 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6914 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6915 | __ jmp(&done); |
| 6916 | __ bind(&left_smi); |
| 6917 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6918 | __ SmiUntag(ecx); |
| 6919 | __ cvtsi2sd(xmm0, ecx); |
| 6920 | |
| 6921 | __ bind(&done); |
| 6922 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6923 | __ ucomisd(xmm0, xmm1); |
| 6924 | |
| 6925 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6926 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6927 | |
| 6928 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6929 | // Performing mov, because xor would destroy the flag register. |
| 6930 | __ mov(eax, 0); // equal |
| 6931 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6932 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6933 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6934 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6935 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6936 | } else { |
| 6937 | __ mov(ecx, edx); |
| 6938 | __ and_(ecx, eax); |
| 6939 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6940 | |
| 6941 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6942 | masm->isolate()->factory()->heap_number_map()); |
| 6943 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6944 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6945 | masm->isolate()->factory()->heap_number_map()); |
| 6946 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6947 | } |
| 6948 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6949 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6950 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6951 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6952 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6953 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6954 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6955 | __ bind(&maybe_undefined1); |
| 6956 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6957 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6958 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6959 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6960 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6961 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6962 | __ jmp(&unordered); |
| 6963 | } |
| 6964 | |
| 6965 | __ bind(&maybe_undefined2); |
| 6966 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6967 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6968 | __ j(equal, &unordered); |
| 6969 | } |
| 6970 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6971 | __ bind(&miss); |
| 6972 | GenerateMiss(masm); |
| 6973 | } |
| 6974 | |
| 6975 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6976 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6977 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6978 | ASSERT(GetCondition() == equal); |
| 6979 | |
| 6980 | // Registers containing left and right operands respectively. |
| 6981 | Register left = edx; |
| 6982 | Register right = eax; |
| 6983 | Register tmp1 = ecx; |
| 6984 | Register tmp2 = ebx; |
| 6985 | |
| 6986 | // Check that both operands are heap objects. |
| 6987 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6988 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6989 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6990 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6991 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6992 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6993 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6994 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6995 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6996 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6997 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6998 | STATIC_ASSERT(kInternalizedTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6999 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7000 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7001 | __ j(zero, &miss, Label::kNear); |
| 7002 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7003 | // Internalized strings are compared by identity. |
| 7004 | Label done; |
| 7005 | __ cmp(left, right); |
| 7006 | // Make sure eax is non-zero. At this point input operands are |
| 7007 | // guaranteed to be non-zero. |
| 7008 | ASSERT(right.is(eax)); |
| 7009 | __ j(not_equal, &done, Label::kNear); |
| 7010 | STATIC_ASSERT(EQUAL == 0); |
| 7011 | STATIC_ASSERT(kSmiTag == 0); |
| 7012 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7013 | __ bind(&done); |
| 7014 | __ ret(0); |
| 7015 | |
| 7016 | __ bind(&miss); |
| 7017 | GenerateMiss(masm); |
| 7018 | } |
| 7019 | |
| 7020 | |
| 7021 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 7022 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 7023 | ASSERT(GetCondition() == equal); |
| 7024 | |
| 7025 | // Registers containing left and right operands respectively. |
| 7026 | Register left = edx; |
| 7027 | Register right = eax; |
| 7028 | Register tmp1 = ecx; |
| 7029 | Register tmp2 = ebx; |
| 7030 | |
| 7031 | // Check that both operands are heap objects. |
| 7032 | Label miss; |
| 7033 | __ mov(tmp1, left); |
| 7034 | STATIC_ASSERT(kSmiTag == 0); |
| 7035 | __ and_(tmp1, right); |
| 7036 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 7037 | |
| 7038 | // Check that both operands are unique names. This leaves the instance |
| 7039 | // types loaded in tmp1 and tmp2. |
| 7040 | STATIC_ASSERT(kInternalizedTag != 0); |
| 7041 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 7042 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 7043 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7044 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7045 | |
| 7046 | Label succeed1; |
| 7047 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
| 7048 | __ j(not_zero, &succeed1); |
| 7049 | __ cmpb(tmp1, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7050 | __ j(not_equal, &miss); |
| 7051 | __ bind(&succeed1); |
| 7052 | |
| 7053 | Label succeed2; |
| 7054 | __ test(tmp2, Immediate(kIsInternalizedMask)); |
| 7055 | __ j(not_zero, &succeed2); |
| 7056 | __ cmpb(tmp2, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7057 | __ j(not_equal, &miss); |
| 7058 | __ bind(&succeed2); |
| 7059 | |
| 7060 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7061 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7062 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7063 | // Make sure eax is non-zero. At this point input operands are |
| 7064 | // guaranteed to be non-zero. |
| 7065 | ASSERT(right.is(eax)); |
| 7066 | __ j(not_equal, &done, Label::kNear); |
| 7067 | STATIC_ASSERT(EQUAL == 0); |
| 7068 | STATIC_ASSERT(kSmiTag == 0); |
| 7069 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7070 | __ bind(&done); |
| 7071 | __ ret(0); |
| 7072 | |
| 7073 | __ bind(&miss); |
| 7074 | GenerateMiss(masm); |
| 7075 | } |
| 7076 | |
| 7077 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7078 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7079 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7080 | Label miss; |
| 7081 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7082 | bool equality = Token::IsEqualityOp(op_); |
| 7083 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7084 | // Registers containing left and right operands respectively. |
| 7085 | Register left = edx; |
| 7086 | Register right = eax; |
| 7087 | Register tmp1 = ecx; |
| 7088 | Register tmp2 = ebx; |
| 7089 | Register tmp3 = edi; |
| 7090 | |
| 7091 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7092 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7093 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7094 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7095 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7096 | |
| 7097 | // Check that both operands are strings. This leaves the instance |
| 7098 | // types loaded in tmp1 and tmp2. |
| 7099 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 7100 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 7101 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7102 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7103 | __ mov(tmp3, tmp1); |
| 7104 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7105 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7106 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 7107 | __ j(not_zero, &miss); |
| 7108 | |
| 7109 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7110 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7111 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7112 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7113 | STATIC_ASSERT(EQUAL == 0); |
| 7114 | STATIC_ASSERT(kSmiTag == 0); |
| 7115 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7116 | __ ret(0); |
| 7117 | |
| 7118 | // Handle not identical strings. |
| 7119 | __ bind(¬_same); |
| 7120 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7121 | // 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] | 7122 | // because we already know they are not identical. But in the case of |
| 7123 | // non-equality compare, we still need to determine the order. |
| 7124 | if (equality) { |
| 7125 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7126 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7127 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7128 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7129 | __ j(zero, &do_compare, Label::kNear); |
| 7130 | // Make sure eax is non-zero. At this point input operands are |
| 7131 | // guaranteed to be non-zero. |
| 7132 | ASSERT(right.is(eax)); |
| 7133 | __ ret(0); |
| 7134 | __ bind(&do_compare); |
| 7135 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7136 | |
| 7137 | // Check that both strings are sequential ASCII. |
| 7138 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7139 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 7140 | |
| 7141 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7142 | if (equality) { |
| 7143 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 7144 | masm, left, right, tmp1, tmp2); |
| 7145 | } else { |
| 7146 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 7147 | masm, left, right, tmp1, tmp2, tmp3); |
| 7148 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7149 | |
| 7150 | // Handle more complex cases in runtime. |
| 7151 | __ bind(&runtime); |
| 7152 | __ pop(tmp1); // Return address. |
| 7153 | __ push(left); |
| 7154 | __ push(right); |
| 7155 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7156 | if (equality) { |
| 7157 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 7158 | } else { |
| 7159 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 7160 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7161 | |
| 7162 | __ bind(&miss); |
| 7163 | GenerateMiss(masm); |
| 7164 | } |
| 7165 | |
| 7166 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7167 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7168 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7169 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7170 | __ mov(ecx, edx); |
| 7171 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7172 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7173 | |
| 7174 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7175 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7176 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7177 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7178 | |
| 7179 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7180 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7181 | __ ret(0); |
| 7182 | |
| 7183 | __ bind(&miss); |
| 7184 | GenerateMiss(masm); |
| 7185 | } |
| 7186 | |
| 7187 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7188 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7189 | Label miss; |
| 7190 | __ mov(ecx, edx); |
| 7191 | __ and_(ecx, eax); |
| 7192 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7193 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7194 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7195 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7196 | __ cmp(ecx, known_map_); |
| 7197 | __ j(not_equal, &miss, Label::kNear); |
| 7198 | __ cmp(ebx, known_map_); |
| 7199 | __ j(not_equal, &miss, Label::kNear); |
| 7200 | |
| 7201 | __ sub(eax, edx); |
| 7202 | __ ret(0); |
| 7203 | |
| 7204 | __ bind(&miss); |
| 7205 | GenerateMiss(masm); |
| 7206 | } |
| 7207 | |
| 7208 | |
| 7209 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7210 | { |
| 7211 | // Call the runtime system in a fresh internal frame. |
| 7212 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7213 | masm->isolate()); |
| 7214 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7215 | __ push(edx); // Preserve edx and eax. |
| 7216 | __ push(eax); |
| 7217 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7218 | __ push(eax); |
| 7219 | __ push(Immediate(Smi::FromInt(op_))); |
| 7220 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7221 | // Compute the entry point of the rewritten stub. |
| 7222 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7223 | __ pop(eax); |
| 7224 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7225 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7226 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7227 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7228 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7229 | } |
| 7230 | |
| 7231 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7232 | // Helper function used to check that the dictionary doesn't contain |
| 7233 | // the property. This function may return false negatives, so miss_label |
| 7234 | // must always call a backup property check that is complete. |
| 7235 | // This function is safe to call if the receiver has fast properties. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7236 | // Name must be an internalized string and receiver must be a heap object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7237 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7238 | Label* miss, |
| 7239 | Label* done, |
| 7240 | Register properties, |
| 7241 | Handle<String> name, |
| 7242 | Register r0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7243 | ASSERT(name->IsInternalizedString()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7244 | |
| 7245 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7246 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7247 | // undefined value), it guarantees the hash table doesn't contain the |
| 7248 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7249 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7250 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7251 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7252 | Register index = r0; |
| 7253 | // Capacity is smi 2^n. |
| 7254 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7255 | __ dec(index); |
| 7256 | __ and_(index, |
| 7257 | Immediate(Smi::FromInt(name->Hash() + |
| 7258 | StringDictionary::GetProbeOffset(i)))); |
| 7259 | |
| 7260 | // Scale the index by multiplying by the entry size. |
| 7261 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7262 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7263 | Register entity_name = r0; |
| 7264 | // Having undefined at this place means the name is not contained. |
| 7265 | ASSERT_EQ(kSmiTagSize, 1); |
| 7266 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7267 | kElementsStartOffset - kHeapObjectTag)); |
| 7268 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7269 | __ j(equal, done); |
| 7270 | |
| 7271 | // Stop if found the property. |
| 7272 | __ cmp(entity_name, Handle<String>(name)); |
| 7273 | __ j(equal, miss); |
| 7274 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7275 | Label the_hole; |
| 7276 | // Check for the hole and skip. |
| 7277 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 7278 | __ j(equal, &the_hole, Label::kNear); |
| 7279 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7280 | // Check if the entry name is not an internalized string. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7281 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7282 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7283 | kIsInternalizedMask); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7284 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7285 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | StringDictionaryLookupStub stub(properties, |
| 7289 | r0, |
| 7290 | r0, |
| 7291 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 7292 | __ push(Immediate(Handle<Object>(name))); |
| 7293 | __ push(Immediate(name->Hash())); |
| 7294 | __ CallStub(&stub); |
| 7295 | __ test(r0, r0); |
| 7296 | __ j(not_zero, miss); |
| 7297 | __ jmp(done); |
| 7298 | } |
| 7299 | |
| 7300 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7301 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7302 | // |done| label if a property with the given name is found leaving the |
| 7303 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7304 | // otherwise. |
| 7305 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7306 | Label* miss, |
| 7307 | Label* done, |
| 7308 | Register elements, |
| 7309 | Register name, |
| 7310 | Register r0, |
| 7311 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7312 | ASSERT(!elements.is(r0)); |
| 7313 | ASSERT(!elements.is(r1)); |
| 7314 | ASSERT(!name.is(r0)); |
| 7315 | ASSERT(!name.is(r1)); |
| 7316 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7317 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7318 | |
| 7319 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7320 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7321 | __ dec(r1); |
| 7322 | |
| 7323 | // Generate an unrolled loop that performs a few probes before |
| 7324 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7325 | // cover ~93% of loads from dictionaries. |
| 7326 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7327 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7328 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7329 | __ shr(r0, String::kHashShift); |
| 7330 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7331 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7332 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7333 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7334 | |
| 7335 | // Scale the index by multiplying by the entry size. |
| 7336 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7337 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7338 | |
| 7339 | // Check if the key is identical to the name. |
| 7340 | __ cmp(name, Operand(elements, |
| 7341 | r0, |
| 7342 | times_4, |
| 7343 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7344 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7345 | } |
| 7346 | |
| 7347 | StringDictionaryLookupStub stub(elements, |
| 7348 | r1, |
| 7349 | r0, |
| 7350 | POSITIVE_LOOKUP); |
| 7351 | __ push(name); |
| 7352 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7353 | __ shr(r0, String::kHashShift); |
| 7354 | __ push(r0); |
| 7355 | __ CallStub(&stub); |
| 7356 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7357 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7358 | __ j(zero, miss); |
| 7359 | __ jmp(done); |
| 7360 | } |
| 7361 | |
| 7362 | |
| 7363 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7364 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7365 | // 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] | 7366 | // Stack frame on entry: |
| 7367 | // esp[0 * kPointerSize]: return address. |
| 7368 | // esp[1 * kPointerSize]: key's hash. |
| 7369 | // esp[2 * kPointerSize]: key. |
| 7370 | // Registers: |
| 7371 | // dictionary_: StringDictionary to probe. |
| 7372 | // result_: used as scratch. |
| 7373 | // index_: will hold an index of entry if lookup is successful. |
| 7374 | // might alias with result_. |
| 7375 | // Returns: |
| 7376 | // result_ is zero if lookup failed, non zero otherwise. |
| 7377 | |
| 7378 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7379 | |
| 7380 | Register scratch = result_; |
| 7381 | |
| 7382 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7383 | __ dec(scratch); |
| 7384 | __ SmiUntag(scratch); |
| 7385 | __ push(scratch); |
| 7386 | |
| 7387 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7388 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7389 | // undefined value), it guarantees the hash table doesn't contain the |
| 7390 | // property. It's true even if some slots represent deleted properties |
| 7391 | // (their names are the null value). |
| 7392 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7393 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7394 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7395 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7396 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7397 | } |
| 7398 | __ and_(scratch, Operand(esp, 0)); |
| 7399 | |
| 7400 | // Scale the index by multiplying by the entry size. |
| 7401 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7402 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7403 | |
| 7404 | // Having undefined at this place means the name is not contained. |
| 7405 | ASSERT_EQ(kSmiTagSize, 1); |
| 7406 | __ mov(scratch, Operand(dictionary_, |
| 7407 | index_, |
| 7408 | times_pointer_size, |
| 7409 | kElementsStartOffset - kHeapObjectTag)); |
| 7410 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7411 | __ j(equal, ¬_in_dictionary); |
| 7412 | |
| 7413 | // Stop if found the property. |
| 7414 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7415 | __ j(equal, &in_dictionary); |
| 7416 | |
| 7417 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7418 | // If we hit a key that is not an internalized string during negative |
| 7419 | // 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] | 7420 | // key we are looking for. |
| 7421 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7422 | // Check if the entry name is not an internalized string. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7423 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7424 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 7425 | kIsInternalizedMask); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7426 | __ j(zero, &maybe_in_dictionary); |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | __ bind(&maybe_in_dictionary); |
| 7431 | // If we are doing negative lookup then probing failure should be |
| 7432 | // treated as a lookup success. For positive lookup probing failure |
| 7433 | // should be treated as lookup failure. |
| 7434 | if (mode_ == POSITIVE_LOOKUP) { |
| 7435 | __ mov(result_, Immediate(0)); |
| 7436 | __ Drop(1); |
| 7437 | __ ret(2 * kPointerSize); |
| 7438 | } |
| 7439 | |
| 7440 | __ bind(&in_dictionary); |
| 7441 | __ mov(result_, Immediate(1)); |
| 7442 | __ Drop(1); |
| 7443 | __ ret(2 * kPointerSize); |
| 7444 | |
| 7445 | __ bind(¬_in_dictionary); |
| 7446 | __ mov(result_, Immediate(0)); |
| 7447 | __ Drop(1); |
| 7448 | __ ret(2 * kPointerSize); |
| 7449 | } |
| 7450 | |
| 7451 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7452 | struct AheadOfTimeWriteBarrierStubList { |
| 7453 | Register object, value, address; |
| 7454 | RememberedSetAction action; |
| 7455 | }; |
| 7456 | |
| 7457 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7458 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7459 | |
| 7460 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7461 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7462 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7463 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7464 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7465 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7466 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7467 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7468 | // Used in StoreStubCompiler::CompileStoreField and |
| 7469 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7470 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7471 | // GenerateStoreField calls the stub with two different permutations of |
| 7472 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7473 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7474 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7475 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7476 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7477 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7478 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7479 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7480 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7481 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7482 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7483 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7484 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7485 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7486 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7487 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7488 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7489 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7490 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7491 | // FastNewClosureStub |
| 7492 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7493 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7494 | { 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] | 7495 | }; |
| 7496 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7497 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7498 | |
| 7499 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7500 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7501 | !entry->object.is(no_reg); |
| 7502 | entry++) { |
| 7503 | if (object_.is(entry->object) && |
| 7504 | value_.is(entry->value) && |
| 7505 | address_.is(entry->address) && |
| 7506 | remembered_set_action_ == entry->action && |
| 7507 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7508 | return true; |
| 7509 | } |
| 7510 | } |
| 7511 | return false; |
| 7512 | } |
| 7513 | |
| 7514 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7515 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7516 | Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7517 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7518 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7519 | |
| 7520 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7521 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7522 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7523 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7524 | } |
| 7525 | } |
| 7526 | |
| 7527 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7528 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7529 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7530 | !entry->object.is(no_reg); |
| 7531 | entry++) { |
| 7532 | RecordWriteStub stub(entry->object, |
| 7533 | entry->value, |
| 7534 | entry->address, |
| 7535 | entry->action, |
| 7536 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7537 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7538 | } |
| 7539 | } |
| 7540 | |
| 7541 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7542 | bool CodeStub::CanUseFPRegisters() { |
| 7543 | return CpuFeatures::IsSupported(SSE2); |
| 7544 | } |
| 7545 | |
| 7546 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7547 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7548 | // the value has just been written into the object, now this stub makes sure |
| 7549 | // we keep the GC informed. The word in the object where the value has been |
| 7550 | // written is in the address register. |
| 7551 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7552 | Label skip_to_incremental_noncompacting; |
| 7553 | Label skip_to_incremental_compacting; |
| 7554 | |
| 7555 | // The first two instructions are generated with labels so as to get the |
| 7556 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7557 | // forth between a compare instructions (a nop in this position) and the |
| 7558 | // real branch when we start and stop incremental heap marking. |
| 7559 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7560 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7561 | |
| 7562 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7563 | __ RememberedSetHelper(object_, |
| 7564 | address_, |
| 7565 | value_, |
| 7566 | save_fp_regs_mode_, |
| 7567 | MacroAssembler::kReturnAtEnd); |
| 7568 | } else { |
| 7569 | __ ret(0); |
| 7570 | } |
| 7571 | |
| 7572 | __ bind(&skip_to_incremental_noncompacting); |
| 7573 | GenerateIncremental(masm, INCREMENTAL); |
| 7574 | |
| 7575 | __ bind(&skip_to_incremental_compacting); |
| 7576 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7577 | |
| 7578 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7579 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7580 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7581 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7582 | } |
| 7583 | |
| 7584 | |
| 7585 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7586 | regs_.Save(masm); |
| 7587 | |
| 7588 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7589 | Label dont_need_remembered_set; |
| 7590 | |
| 7591 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7592 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7593 | regs_.scratch0(), |
| 7594 | &dont_need_remembered_set); |
| 7595 | |
| 7596 | __ CheckPageFlag(regs_.object(), |
| 7597 | regs_.scratch0(), |
| 7598 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7599 | not_zero, |
| 7600 | &dont_need_remembered_set); |
| 7601 | |
| 7602 | // First notify the incremental marker if necessary, then update the |
| 7603 | // remembered set. |
| 7604 | CheckNeedsToInformIncrementalMarker( |
| 7605 | masm, |
| 7606 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7607 | mode); |
| 7608 | InformIncrementalMarker(masm, mode); |
| 7609 | regs_.Restore(masm); |
| 7610 | __ RememberedSetHelper(object_, |
| 7611 | address_, |
| 7612 | value_, |
| 7613 | save_fp_regs_mode_, |
| 7614 | MacroAssembler::kReturnAtEnd); |
| 7615 | |
| 7616 | __ bind(&dont_need_remembered_set); |
| 7617 | } |
| 7618 | |
| 7619 | CheckNeedsToInformIncrementalMarker( |
| 7620 | masm, |
| 7621 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7622 | mode); |
| 7623 | InformIncrementalMarker(masm, mode); |
| 7624 | regs_.Restore(masm); |
| 7625 | __ ret(0); |
| 7626 | } |
| 7627 | |
| 7628 | |
| 7629 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7630 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7631 | int argument_count = 3; |
| 7632 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7633 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7634 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7635 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7636 | Immediate(ExternalReference::isolate_address())); |
| 7637 | |
| 7638 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7639 | if (mode == INCREMENTAL_COMPACTION) { |
| 7640 | __ CallCFunction( |
| 7641 | ExternalReference::incremental_evacuation_record_write_function( |
| 7642 | masm->isolate()), |
| 7643 | argument_count); |
| 7644 | } else { |
| 7645 | ASSERT(mode == INCREMENTAL); |
| 7646 | __ CallCFunction( |
| 7647 | ExternalReference::incremental_marking_record_write_function( |
| 7648 | masm->isolate()), |
| 7649 | argument_count); |
| 7650 | } |
| 7651 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7652 | } |
| 7653 | |
| 7654 | |
| 7655 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7656 | MacroAssembler* masm, |
| 7657 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7658 | Mode mode) { |
| 7659 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7660 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7661 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7662 | __ and_(regs_.scratch0(), regs_.object()); |
| 7663 | __ mov(regs_.scratch1(), |
| 7664 | Operand(regs_.scratch0(), |
| 7665 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7666 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7667 | __ mov(Operand(regs_.scratch0(), |
| 7668 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7669 | regs_.scratch1()); |
| 7670 | __ j(negative, &need_incremental); |
| 7671 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7672 | // Let's look at the color of the object: If it is not black we don't have |
| 7673 | // to inform the incremental marker. |
| 7674 | __ JumpIfBlack(regs_.object(), |
| 7675 | regs_.scratch0(), |
| 7676 | regs_.scratch1(), |
| 7677 | &object_is_black, |
| 7678 | Label::kNear); |
| 7679 | |
| 7680 | regs_.Restore(masm); |
| 7681 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7682 | __ RememberedSetHelper(object_, |
| 7683 | address_, |
| 7684 | value_, |
| 7685 | save_fp_regs_mode_, |
| 7686 | MacroAssembler::kReturnAtEnd); |
| 7687 | } else { |
| 7688 | __ ret(0); |
| 7689 | } |
| 7690 | |
| 7691 | __ bind(&object_is_black); |
| 7692 | |
| 7693 | // Get the value from the slot. |
| 7694 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7695 | |
| 7696 | if (mode == INCREMENTAL_COMPACTION) { |
| 7697 | Label ensure_not_white; |
| 7698 | |
| 7699 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7700 | regs_.scratch1(), // Scratch. |
| 7701 | MemoryChunk::kEvacuationCandidateMask, |
| 7702 | zero, |
| 7703 | &ensure_not_white, |
| 7704 | Label::kNear); |
| 7705 | |
| 7706 | __ CheckPageFlag(regs_.object(), |
| 7707 | regs_.scratch1(), // Scratch. |
| 7708 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7709 | not_zero, |
| 7710 | &ensure_not_white, |
| 7711 | Label::kNear); |
| 7712 | |
| 7713 | __ jmp(&need_incremental); |
| 7714 | |
| 7715 | __ bind(&ensure_not_white); |
| 7716 | } |
| 7717 | |
| 7718 | // We need an extra register for this, so we push the object register |
| 7719 | // temporarily. |
| 7720 | __ push(regs_.object()); |
| 7721 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7722 | regs_.scratch1(), // Scratch. |
| 7723 | regs_.object(), // Scratch. |
| 7724 | &need_incremental_pop_object, |
| 7725 | Label::kNear); |
| 7726 | __ pop(regs_.object()); |
| 7727 | |
| 7728 | regs_.Restore(masm); |
| 7729 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7730 | __ RememberedSetHelper(object_, |
| 7731 | address_, |
| 7732 | value_, |
| 7733 | save_fp_regs_mode_, |
| 7734 | MacroAssembler::kReturnAtEnd); |
| 7735 | } else { |
| 7736 | __ ret(0); |
| 7737 | } |
| 7738 | |
| 7739 | __ bind(&need_incremental_pop_object); |
| 7740 | __ pop(regs_.object()); |
| 7741 | |
| 7742 | __ bind(&need_incremental); |
| 7743 | |
| 7744 | // Fall through when we need to inform the incremental marker. |
| 7745 | } |
| 7746 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7747 | |
| 7748 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7749 | // ----------- S t a t e ------------- |
| 7750 | // -- eax : element value to store |
| 7751 | // -- ebx : array literal |
| 7752 | // -- edi : map of array literal |
| 7753 | // -- ecx : element index as smi |
| 7754 | // -- edx : array literal index in function |
| 7755 | // -- esp[0] : return address |
| 7756 | // ----------------------------------- |
| 7757 | |
| 7758 | Label element_done; |
| 7759 | Label double_elements; |
| 7760 | Label smi_element; |
| 7761 | Label slow_elements; |
| 7762 | Label slow_elements_from_double; |
| 7763 | Label fast_elements; |
| 7764 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7765 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7766 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7767 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7768 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7769 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7770 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7771 | // Store into the array literal requires a elements transition. Call into |
| 7772 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7773 | |
| 7774 | __ bind(&slow_elements); |
| 7775 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7776 | // call. |
| 7777 | __ push(ebx); |
| 7778 | __ push(ecx); |
| 7779 | __ push(eax); |
| 7780 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7781 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7782 | __ push(edx); |
| 7783 | __ push(edi); // Return return address so that tail call returns to right |
| 7784 | // place. |
| 7785 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7786 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7787 | __ bind(&slow_elements_from_double); |
| 7788 | __ pop(edx); |
| 7789 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7790 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7791 | // 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] | 7792 | __ bind(&fast_elements); |
| 7793 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7794 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7795 | FixedArrayBase::kHeaderSize)); |
| 7796 | __ mov(Operand(ecx, 0), eax); |
| 7797 | // Update the write barrier for the array store. |
| 7798 | __ RecordWrite(ebx, ecx, eax, |
| 7799 | kDontSaveFPRegs, |
| 7800 | EMIT_REMEMBERED_SET, |
| 7801 | OMIT_SMI_CHECK); |
| 7802 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7803 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7804 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7805 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7806 | __ bind(&smi_element); |
| 7807 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7808 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7809 | FixedArrayBase::kHeaderSize), eax); |
| 7810 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7811 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7812 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7813 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7814 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7815 | __ push(edx); |
| 7816 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7817 | __ StoreNumberToDoubleElements(eax, |
| 7818 | edx, |
| 7819 | ecx, |
| 7820 | edi, |
| 7821 | xmm0, |
| 7822 | &slow_elements_from_double, |
| 7823 | false); |
| 7824 | __ pop(edx); |
| 7825 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7826 | } |
| 7827 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7828 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7829 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7830 | ASSERT(!Serializer::enabled()); |
| 7831 | bool save_fp_regs = CpuFeatures::IsSupported(SSE2); |
| 7832 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7833 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7834 | int parameter_count_offset = |
| 7835 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7836 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7837 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7838 | __ pop(ecx); |
| 7839 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, |
| 7840 | extra_expression_stack_count_ * kPointerSize)); |
| 7841 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7842 | } |
| 7843 | |
| 7844 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7845 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7846 | if (entry_hook_ != NULL) { |
| 7847 | ProfileEntryHookStub stub; |
| 7848 | masm->CallStub(&stub); |
| 7849 | } |
| 7850 | } |
| 7851 | |
| 7852 | |
| 7853 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7854 | // Ecx is the only volatile register we must save. |
| 7855 | __ push(ecx); |
| 7856 | |
| 7857 | // Calculate and push the original stack pointer. |
| 7858 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7859 | __ push(eax); |
| 7860 | |
| 7861 | // Calculate and push the function address. |
| 7862 | __ mov(eax, Operand(eax, 0)); |
| 7863 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7864 | __ push(eax); |
| 7865 | |
| 7866 | // Call the entry hook. |
| 7867 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7868 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7869 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7870 | |
| 7871 | // Restore ecx. |
| 7872 | __ pop(ecx); |
| 7873 | __ ret(0); |
| 7874 | } |
| 7875 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7876 | #undef __ |
| 7877 | |
| 7878 | } } // namespace v8::internal |
| 7879 | |
| 7880 | #endif // V8_TARGET_ARCH_IA32 |