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 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 70 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 71 | Isolate* isolate, |
| 72 | CodeStubInterfaceDescriptor* descriptor) { |
| 73 | static Register registers[] = { edx, ecx, eax }; |
| 74 | descriptor->register_param_count_ = 3; |
| 75 | descriptor->register_params_ = registers; |
| 76 | descriptor->deoptimization_handler_ = |
| 77 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 78 | } |
| 79 | |
| 80 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 81 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 82 | Isolate* isolate, |
| 83 | CodeStubInterfaceDescriptor* descriptor) { |
| 84 | static Register registers[] = { eax, ebx }; |
| 85 | descriptor->register_param_count_ = 2; |
| 86 | descriptor->register_params_ = registers; |
| 87 | descriptor->deoptimization_handler_ = |
| 88 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 89 | } |
| 90 | |
| 91 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 92 | static void InitializeArrayConstructorDescriptor(Isolate* isolate, |
| 93 | CodeStubInterfaceDescriptor* descriptor) { |
| 94 | // register state |
| 95 | // edi -- constructor function |
| 96 | // ebx -- type info cell with elements kind |
| 97 | // eax -- number of arguments to the constructor function |
| 98 | static Register registers[] = { edi, ebx }; |
| 99 | descriptor->register_param_count_ = 2; |
| 100 | // stack param count needs (constructor pointer, and single argument) |
| 101 | descriptor->stack_parameter_count_ = &eax; |
| 102 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 103 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 104 | descriptor->deoptimization_handler_ = |
| 105 | FUNCTION_ADDR(ArrayConstructor_StubFailure); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 110 | Isolate* isolate, |
| 111 | CodeStubInterfaceDescriptor* descriptor) { |
| 112 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 117 | Isolate* isolate, |
| 118 | CodeStubInterfaceDescriptor* descriptor) { |
| 119 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 124 | Isolate* isolate, |
| 125 | CodeStubInterfaceDescriptor* descriptor) { |
| 126 | InitializeArrayConstructorDescriptor(isolate, descriptor); |
| 127 | } |
| 128 | |
| 129 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 130 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 131 | |
| 132 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 133 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 134 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 135 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 136 | __ ret(0); |
| 137 | |
| 138 | __ bind(&check_heap_number); |
| 139 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 140 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 141 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 142 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 143 | __ ret(0); |
| 144 | |
| 145 | __ bind(&call_builtin); |
| 146 | __ pop(ecx); // Pop return address. |
| 147 | __ push(eax); |
| 148 | __ push(ecx); // Push return address. |
| 149 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 150 | } |
| 151 | |
| 152 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 153 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 154 | // Create a new closure from the given function info in new |
| 155 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 156 | Counters* counters = masm->isolate()->counters(); |
| 157 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 158 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 159 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 160 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 161 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 162 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 163 | // Get the function info from the stack. |
| 164 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 165 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 166 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 167 | ? Context::FUNCTION_MAP_INDEX |
| 168 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 169 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 170 | // 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] | 171 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 172 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 173 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 174 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 175 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 176 | |
| 177 | // Initialize the rest of the function. We don't have to update the |
| 178 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 179 | Factory* factory = masm->isolate()->factory(); |
| 180 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 181 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 182 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 183 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 184 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 185 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 186 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 187 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 188 | |
| 189 | // Initialize the code pointer in the function to be the one |
| 190 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 191 | // But first check if there is an optimized version for our context. |
| 192 | Label check_optimized; |
| 193 | Label install_unoptimized; |
| 194 | if (FLAG_cache_optimized_code) { |
| 195 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 196 | __ test(ebx, ebx); |
| 197 | __ j(not_zero, &check_optimized, Label::kNear); |
| 198 | } |
| 199 | __ bind(&install_unoptimized); |
| 200 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 201 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 202 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 203 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 204 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 205 | |
| 206 | // Return and remove the on-stack parameter. |
| 207 | __ ret(1 * kPointerSize); |
| 208 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 209 | __ bind(&check_optimized); |
| 210 | |
| 211 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 212 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 213 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 214 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 215 | // Map must never be empty, so check the first elements. |
| 216 | Label install_optimized; |
| 217 | // Speculatively move code object into edx. |
| 218 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 219 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 220 | __ j(equal, &install_optimized); |
| 221 | |
| 222 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 223 | Label loop; |
| 224 | Label restore; |
| 225 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 226 | __ bind(&loop); |
| 227 | // Do not double check first entry. |
| 228 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 229 | __ j(equal, &restore); |
| 230 | __ sub(edx, Immediate(Smi::FromInt( |
| 231 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 232 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 233 | __ j(not_equal, &loop, Label::kNear); |
| 234 | // Hit: fetch the optimized code. |
| 235 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 236 | |
| 237 | __ bind(&install_optimized); |
| 238 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 239 | |
| 240 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 241 | // map and either unmangle them on marking or do nothing as the whole map is |
| 242 | // discarded on major GC anyway. |
| 243 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 244 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 245 | |
| 246 | // Now link a function into a list of optimized functions. |
| 247 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 248 | |
| 249 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 250 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 251 | |
| 252 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 253 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 254 | // it clobbers all the registers passed. |
| 255 | __ mov(edx, eax); |
| 256 | __ RecordWriteContextSlot( |
| 257 | ecx, |
| 258 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 259 | edx, |
| 260 | ebx, |
| 261 | kDontSaveFPRegs); |
| 262 | |
| 263 | // Return and remove the on-stack parameter. |
| 264 | __ ret(1 * kPointerSize); |
| 265 | |
| 266 | __ bind(&restore); |
| 267 | // Restore SharedFunctionInfo into edx. |
| 268 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 269 | __ jmp(&install_unoptimized); |
| 270 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 271 | // Create a new closure through the slower runtime call. |
| 272 | __ bind(&gc); |
| 273 | __ pop(ecx); // Temporarily remove return address. |
| 274 | __ pop(edx); |
| 275 | __ push(esi); |
| 276 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 277 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 278 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 279 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 284 | // Try to allocate the context in new space. |
| 285 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 286 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 287 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 288 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 289 | |
| 290 | // Get the function from the stack. |
| 291 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 292 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 293 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 294 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 295 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 296 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 297 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 298 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 299 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 300 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 301 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 302 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 303 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 304 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 305 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 306 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 307 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 308 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 309 | |
| 310 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 311 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 312 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 313 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 314 | } |
| 315 | |
| 316 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 317 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 318 | __ ret(1 * kPointerSize); |
| 319 | |
| 320 | // Need to collect. Call into runtime system. |
| 321 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 322 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 326 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 327 | // Stack layout on entry: |
| 328 | // |
| 329 | // [esp + (1 * kPointerSize)]: function |
| 330 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 331 | |
| 332 | // Try to allocate the context in new space. |
| 333 | Label gc; |
| 334 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 335 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 336 | |
| 337 | // Get the function or sentinel from the stack. |
| 338 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 339 | |
| 340 | // Get the serialized scope info from the stack. |
| 341 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 342 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 343 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 344 | Factory* factory = masm->isolate()->factory(); |
| 345 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 346 | factory->block_context_map()); |
| 347 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 348 | Immediate(Smi::FromInt(length))); |
| 349 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 350 | // 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] | 351 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 352 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 353 | // we still have to look up. |
| 354 | Label after_sentinel; |
| 355 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 356 | if (FLAG_debug_code) { |
| 357 | const char* message = "Expected 0 as a Smi sentinel"; |
| 358 | __ cmp(ecx, 0); |
| 359 | __ Assert(equal, message); |
| 360 | } |
| 361 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 362 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 363 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 364 | __ bind(&after_sentinel); |
| 365 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 366 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 367 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 368 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 369 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 370 | |
| 371 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 372 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 373 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 374 | |
| 375 | // Initialize the rest of the slots to the hole value. |
| 376 | if (slots_ == 1) { |
| 377 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 378 | factory->the_hole_value()); |
| 379 | } else { |
| 380 | __ mov(ebx, factory->the_hole_value()); |
| 381 | for (int i = 0; i < slots_; i++) { |
| 382 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // Return and remove the on-stack parameters. |
| 387 | __ mov(esi, eax); |
| 388 | __ ret(2 * kPointerSize); |
| 389 | |
| 390 | // Need to collect. Call into runtime system. |
| 391 | __ bind(&gc); |
| 392 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 393 | } |
| 394 | |
| 395 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 396 | static void GenerateFastCloneShallowArrayCommon( |
| 397 | MacroAssembler* masm, |
| 398 | int length, |
| 399 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 400 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 401 | Label* fail) { |
| 402 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 403 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 404 | // ecx: boilerplate literal array. |
| 405 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 406 | |
| 407 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 408 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 409 | if (length > 0) { |
| 410 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 411 | ? FixedDoubleArray::SizeFor(length) |
| 412 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 413 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 414 | int size = JSArray::kSize; |
| 415 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 416 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 417 | size += AllocationSiteInfo::kSize; |
| 418 | } |
| 419 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 420 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 421 | // Allocate both the JS array and the elements array in one big |
| 422 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 423 | AllocationFlags flags = TAG_OBJECT; |
| 424 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 425 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 426 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 427 | __ Allocate(size, eax, ebx, edx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 428 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 429 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 430 | __ mov(FieldOperand(eax, allocation_info_start), |
| 431 | Immediate(Handle<Map>(masm->isolate()->heap()-> |
| 432 | allocation_site_info_map()))); |
| 433 | __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); |
| 434 | } |
| 435 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 436 | // Copy the JS array part. |
| 437 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 438 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 439 | __ mov(ebx, FieldOperand(ecx, i)); |
| 440 | __ mov(FieldOperand(eax, i), ebx); |
| 441 | } |
| 442 | } |
| 443 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 444 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 445 | // Get hold of the elements array of the boilerplate and setup the |
| 446 | // elements pointer in the resulting object. |
| 447 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 448 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 449 | __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 450 | } else { |
| 451 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 452 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 453 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 454 | |
| 455 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 456 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 457 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 458 | __ mov(ebx, FieldOperand(ecx, i)); |
| 459 | __ mov(FieldOperand(edx, i), ebx); |
| 460 | } |
| 461 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 462 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 463 | int i; |
| 464 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 465 | __ mov(ebx, FieldOperand(ecx, i)); |
| 466 | __ mov(FieldOperand(edx, i), ebx); |
| 467 | } |
| 468 | while (i < elements_size) { |
| 469 | __ fld_d(FieldOperand(ecx, i)); |
| 470 | __ fstp_d(FieldOperand(edx, i)); |
| 471 | i += kDoubleSize; |
| 472 | } |
| 473 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 476 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 477 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 478 | |
| 479 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 480 | // Stack layout on entry: |
| 481 | // |
| 482 | // [esp + kPointerSize]: constant elements. |
| 483 | // [esp + (2 * kPointerSize)]: literal index. |
| 484 | // [esp + (3 * kPointerSize)]: literals array. |
| 485 | |
| 486 | // Load boilerplate object into ecx and check if we need to create a |
| 487 | // boilerplate. |
| 488 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 489 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 490 | STATIC_ASSERT(kPointerSize == 4); |
| 491 | STATIC_ASSERT(kSmiTagSize == 1); |
| 492 | STATIC_ASSERT(kSmiTag == 0); |
| 493 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 494 | FixedArray::kHeaderSize)); |
| 495 | Factory* factory = masm->isolate()->factory(); |
| 496 | __ cmp(ecx, factory->undefined_value()); |
| 497 | Label slow_case; |
| 498 | __ j(equal, &slow_case); |
| 499 | |
| 500 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 501 | // ecx is boilerplate object. |
| 502 | if (mode == CLONE_ANY_ELEMENTS) { |
| 503 | Label double_elements, check_fast_elements; |
| 504 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 505 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 506 | &check_fast_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 507 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 508 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 509 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 510 | __ ret(3 * kPointerSize); |
| 511 | |
| 512 | __ bind(&check_fast_elements); |
| 513 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 514 | &double_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 515 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 516 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 517 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 518 | __ ret(3 * kPointerSize); |
| 519 | |
| 520 | __ bind(&double_elements); |
| 521 | mode = CLONE_DOUBLE_ELEMENTS; |
| 522 | // Fall through to generate the code to handle double elements. |
| 523 | } |
| 524 | |
| 525 | if (FLAG_debug_code) { |
| 526 | const char* message; |
| 527 | Handle<Map> expected_map; |
| 528 | if (mode == CLONE_ELEMENTS) { |
| 529 | message = "Expected (writable) fixed array"; |
| 530 | expected_map = factory->fixed_array_map(); |
| 531 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 532 | message = "Expected (writable) fixed double array"; |
| 533 | expected_map = factory->fixed_double_array_map(); |
| 534 | } else { |
| 535 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 536 | message = "Expected copy-on-write fixed array"; |
| 537 | expected_map = factory->fixed_cow_array_map(); |
| 538 | } |
| 539 | __ push(ecx); |
| 540 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 541 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 542 | __ Assert(equal, message); |
| 543 | __ pop(ecx); |
| 544 | } |
| 545 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 546 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 547 | allocation_site_mode_, |
| 548 | &slow_case); |
| 549 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 550 | // Return and remove the on-stack parameters. |
| 551 | __ ret(3 * kPointerSize); |
| 552 | |
| 553 | __ bind(&slow_case); |
| 554 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 555 | } |
| 556 | |
| 557 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 558 | // The stub expects its argument on the stack and returns its result in tos_: |
| 559 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 560 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 561 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 562 | // 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] | 563 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 564 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 565 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 566 | const Register map = edx; |
| 567 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 568 | if (!types_.IsEmpty()) { |
| 569 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 570 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 571 | |
| 572 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 573 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 574 | |
| 575 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 576 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 577 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 578 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 579 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 580 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 581 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 582 | if (types_.Contains(SMI)) { |
| 583 | // Smis: 0 -> false, all other -> true |
| 584 | Label not_smi; |
| 585 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 586 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 587 | if (!tos_.is(argument)) { |
| 588 | __ mov(tos_, argument); |
| 589 | } |
| 590 | __ ret(1 * kPointerSize); |
| 591 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 592 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 593 | // If we need a map later and have a Smi -> patch. |
| 594 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 595 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 596 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 597 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 598 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 599 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 600 | if (types_.CanBeUndetectable()) { |
| 601 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 602 | 1 << Map::kIsUndetectable); |
| 603 | // Undetectable -> false. |
| 604 | Label not_undetectable; |
| 605 | __ j(zero, ¬_undetectable, Label::kNear); |
| 606 | __ Set(tos_, Immediate(0)); |
| 607 | __ ret(1 * kPointerSize); |
| 608 | __ bind(¬_undetectable); |
| 609 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 610 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 611 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 612 | if (types_.Contains(SPEC_OBJECT)) { |
| 613 | // spec object -> true. |
| 614 | Label not_js_object; |
| 615 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 616 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 617 | // argument contains the correct return value already. |
| 618 | if (!tos_.is(argument)) { |
| 619 | __ Set(tos_, Immediate(1)); |
| 620 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 621 | __ ret(1 * kPointerSize); |
| 622 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 623 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 624 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 625 | if (types_.Contains(STRING)) { |
| 626 | // String value -> false iff empty. |
| 627 | Label not_string; |
| 628 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 629 | __ j(above_equal, ¬_string, Label::kNear); |
| 630 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 631 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 632 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 633 | } |
| 634 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 635 | if (types_.Contains(SYMBOL)) { |
| 636 | // Symbol value -> true. |
| 637 | Label not_symbol; |
| 638 | __ CmpInstanceType(map, SYMBOL_TYPE); |
| 639 | __ j(not_equal, ¬_symbol, Label::kNear); |
| 640 | __ bind(¬_symbol); |
| 641 | } |
| 642 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 643 | if (types_.Contains(HEAP_NUMBER)) { |
| 644 | // heap number -> false iff +0, -0, or NaN. |
| 645 | Label not_heap_number, false_result; |
| 646 | __ cmp(map, factory->heap_number_map()); |
| 647 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 648 | __ fldz(); |
| 649 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 650 | __ FCmp(); |
| 651 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 652 | // argument contains the correct return value already. |
| 653 | if (!tos_.is(argument)) { |
| 654 | __ Set(tos_, Immediate(1)); |
| 655 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 656 | __ ret(1 * kPointerSize); |
| 657 | __ bind(&false_result); |
| 658 | __ Set(tos_, Immediate(0)); |
| 659 | __ ret(1 * kPointerSize); |
| 660 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 661 | } |
| 662 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 663 | __ bind(&patch); |
| 664 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 668 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 669 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 670 | // store the registers in any particular way, but we do have to store and |
| 671 | // restore them. |
| 672 | __ pushad(); |
| 673 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 674 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 675 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 676 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 677 | XMMRegister reg = XMMRegister::from_code(i); |
| 678 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 679 | } |
| 680 | } |
| 681 | const int argument_count = 1; |
| 682 | |
| 683 | AllowExternalCallThatCantCauseGC scope(masm); |
| 684 | __ PrepareCallCFunction(argument_count, ecx); |
| 685 | __ mov(Operand(esp, 0 * kPointerSize), |
| 686 | Immediate(ExternalReference::isolate_address())); |
| 687 | __ CallCFunction( |
| 688 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 689 | argument_count); |
| 690 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 691 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 692 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 693 | XMMRegister reg = XMMRegister::from_code(i); |
| 694 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 695 | } |
| 696 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 697 | } |
| 698 | __ popad(); |
| 699 | __ ret(0); |
| 700 | } |
| 701 | |
| 702 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 703 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 704 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 705 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 706 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 707 | const Register argument = eax; |
| 708 | if (types_.Contains(type)) { |
| 709 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 710 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 711 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 712 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 713 | if (!result) { |
| 714 | // If we have to return zero, there is no way around clearing tos_. |
| 715 | __ Set(tos_, Immediate(0)); |
| 716 | } else if (!tos_.is(argument)) { |
| 717 | // If we have to return non-zero, we can re-use the argument if it is the |
| 718 | // same register as the result, because we never see Smi-zero here. |
| 719 | __ Set(tos_, Immediate(1)); |
| 720 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 721 | __ ret(1 * kPointerSize); |
| 722 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
| 726 | |
| 727 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 728 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 729 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 730 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 731 | __ push(ecx); // Push return address. |
| 732 | // Patch the caller to an appropriate specialized stub and return the |
| 733 | // operation result to the caller of the stub. |
| 734 | __ TailCallExternalReference( |
| 735 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 736 | 3, |
| 737 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 741 | class FloatingPointHelper : public AllStatic { |
| 742 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 743 | enum ArgLocation { |
| 744 | ARGS_ON_STACK, |
| 745 | ARGS_IN_REGISTERS |
| 746 | }; |
| 747 | |
| 748 | // Code pattern for loading a floating point value. Input value must |
| 749 | // be either a smi or a heap number object (fp value). Requirements: |
| 750 | // operand in register number. Returns operand as floating point number |
| 751 | // on FPU stack. |
| 752 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 753 | |
| 754 | // Code pattern for loading floating point values. Input values must |
| 755 | // be either smi or heap number objects (fp values). Requirements: |
| 756 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 757 | // Returns operands as floating point numbers on FPU stack. |
| 758 | static void LoadFloatOperands(MacroAssembler* masm, |
| 759 | Register scratch, |
| 760 | ArgLocation arg_location = ARGS_ON_STACK); |
| 761 | |
| 762 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 763 | // Expects operands in edx, eax. |
| 764 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 765 | |
| 766 | // Test if operands are smi or number objects (fp). Requirements: |
| 767 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 768 | // operands, jumps to the non_float label otherwise. |
| 769 | static void CheckFloatOperands(MacroAssembler* masm, |
| 770 | Label* non_float, |
| 771 | Register scratch); |
| 772 | |
| 773 | // Takes the operands in edx and eax and loads them as integers in eax |
| 774 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 775 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 776 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 777 | BinaryOpIC::TypeInfo left_type, |
| 778 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 779 | Label* operand_conversion_failure); |
| 780 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 781 | // Assumes that operands are smis or heap numbers and loads them |
| 782 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 783 | // Leaves operands unchanged. |
| 784 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 785 | |
| 786 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 787 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 788 | // either operand is not a number. Operands are in edx and eax. |
| 789 | // Leaves operands unchanged. |
| 790 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 791 | |
| 792 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 793 | // Expects operands in edx, eax. |
| 794 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 795 | |
| 796 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 797 | // have int32 values. |
| 798 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 799 | Label* non_int32, |
| 800 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 801 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 802 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 803 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 804 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 805 | Label* non_int32, |
| 806 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 807 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 808 | Register scratch, |
| 809 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 810 | }; |
| 811 | |
| 812 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 813 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 814 | // is faster than using the built-in instructions on floating point registers. |
| 815 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 816 | // trashed registers. |
| 817 | static void IntegerConvert(MacroAssembler* masm, |
| 818 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 819 | bool use_sse3, |
| 820 | Label* conversion_failure) { |
| 821 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 822 | Label done, right_exponent, normal_exponent; |
| 823 | Register scratch = ebx; |
| 824 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 825 | // Get exponent word. |
| 826 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 827 | // Get exponent alone in scratch2. |
| 828 | __ mov(scratch2, scratch); |
| 829 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 830 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 831 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 832 | // Load ecx with zero. We use this either for the final shift or |
| 833 | // for the answer. |
| 834 | __ xor_(ecx, ecx); |
| 835 | // If the exponent is above 83, the number contains no significant |
| 836 | // bits in the range 0..2^31, so the result is zero. |
| 837 | static const uint32_t kResultIsZeroExponent = 83; |
| 838 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 839 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | if (use_sse3) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 841 | CpuFeatureScope scope(masm, SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 842 | // 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] | 843 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 844 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 845 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 846 | // Load x87 register with heap number. |
| 847 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 848 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 849 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 850 | // Do conversion, which cannot fail because we checked the exponent. |
| 851 | __ fisttp_d(Operand(esp, 0)); |
| 852 | __ 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] | 853 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 854 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 855 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 856 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 857 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 858 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 859 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 860 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 861 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 862 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 863 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 864 | // If the exponent is higher than that then go to slow case. This catches |
| 865 | // 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] | 866 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 867 | |
| 868 | { |
| 869 | // Handle a big exponent. The only reason we have this code is that the |
| 870 | // >>> 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] | 871 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 872 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 873 | __ j(not_equal, conversion_failure); |
| 874 | // We have the big exponent, typically from >>>. This means the number is |
| 875 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 876 | __ mov(scratch2, scratch); |
| 877 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 878 | // Put back the implicit 1. |
| 879 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 880 | // Shift up the mantissa bits to take up the space the exponent used to |
| 881 | // take. We just orred in the implicit bit so that took care of one and |
| 882 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 883 | // shift distance. |
| 884 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 885 | __ shl(scratch2, big_shift_distance); |
| 886 | // Get the second half of the double. |
| 887 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 888 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 889 | // mantissa word. |
| 890 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 891 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 892 | // 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] | 893 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 894 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 895 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 896 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 900 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 901 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 902 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 903 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 904 | |
| 905 | __ bind(&right_exponent); |
| 906 | // Here ecx is the shift, scratch is the exponent word. |
| 907 | // Get the top bits of the mantissa. |
| 908 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 909 | // Put back the implicit 1. |
| 910 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 911 | // Shift up the mantissa bits to take up the space the exponent used to |
| 912 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 913 | // word. Shift them to the top bits. |
| 914 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 915 | __ shl(scratch, shift_distance); |
| 916 | // Get the second half of the double. For some exponents we don't |
| 917 | // actually need this because the bits get shifted out again, but |
| 918 | // it's probably slower to test than just to do it. |
| 919 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 920 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 921 | // mantissa word. |
| 922 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 923 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 924 | // Move down according to the exponent. |
| 925 | __ shr_cl(scratch2); |
| 926 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 927 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 928 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 929 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 930 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 931 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 932 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 933 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 934 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 935 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 936 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 937 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 941 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 942 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 943 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 944 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 945 | Register source, |
| 946 | Label* conversion_failure) { |
| 947 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 948 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 949 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 950 | } |
| 951 | |
| 952 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 953 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 954 | const char* op_name = Token::Name(op_); |
| 955 | const char* overwrite_name = NULL; // Make g++ happy. |
| 956 | switch (mode_) { |
| 957 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 958 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 959 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 960 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 961 | op_name, |
| 962 | overwrite_name, |
| 963 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | |
| 967 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 968 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 969 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 970 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 971 | GenerateTypeTransition(masm); |
| 972 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 973 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 974 | GenerateSmiStub(masm); |
| 975 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 976 | case UnaryOpIC::NUMBER: |
| 977 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 978 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 979 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 980 | GenerateGenericStub(masm); |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 986 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 987 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 988 | |
| 989 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 990 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 991 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 992 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 993 | |
| 994 | __ push(ecx); // Push return address. |
| 995 | |
| 996 | // Patch the caller to an appropriate specialized stub and return the |
| 997 | // operation result to the caller of the stub. |
| 998 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 999 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1004 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1005 | switch (op_) { |
| 1006 | case Token::SUB: |
| 1007 | GenerateSmiStubSub(masm); |
| 1008 | break; |
| 1009 | case Token::BIT_NOT: |
| 1010 | GenerateSmiStubBitNot(masm); |
| 1011 | break; |
| 1012 | default: |
| 1013 | UNREACHABLE(); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1018 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1019 | Label non_smi, undo, slow; |
| 1020 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 1021 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1022 | __ bind(&undo); |
| 1023 | GenerateSmiCodeUndo(masm); |
| 1024 | __ bind(&non_smi); |
| 1025 | __ bind(&slow); |
| 1026 | GenerateTypeTransition(masm); |
| 1027 | } |
| 1028 | |
| 1029 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1030 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1031 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1032 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1033 | __ bind(&non_smi); |
| 1034 | GenerateTypeTransition(masm); |
| 1035 | } |
| 1036 | |
| 1037 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1038 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 1039 | Label* non_smi, |
| 1040 | Label* undo, |
| 1041 | Label* slow, |
| 1042 | Label::Distance non_smi_near, |
| 1043 | Label::Distance undo_near, |
| 1044 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1045 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1046 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1047 | |
| 1048 | // 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] | 1049 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1050 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1051 | |
| 1052 | // 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] | 1053 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1054 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1055 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1056 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1057 | __ ret(0); |
| 1058 | } |
| 1059 | |
| 1060 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1061 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1062 | MacroAssembler* masm, |
| 1063 | Label* non_smi, |
| 1064 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1065 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1066 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1067 | |
| 1068 | // Flip bits and revert inverted smi-tag. |
| 1069 | __ not_(eax); |
| 1070 | __ and_(eax, ~kSmiTagMask); |
| 1071 | __ ret(0); |
| 1072 | } |
| 1073 | |
| 1074 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1075 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1076 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1081 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1082 | switch (op_) { |
| 1083 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1084 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1085 | break; |
| 1086 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1087 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | default: |
| 1090 | UNREACHABLE(); |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1095 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1096 | Label non_smi, undo, slow, call_builtin; |
| 1097 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1098 | __ bind(&non_smi); |
| 1099 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1100 | __ bind(&undo); |
| 1101 | GenerateSmiCodeUndo(masm); |
| 1102 | __ bind(&slow); |
| 1103 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1104 | __ bind(&call_builtin); |
| 1105 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1109 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1110 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1111 | Label non_smi, slow; |
| 1112 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1113 | __ bind(&non_smi); |
| 1114 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1115 | __ bind(&slow); |
| 1116 | GenerateTypeTransition(masm); |
| 1117 | } |
| 1118 | |
| 1119 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1120 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1121 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1122 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1123 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1124 | __ j(not_equal, slow); |
| 1125 | |
| 1126 | if (mode_ == UNARY_OVERWRITE) { |
| 1127 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1128 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1129 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1130 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1131 | // edx: operand |
| 1132 | |
| 1133 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1134 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1135 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1136 | |
| 1137 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1138 | { |
| 1139 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1140 | __ push(edx); |
| 1141 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1142 | __ pop(edx); |
| 1143 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1144 | |
| 1145 | __ bind(&heapnumber_allocated); |
| 1146 | // eax: allocated 'empty' number |
| 1147 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1148 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1149 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1150 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1151 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1152 | } |
| 1153 | __ ret(0); |
| 1154 | } |
| 1155 | |
| 1156 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1157 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1158 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1159 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1160 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1161 | __ j(not_equal, slow); |
| 1162 | |
| 1163 | // 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] | 1164 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1165 | |
| 1166 | // 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] | 1167 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1168 | __ not_(ecx); |
| 1169 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1170 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1171 | |
| 1172 | // Tag the result as a smi and we're done. |
| 1173 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1174 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1175 | __ ret(0); |
| 1176 | |
| 1177 | // Try to store the result in a heap number. |
| 1178 | __ bind(&try_float); |
| 1179 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1180 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1181 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1182 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1183 | __ jmp(&heapnumber_allocated); |
| 1184 | |
| 1185 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1186 | { |
| 1187 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1188 | // Push the original HeapNumber on the stack. The integer value can't |
| 1189 | // be stored since it's untagged and not in the smi range (so we can't |
| 1190 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1191 | __ push(ebx); |
| 1192 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1193 | // New HeapNumber is in eax. |
| 1194 | __ pop(edx); |
| 1195 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1196 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1197 | // This conversion won't go slow-case. |
| 1198 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1199 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1200 | |
| 1201 | __ bind(&heapnumber_allocated); |
| 1202 | } |
| 1203 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1204 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1205 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1206 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1207 | } else { |
| 1208 | __ push(ecx); |
| 1209 | __ fild_s(Operand(esp, 0)); |
| 1210 | __ pop(ecx); |
| 1211 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1212 | } |
| 1213 | __ ret(0); |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1218 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1219 | switch (op_) { |
| 1220 | case Token::SUB: |
| 1221 | GenerateGenericStubSub(masm); |
| 1222 | break; |
| 1223 | case Token::BIT_NOT: |
| 1224 | GenerateGenericStubBitNot(masm); |
| 1225 | break; |
| 1226 | default: |
| 1227 | UNREACHABLE(); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1232 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1233 | Label non_smi, undo, slow; |
| 1234 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1235 | __ bind(&non_smi); |
| 1236 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1237 | __ bind(&undo); |
| 1238 | GenerateSmiCodeUndo(masm); |
| 1239 | __ bind(&slow); |
| 1240 | GenerateGenericCodeFallback(masm); |
| 1241 | } |
| 1242 | |
| 1243 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1244 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1245 | Label non_smi, slow; |
| 1246 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1247 | __ bind(&non_smi); |
| 1248 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1249 | __ bind(&slow); |
| 1250 | GenerateGenericCodeFallback(masm); |
| 1251 | } |
| 1252 | |
| 1253 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1254 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1255 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1256 | __ pop(ecx); // pop return address. |
| 1257 | __ push(eax); |
| 1258 | __ push(ecx); // push return address |
| 1259 | switch (op_) { |
| 1260 | case Token::SUB: |
| 1261 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1262 | break; |
| 1263 | case Token::BIT_NOT: |
| 1264 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1265 | break; |
| 1266 | default: |
| 1267 | UNREACHABLE(); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1272 | void BinaryOpStub::Initialize() { |
| 1273 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1274 | } |
| 1275 | |
| 1276 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1277 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1278 | __ pop(ecx); // Save return address. |
| 1279 | __ push(edx); |
| 1280 | __ push(eax); |
| 1281 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1282 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1283 | |
| 1284 | __ push(ecx); // Push return address. |
| 1285 | |
| 1286 | // Patch the caller to an appropriate specialized stub and return the |
| 1287 | // operation result to the caller of the stub. |
| 1288 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1289 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1290 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1291 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1292 | 1); |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | // Prepare for a type transition runtime call when the args are already on |
| 1297 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1298 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | __ pop(ecx); // Save return address. |
| 1300 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1301 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1302 | |
| 1303 | __ push(ecx); // Push return address. |
| 1304 | |
| 1305 | // Patch the caller to an appropriate specialized stub and return the |
| 1306 | // operation result to the caller of the stub. |
| 1307 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1308 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1309 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1310 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1311 | 1); |
| 1312 | } |
| 1313 | |
| 1314 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1315 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1316 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1317 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1318 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1319 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1320 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1321 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1322 | Comment load_comment(masm, "-- Load arguments"); |
| 1323 | Register left = edx; |
| 1324 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1325 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1326 | left = eax; |
| 1327 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1328 | __ mov(ebx, eax); |
| 1329 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | // 2. Prepare the smi check of both operands by oring them together. |
| 1334 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1335 | Label not_smis; |
| 1336 | Register combined = ecx; |
| 1337 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1338 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1339 | case Token::BIT_OR: |
| 1340 | // Perform the operation into eax and smi check the result. Preserve |
| 1341 | // eax in case the result is not a smi. |
| 1342 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1343 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1344 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1345 | combined = right; |
| 1346 | break; |
| 1347 | |
| 1348 | case Token::BIT_XOR: |
| 1349 | case Token::BIT_AND: |
| 1350 | case Token::ADD: |
| 1351 | case Token::SUB: |
| 1352 | case Token::MUL: |
| 1353 | case Token::DIV: |
| 1354 | case Token::MOD: |
| 1355 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1356 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1357 | break; |
| 1358 | |
| 1359 | case Token::SHL: |
| 1360 | case Token::SAR: |
| 1361 | case Token::SHR: |
| 1362 | // Move the right operand into ecx for the shift operation, use eax |
| 1363 | // for the smi check register. |
| 1364 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1365 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1366 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1367 | combined = right; |
| 1368 | break; |
| 1369 | |
| 1370 | default: |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | // 3. Perform the smi check of the operands. |
| 1375 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1376 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1377 | |
| 1378 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1379 | // eax and check the result if necessary. |
| 1380 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1381 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1382 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1383 | case Token::BIT_OR: |
| 1384 | // Nothing to do. |
| 1385 | break; |
| 1386 | |
| 1387 | case Token::BIT_XOR: |
| 1388 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1389 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1390 | break; |
| 1391 | |
| 1392 | case Token::BIT_AND: |
| 1393 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1394 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | |
| 1397 | case Token::SHL: |
| 1398 | // Remove tags from operands (but keep sign). |
| 1399 | __ SmiUntag(left); |
| 1400 | __ SmiUntag(ecx); |
| 1401 | // Perform the operation. |
| 1402 | __ shl_cl(left); |
| 1403 | // Check that the *signed* result fits in a smi. |
| 1404 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1405 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1406 | // Tag the result and store it in register eax. |
| 1407 | __ SmiTag(left); |
| 1408 | __ mov(eax, left); |
| 1409 | break; |
| 1410 | |
| 1411 | case Token::SAR: |
| 1412 | // Remove tags from operands (but keep sign). |
| 1413 | __ SmiUntag(left); |
| 1414 | __ SmiUntag(ecx); |
| 1415 | // Perform the operation. |
| 1416 | __ sar_cl(left); |
| 1417 | // Tag the result and store it in register eax. |
| 1418 | __ SmiTag(left); |
| 1419 | __ mov(eax, left); |
| 1420 | break; |
| 1421 | |
| 1422 | case Token::SHR: |
| 1423 | // Remove tags from operands (but keep sign). |
| 1424 | __ SmiUntag(left); |
| 1425 | __ SmiUntag(ecx); |
| 1426 | // Perform the operation. |
| 1427 | __ shr_cl(left); |
| 1428 | // Check that the *unsigned* result fits in a smi. |
| 1429 | // Neither of the two high-order bits can be set: |
| 1430 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1431 | // - 0x40000000: this number would convert to negative when |
| 1432 | // Smi tagging these two cases can only happen with shifts |
| 1433 | // by 0 or 1 when handed a valid smi. |
| 1434 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1435 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1436 | // Tag the result and store it in register eax. |
| 1437 | __ SmiTag(left); |
| 1438 | __ mov(eax, left); |
| 1439 | break; |
| 1440 | |
| 1441 | case Token::ADD: |
| 1442 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1443 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1444 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1448 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1449 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1450 | __ mov(eax, left); |
| 1451 | break; |
| 1452 | |
| 1453 | case Token::MUL: |
| 1454 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1455 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1456 | // We can't revert the multiplication if the result is not a smi |
| 1457 | // so save the right operand. |
| 1458 | __ mov(ebx, right); |
| 1459 | // Remove tag from one of the operands (but keep sign). |
| 1460 | __ SmiUntag(right); |
| 1461 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1462 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1463 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1464 | // Check for negative zero result. Use combined = left | right. |
| 1465 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1466 | break; |
| 1467 | |
| 1468 | case Token::DIV: |
| 1469 | // We can't revert the division if the result is not a smi so |
| 1470 | // save the left operand. |
| 1471 | __ mov(edi, left); |
| 1472 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1473 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1474 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | // Sign extend left into edx:eax. |
| 1476 | ASSERT(left.is(eax)); |
| 1477 | __ cdq(); |
| 1478 | // Divide edx:eax by right. |
| 1479 | __ idiv(right); |
| 1480 | // Check for the corner case of dividing the most negative smi by |
| 1481 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1482 | // instruction. |
| 1483 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1484 | __ cmp(eax, 0x40000000); |
| 1485 | __ j(equal, &use_fp_on_smis); |
| 1486 | // Check for negative zero result. Use combined = left | right. |
| 1487 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1488 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1489 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1490 | __ j(not_zero, &use_fp_on_smis); |
| 1491 | // Tag the result and store it in register eax. |
| 1492 | __ SmiTag(eax); |
| 1493 | break; |
| 1494 | |
| 1495 | case Token::MOD: |
| 1496 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1497 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1498 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1499 | |
| 1500 | // Sign extend left into edx:eax. |
| 1501 | ASSERT(left.is(eax)); |
| 1502 | __ cdq(); |
| 1503 | // Divide edx:eax by right. |
| 1504 | __ idiv(right); |
| 1505 | // Check for negative zero result. Use combined = left | right. |
| 1506 | __ NegativeZeroTest(edx, combined, slow); |
| 1507 | // Move remainder to register eax. |
| 1508 | __ mov(eax, edx); |
| 1509 | break; |
| 1510 | |
| 1511 | default: |
| 1512 | UNREACHABLE(); |
| 1513 | } |
| 1514 | |
| 1515 | // 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] | 1516 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1517 | case Token::ADD: |
| 1518 | case Token::SUB: |
| 1519 | case Token::MUL: |
| 1520 | case Token::DIV: |
| 1521 | __ ret(0); |
| 1522 | break; |
| 1523 | case Token::MOD: |
| 1524 | case Token::BIT_OR: |
| 1525 | case Token::BIT_AND: |
| 1526 | case Token::BIT_XOR: |
| 1527 | case Token::SAR: |
| 1528 | case Token::SHL: |
| 1529 | case Token::SHR: |
| 1530 | __ ret(2 * kPointerSize); |
| 1531 | break; |
| 1532 | default: |
| 1533 | UNREACHABLE(); |
| 1534 | } |
| 1535 | |
| 1536 | // 6. For some operations emit inline code to perform floating point |
| 1537 | // operations on known smis (e.g., if the result of the operation |
| 1538 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1539 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1540 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1541 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1542 | // Undo the effects of some operations, and some register moves. |
| 1543 | case Token::SHL: |
| 1544 | // The arguments are saved on the stack, and only used from there. |
| 1545 | break; |
| 1546 | case Token::ADD: |
| 1547 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1548 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | case Token::SUB: |
| 1551 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1552 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1553 | break; |
| 1554 | case Token::MUL: |
| 1555 | // Right was clobbered but a copy is in ebx. |
| 1556 | __ mov(right, ebx); |
| 1557 | break; |
| 1558 | case Token::DIV: |
| 1559 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1560 | // division. They should be in eax, ebx for jump to not_smi. |
| 1561 | __ mov(eax, edi); |
| 1562 | break; |
| 1563 | default: |
| 1564 | // No other operators jump to use_fp_on_smis. |
| 1565 | break; |
| 1566 | } |
| 1567 | __ jmp(¬_smis); |
| 1568 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1569 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1570 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1571 | case Token::SHL: |
| 1572 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1573 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1574 | __ bind(&use_fp_on_smis); |
| 1575 | // Result we want is in left == edx, so we can put the allocated heap |
| 1576 | // number in eax. |
| 1577 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1578 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1579 | // It's OK to overwrite the arguments on the stack because we |
| 1580 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1581 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1582 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1583 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1584 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1585 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1586 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1587 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1588 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1589 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1590 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1591 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1592 | } else { |
| 1593 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1594 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1595 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1596 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1597 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1598 | __ ret(2 * kPointerSize); |
| 1599 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | case Token::ADD: |
| 1603 | case Token::SUB: |
| 1604 | case Token::MUL: |
| 1605 | case Token::DIV: { |
| 1606 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1607 | __ bind(&use_fp_on_smis); |
| 1608 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1609 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1610 | case Token::ADD: |
| 1611 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1612 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | case Token::SUB: |
| 1615 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1616 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1617 | break; |
| 1618 | case Token::MUL: |
| 1619 | // Right was clobbered but a copy is in ebx. |
| 1620 | __ mov(right, ebx); |
| 1621 | break; |
| 1622 | case Token::DIV: |
| 1623 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1624 | // division. |
| 1625 | __ mov(edx, edi); |
| 1626 | __ mov(eax, right); |
| 1627 | break; |
| 1628 | default: UNREACHABLE(); |
| 1629 | break; |
| 1630 | } |
| 1631 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1632 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1633 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1635 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1636 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1637 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1638 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1639 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1640 | default: UNREACHABLE(); |
| 1641 | } |
| 1642 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1643 | } else { // SSE2 not available, use FPU. |
| 1644 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1645 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1646 | case Token::ADD: __ faddp(1); break; |
| 1647 | case Token::SUB: __ fsubp(1); break; |
| 1648 | case Token::MUL: __ fmulp(1); break; |
| 1649 | case Token::DIV: __ fdivp(1); break; |
| 1650 | default: UNREACHABLE(); |
| 1651 | } |
| 1652 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1653 | } |
| 1654 | __ mov(eax, ecx); |
| 1655 | __ ret(0); |
| 1656 | break; |
| 1657 | } |
| 1658 | |
| 1659 | default: |
| 1660 | break; |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1665 | // edx and eax. |
| 1666 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1667 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1668 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1669 | case Token::BIT_OR: |
| 1670 | case Token::SHL: |
| 1671 | case Token::SAR: |
| 1672 | case Token::SHR: |
| 1673 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1674 | // check. |
| 1675 | __ mov(eax, ecx); |
| 1676 | break; |
| 1677 | |
| 1678 | case Token::DIV: |
| 1679 | case Token::MOD: |
| 1680 | // Operands are in eax, ebx at this point. |
| 1681 | __ mov(edx, eax); |
| 1682 | __ mov(eax, ebx); |
| 1683 | break; |
| 1684 | |
| 1685 | default: |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1691 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | Label call_runtime; |
| 1693 | |
| 1694 | switch (op_) { |
| 1695 | case Token::ADD: |
| 1696 | case Token::SUB: |
| 1697 | case Token::MUL: |
| 1698 | case Token::DIV: |
| 1699 | break; |
| 1700 | case Token::MOD: |
| 1701 | case Token::BIT_OR: |
| 1702 | case Token::BIT_AND: |
| 1703 | case Token::BIT_XOR: |
| 1704 | case Token::SAR: |
| 1705 | case Token::SHL: |
| 1706 | case Token::SHR: |
| 1707 | GenerateRegisterArgsPush(masm); |
| 1708 | break; |
| 1709 | default: |
| 1710 | UNREACHABLE(); |
| 1711 | } |
| 1712 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1713 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1714 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1715 | BinaryOpStub_GenerateSmiCode( |
| 1716 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1718 | BinaryOpStub_GenerateSmiCode( |
| 1719 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1720 | } |
| 1721 | __ bind(&call_runtime); |
| 1722 | switch (op_) { |
| 1723 | case Token::ADD: |
| 1724 | case Token::SUB: |
| 1725 | case Token::MUL: |
| 1726 | case Token::DIV: |
| 1727 | GenerateTypeTransition(masm); |
| 1728 | break; |
| 1729 | case Token::MOD: |
| 1730 | case Token::BIT_OR: |
| 1731 | case Token::BIT_AND: |
| 1732 | case Token::BIT_XOR: |
| 1733 | case Token::SAR: |
| 1734 | case Token::SHL: |
| 1735 | case Token::SHR: |
| 1736 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1737 | break; |
| 1738 | default: |
| 1739 | UNREACHABLE(); |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1744 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1745 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1746 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1747 | ASSERT(op_ == Token::ADD); |
| 1748 | // If both arguments are strings, call the string add stub. |
| 1749 | // Otherwise, do a transition. |
| 1750 | |
| 1751 | // Registers containing left and right operands respectively. |
| 1752 | Register left = edx; |
| 1753 | Register right = eax; |
| 1754 | |
| 1755 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1756 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1757 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1758 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1759 | |
| 1760 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1761 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1762 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1763 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1764 | |
| 1765 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1766 | GenerateRegisterArgsPush(masm); |
| 1767 | __ TailCallStub(&string_add_stub); |
| 1768 | |
| 1769 | __ bind(&call_runtime); |
| 1770 | GenerateTypeTransition(masm); |
| 1771 | } |
| 1772 | |
| 1773 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1774 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1775 | Label* alloc_failure, |
| 1776 | OverwriteMode mode); |
| 1777 | |
| 1778 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1779 | // Input: |
| 1780 | // edx: left operand (tagged) |
| 1781 | // eax: right operand (tagged) |
| 1782 | // Output: |
| 1783 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1784 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1785 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1786 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Floating point case. |
| 1789 | switch (op_) { |
| 1790 | case Token::ADD: |
| 1791 | case Token::SUB: |
| 1792 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1793 | case Token::DIV: |
| 1794 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1795 | Label not_floats; |
| 1796 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1797 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1798 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1799 | // It could be that only SMIs have been seen at either the left |
| 1800 | // or the right operand. For precise type feedback, patch the IC |
| 1801 | // again if this changes. |
| 1802 | // In theory, we would need the same check in the non-SSE2 case, |
| 1803 | // but since we don't support Crankshaft on such hardware we can |
| 1804 | // afford not to care about precise type feedback. |
| 1805 | if (left_type_ == BinaryOpIC::SMI) { |
| 1806 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1807 | } |
| 1808 | if (right_type_ == BinaryOpIC::SMI) { |
| 1809 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1810 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1811 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1812 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1813 | if (op_ == Token::MOD) { |
| 1814 | GenerateRegisterArgsPush(masm); |
| 1815 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1816 | } else { |
| 1817 | switch (op_) { |
| 1818 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1819 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1820 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1821 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1822 | default: UNREACHABLE(); |
| 1823 | } |
| 1824 | // Check result type if it is currently Int32. |
| 1825 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1826 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1827 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1828 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1829 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1830 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1831 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1832 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1833 | } else { // SSE2 not available, use FPU. |
| 1834 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1835 | FloatingPointHelper::LoadFloatOperands( |
| 1836 | masm, |
| 1837 | ecx, |
| 1838 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1839 | if (op_ == Token::MOD) { |
| 1840 | // The operands are now on the FPU stack, but we don't need them. |
| 1841 | __ fstp(0); |
| 1842 | __ fstp(0); |
| 1843 | GenerateRegisterArgsPush(masm); |
| 1844 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1845 | } else { |
| 1846 | switch (op_) { |
| 1847 | case Token::ADD: __ faddp(1); break; |
| 1848 | case Token::SUB: __ fsubp(1); break; |
| 1849 | case Token::MUL: __ fmulp(1); break; |
| 1850 | case Token::DIV: __ fdivp(1); break; |
| 1851 | default: UNREACHABLE(); |
| 1852 | } |
| 1853 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1854 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1855 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1856 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1857 | __ ret(0); |
| 1858 | __ bind(&after_alloc_failure); |
| 1859 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1860 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1861 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | __ bind(¬_floats); |
| 1865 | __ bind(¬_int32); |
| 1866 | GenerateTypeTransition(masm); |
| 1867 | break; |
| 1868 | } |
| 1869 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1870 | case Token::BIT_OR: |
| 1871 | case Token::BIT_AND: |
| 1872 | case Token::BIT_XOR: |
| 1873 | case Token::SAR: |
| 1874 | case Token::SHL: |
| 1875 | case Token::SHR: { |
| 1876 | GenerateRegisterArgsPush(masm); |
| 1877 | Label not_floats; |
| 1878 | Label not_int32; |
| 1879 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1880 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1881 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1882 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1883 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1884 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1885 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1886 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1887 | case Token::SAR: __ sar_cl(eax); break; |
| 1888 | case Token::SHL: __ shl_cl(eax); break; |
| 1889 | case Token::SHR: __ shr_cl(eax); break; |
| 1890 | default: UNREACHABLE(); |
| 1891 | } |
| 1892 | if (op_ == Token::SHR) { |
| 1893 | // Check if result is non-negative and fits in a smi. |
| 1894 | __ test(eax, Immediate(0xc0000000)); |
| 1895 | __ j(not_zero, &call_runtime); |
| 1896 | } else { |
| 1897 | // Check if result fits in a smi. |
| 1898 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1899 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | } |
| 1901 | // Tag smi result and return. |
| 1902 | __ SmiTag(eax); |
| 1903 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1904 | |
| 1905 | // All ops except SHR return a signed int32 that we load in |
| 1906 | // a HeapNumber. |
| 1907 | if (op_ != Token::SHR) { |
| 1908 | __ bind(&non_smi_result); |
| 1909 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1910 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1911 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1912 | switch (mode_) { |
| 1913 | case OVERWRITE_LEFT: |
| 1914 | case OVERWRITE_RIGHT: |
| 1915 | // If the operand was an object, we skip the |
| 1916 | // allocation of a heap number. |
| 1917 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1918 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1919 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1920 | // Fall through! |
| 1921 | case NO_OVERWRITE: |
| 1922 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1923 | __ bind(&skip_allocation); |
| 1924 | break; |
| 1925 | default: UNREACHABLE(); |
| 1926 | } |
| 1927 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1928 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1929 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1930 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1931 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1932 | } else { |
| 1933 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1934 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1935 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1936 | } |
| 1937 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1938 | } |
| 1939 | |
| 1940 | __ bind(¬_floats); |
| 1941 | __ bind(¬_int32); |
| 1942 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1943 | break; |
| 1944 | } |
| 1945 | default: UNREACHABLE(); break; |
| 1946 | } |
| 1947 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1948 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1949 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1950 | __ bind(&call_runtime); |
| 1951 | |
| 1952 | switch (op_) { |
| 1953 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1954 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1955 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1956 | case Token::DIV: |
| 1957 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1958 | break; |
| 1959 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1960 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1961 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1962 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1963 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1964 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1965 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1966 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1967 | break; |
| 1968 | default: |
| 1969 | UNREACHABLE(); |
| 1970 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1971 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1975 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1976 | if (op_ == Token::ADD) { |
| 1977 | // Handle string addition here, because it is the only operation |
| 1978 | // that does not do a ToNumber conversion on the operands. |
| 1979 | GenerateAddStrings(masm); |
| 1980 | } |
| 1981 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1982 | Factory* factory = masm->isolate()->factory(); |
| 1983 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1984 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1985 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1986 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1987 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1988 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1989 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1990 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1991 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1992 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1993 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1994 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1995 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1996 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1997 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1998 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1999 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2000 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2001 | } |
| 2002 | __ bind(&done); |
| 2003 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2004 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2008 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2009 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2010 | |
| 2011 | // Floating point case. |
| 2012 | switch (op_) { |
| 2013 | case Token::ADD: |
| 2014 | case Token::SUB: |
| 2015 | case Token::MUL: |
| 2016 | case Token::DIV: { |
| 2017 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2018 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2019 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2020 | |
| 2021 | // It could be that only SMIs have been seen at either the left |
| 2022 | // or the right operand. For precise type feedback, patch the IC |
| 2023 | // again if this changes. |
| 2024 | // In theory, we would need the same check in the non-SSE2 case, |
| 2025 | // but since we don't support Crankshaft on such hardware we can |
| 2026 | // afford not to care about precise type feedback. |
| 2027 | if (left_type_ == BinaryOpIC::SMI) { |
| 2028 | __ JumpIfNotSmi(edx, ¬_floats); |
| 2029 | } |
| 2030 | if (right_type_ == BinaryOpIC::SMI) { |
| 2031 | __ JumpIfNotSmi(eax, ¬_floats); |
| 2032 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2034 | if (left_type_ == BinaryOpIC::INT32) { |
| 2035 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2036 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2037 | } |
| 2038 | if (right_type_ == BinaryOpIC::INT32) { |
| 2039 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2040 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2041 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2042 | |
| 2043 | switch (op_) { |
| 2044 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2045 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2046 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2047 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2048 | default: UNREACHABLE(); |
| 2049 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2050 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2051 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2052 | __ ret(0); |
| 2053 | } else { // SSE2 not available, use FPU. |
| 2054 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2055 | FloatingPointHelper::LoadFloatOperands( |
| 2056 | masm, |
| 2057 | ecx, |
| 2058 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2059 | switch (op_) { |
| 2060 | case Token::ADD: __ faddp(1); break; |
| 2061 | case Token::SUB: __ fsubp(1); break; |
| 2062 | case Token::MUL: __ fmulp(1); break; |
| 2063 | case Token::DIV: __ fdivp(1); break; |
| 2064 | default: UNREACHABLE(); |
| 2065 | } |
| 2066 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2067 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2068 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2069 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2070 | __ ret(0); |
| 2071 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2072 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2073 | __ jmp(&call_runtime); |
| 2074 | } |
| 2075 | |
| 2076 | __ bind(¬_floats); |
| 2077 | GenerateTypeTransition(masm); |
| 2078 | break; |
| 2079 | } |
| 2080 | |
| 2081 | case Token::MOD: { |
| 2082 | // For MOD we go directly to runtime in the non-smi case. |
| 2083 | break; |
| 2084 | } |
| 2085 | case Token::BIT_OR: |
| 2086 | case Token::BIT_AND: |
| 2087 | case Token::BIT_XOR: |
| 2088 | case Token::SAR: |
| 2089 | case Token::SHL: |
| 2090 | case Token::SHR: { |
| 2091 | GenerateRegisterArgsPush(masm); |
| 2092 | Label not_floats; |
| 2093 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2094 | // We do not check the input arguments here, as any value is |
| 2095 | // unconditionally truncated to an int32 anyway. To get the |
| 2096 | // right optimized code, int32 type feedback is just right. |
| 2097 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2098 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2099 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2100 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2101 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2102 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2103 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2104 | case Token::SAR: __ sar_cl(eax); break; |
| 2105 | case Token::SHL: __ shl_cl(eax); break; |
| 2106 | case Token::SHR: __ shr_cl(eax); break; |
| 2107 | default: UNREACHABLE(); |
| 2108 | } |
| 2109 | if (op_ == Token::SHR) { |
| 2110 | // Check if result is non-negative and fits in a smi. |
| 2111 | __ test(eax, Immediate(0xc0000000)); |
| 2112 | __ j(not_zero, &call_runtime); |
| 2113 | } else { |
| 2114 | // Check if result fits in a smi. |
| 2115 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2116 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2117 | } |
| 2118 | // Tag smi result and return. |
| 2119 | __ SmiTag(eax); |
| 2120 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2121 | |
| 2122 | // All ops except SHR return a signed int32 that we load in |
| 2123 | // a HeapNumber. |
| 2124 | if (op_ != Token::SHR) { |
| 2125 | __ bind(&non_smi_result); |
| 2126 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2127 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2128 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | switch (mode_) { |
| 2130 | case OVERWRITE_LEFT: |
| 2131 | case OVERWRITE_RIGHT: |
| 2132 | // If the operand was an object, we skip the |
| 2133 | // allocation of a heap number. |
| 2134 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2135 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2136 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2137 | // Fall through! |
| 2138 | case NO_OVERWRITE: |
| 2139 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2140 | __ bind(&skip_allocation); |
| 2141 | break; |
| 2142 | default: UNREACHABLE(); |
| 2143 | } |
| 2144 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2145 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2146 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2147 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2148 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2149 | } else { |
| 2150 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2151 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2152 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2153 | } |
| 2154 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2155 | } |
| 2156 | |
| 2157 | __ bind(¬_floats); |
| 2158 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2159 | break; |
| 2160 | } |
| 2161 | default: UNREACHABLE(); break; |
| 2162 | } |
| 2163 | |
| 2164 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2165 | // use the runtime system to get the correct result. |
| 2166 | __ bind(&call_runtime); |
| 2167 | |
| 2168 | switch (op_) { |
| 2169 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2170 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2171 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2172 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2173 | case Token::MOD: |
| 2174 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2177 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2178 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2179 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2180 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2181 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2182 | break; |
| 2183 | default: |
| 2184 | UNREACHABLE(); |
| 2185 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2186 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2190 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2191 | Label call_runtime; |
| 2192 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2193 | Counters* counters = masm->isolate()->counters(); |
| 2194 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2195 | |
| 2196 | switch (op_) { |
| 2197 | case Token::ADD: |
| 2198 | case Token::SUB: |
| 2199 | case Token::MUL: |
| 2200 | case Token::DIV: |
| 2201 | break; |
| 2202 | case Token::MOD: |
| 2203 | case Token::BIT_OR: |
| 2204 | case Token::BIT_AND: |
| 2205 | case Token::BIT_XOR: |
| 2206 | case Token::SAR: |
| 2207 | case Token::SHL: |
| 2208 | case Token::SHR: |
| 2209 | GenerateRegisterArgsPush(masm); |
| 2210 | break; |
| 2211 | default: |
| 2212 | UNREACHABLE(); |
| 2213 | } |
| 2214 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2215 | BinaryOpStub_GenerateSmiCode( |
| 2216 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2217 | |
| 2218 | // Floating point case. |
| 2219 | switch (op_) { |
| 2220 | case Token::ADD: |
| 2221 | case Token::SUB: |
| 2222 | case Token::MUL: |
| 2223 | case Token::DIV: { |
| 2224 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2225 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2226 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2227 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2228 | |
| 2229 | switch (op_) { |
| 2230 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2231 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2232 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2233 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2234 | default: UNREACHABLE(); |
| 2235 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2236 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2237 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2238 | __ ret(0); |
| 2239 | } else { // SSE2 not available, use FPU. |
| 2240 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2241 | FloatingPointHelper::LoadFloatOperands( |
| 2242 | masm, |
| 2243 | ecx, |
| 2244 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2245 | switch (op_) { |
| 2246 | case Token::ADD: __ faddp(1); break; |
| 2247 | case Token::SUB: __ fsubp(1); break; |
| 2248 | case Token::MUL: __ fmulp(1); break; |
| 2249 | case Token::DIV: __ fdivp(1); break; |
| 2250 | default: UNREACHABLE(); |
| 2251 | } |
| 2252 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2253 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2254 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2255 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2256 | __ ret(0); |
| 2257 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2258 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2259 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2260 | } |
| 2261 | __ bind(¬_floats); |
| 2262 | break; |
| 2263 | } |
| 2264 | case Token::MOD: { |
| 2265 | // For MOD we go directly to runtime in the non-smi case. |
| 2266 | break; |
| 2267 | } |
| 2268 | case Token::BIT_OR: |
| 2269 | case Token::BIT_AND: |
| 2270 | case Token::BIT_XOR: |
| 2271 | case Token::SAR: |
| 2272 | case Token::SHL: |
| 2273 | case Token::SHR: { |
| 2274 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2275 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2276 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2277 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2278 | BinaryOpIC::GENERIC, |
| 2279 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | &call_runtime); |
| 2281 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2282 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2283 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2284 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2285 | case Token::SAR: __ sar_cl(eax); break; |
| 2286 | case Token::SHL: __ shl_cl(eax); break; |
| 2287 | case Token::SHR: __ shr_cl(eax); break; |
| 2288 | default: UNREACHABLE(); |
| 2289 | } |
| 2290 | if (op_ == Token::SHR) { |
| 2291 | // Check if result is non-negative and fits in a smi. |
| 2292 | __ test(eax, Immediate(0xc0000000)); |
| 2293 | __ j(not_zero, &call_runtime); |
| 2294 | } else { |
| 2295 | // Check if result fits in a smi. |
| 2296 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2297 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2298 | } |
| 2299 | // Tag smi result and return. |
| 2300 | __ SmiTag(eax); |
| 2301 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2302 | |
| 2303 | // All ops except SHR return a signed int32 that we load in |
| 2304 | // a HeapNumber. |
| 2305 | if (op_ != Token::SHR) { |
| 2306 | __ bind(&non_smi_result); |
| 2307 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2308 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2309 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2310 | switch (mode_) { |
| 2311 | case OVERWRITE_LEFT: |
| 2312 | case OVERWRITE_RIGHT: |
| 2313 | // If the operand was an object, we skip the |
| 2314 | // allocation of a heap number. |
| 2315 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2316 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2317 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2318 | // Fall through! |
| 2319 | case NO_OVERWRITE: |
| 2320 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2321 | __ bind(&skip_allocation); |
| 2322 | break; |
| 2323 | default: UNREACHABLE(); |
| 2324 | } |
| 2325 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2326 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2327 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2328 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2329 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2330 | } else { |
| 2331 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2332 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2333 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2334 | } |
| 2335 | __ ret(2 * kPointerSize); |
| 2336 | } |
| 2337 | break; |
| 2338 | } |
| 2339 | default: UNREACHABLE(); break; |
| 2340 | } |
| 2341 | |
| 2342 | // If all else fails, use the runtime system to get the correct |
| 2343 | // result. |
| 2344 | __ bind(&call_runtime); |
| 2345 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2346 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2347 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2348 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2349 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2350 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2351 | case Token::DIV: |
| 2352 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2355 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2356 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2357 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2358 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2359 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2360 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | default: |
| 2363 | UNREACHABLE(); |
| 2364 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2365 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2369 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2370 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2371 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2372 | |
| 2373 | // Registers containing left and right operands respectively. |
| 2374 | Register left = edx; |
| 2375 | Register right = eax; |
| 2376 | |
| 2377 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2378 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2379 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2380 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2381 | |
| 2382 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2383 | GenerateRegisterArgsPush(masm); |
| 2384 | __ TailCallStub(&string_add_left_stub); |
| 2385 | |
| 2386 | // Left operand is not a string, test right. |
| 2387 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2388 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2389 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2390 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2391 | |
| 2392 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2393 | GenerateRegisterArgsPush(masm); |
| 2394 | __ TailCallStub(&string_add_right_stub); |
| 2395 | |
| 2396 | // Neither argument is a string. |
| 2397 | __ bind(&call_runtime); |
| 2398 | } |
| 2399 | |
| 2400 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2401 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2402 | Label* alloc_failure, |
| 2403 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2404 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2405 | switch (mode) { |
| 2406 | case OVERWRITE_LEFT: { |
| 2407 | // If the argument in edx is already an object, we skip the |
| 2408 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2409 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2410 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2411 | // for the possible runtime call. |
| 2412 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2413 | // Now edx can be overwritten losing one of the arguments as we are |
| 2414 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2415 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2416 | __ bind(&skip_allocation); |
| 2417 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2418 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2419 | break; |
| 2420 | } |
| 2421 | case OVERWRITE_RIGHT: |
| 2422 | // If the argument in eax is already an object, we skip the |
| 2423 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2424 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2425 | // Fall through! |
| 2426 | case NO_OVERWRITE: |
| 2427 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2428 | // for the possible runtime call. |
| 2429 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2430 | // Now eax can be overwritten losing one of the arguments as we are |
| 2431 | // now done and will not need it any more. |
| 2432 | __ mov(eax, ebx); |
| 2433 | __ bind(&skip_allocation); |
| 2434 | break; |
| 2435 | default: UNREACHABLE(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2440 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2441 | __ pop(ecx); |
| 2442 | __ push(edx); |
| 2443 | __ push(eax); |
| 2444 | __ push(ecx); |
| 2445 | } |
| 2446 | |
| 2447 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2448 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2449 | // TAGGED case: |
| 2450 | // Input: |
| 2451 | // esp[4]: tagged number input argument (should be number). |
| 2452 | // esp[0]: return address. |
| 2453 | // Output: |
| 2454 | // eax: tagged double result. |
| 2455 | // UNTAGGED case: |
| 2456 | // Input:: |
| 2457 | // esp[0]: return address. |
| 2458 | // xmm1: untagged double input argument |
| 2459 | // Output: |
| 2460 | // xmm1: untagged double result. |
| 2461 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2462 | Label runtime_call; |
| 2463 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2464 | Label skip_cache; |
| 2465 | const bool tagged = (argument_type_ == TAGGED); |
| 2466 | if (tagged) { |
| 2467 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2468 | Label input_not_smi; |
| 2469 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2470 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2471 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2472 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2473 | // Then load the low and high words of the double into ebx, edx. |
| 2474 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2475 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2476 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2477 | __ mov(Operand(esp, 0), eax); |
| 2478 | __ fild_s(Operand(esp, 0)); |
| 2479 | __ fst_d(Operand(esp, 0)); |
| 2480 | __ pop(edx); |
| 2481 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2482 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2483 | __ bind(&input_not_smi); |
| 2484 | // Check if input is a HeapNumber. |
| 2485 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2486 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2487 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2488 | __ j(not_equal, &runtime_call); |
| 2489 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2490 | // low and high words into ebx, edx. |
| 2491 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2492 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2493 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2494 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2495 | __ bind(&loaded); |
| 2496 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2497 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2498 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2499 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2500 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2501 | } else { |
| 2502 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2503 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2504 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2505 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2509 | // ebx = low 32 bits of double value |
| 2510 | // edx = high 32 bits of double value |
| 2511 | // Compute hash (the shifts are arithmetic): |
| 2512 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2513 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2514 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2515 | __ mov(eax, ecx); |
| 2516 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2517 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2518 | __ mov(eax, ecx); |
| 2519 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2520 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2521 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2522 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2523 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2524 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2525 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2526 | // ebx = low 32 bits of double value. |
| 2527 | // edx = high 32 bits of double value. |
| 2528 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2529 | ExternalReference cache_array = |
| 2530 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2531 | __ mov(eax, Immediate(cache_array)); |
| 2532 | int cache_array_index = |
| 2533 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2534 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2535 | // Eax points to the cache for the type type_. |
| 2536 | // 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] | 2537 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2538 | __ j(zero, &runtime_call_clear_stack); |
| 2539 | #ifdef DEBUG |
| 2540 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2541 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2542 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2543 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2544 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2545 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2546 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2547 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2548 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2549 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2550 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2551 | } |
| 2552 | #endif |
| 2553 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2554 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2555 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2556 | // 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] | 2557 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2558 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2559 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2560 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2561 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2562 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2563 | Counters* counters = masm->isolate()->counters(); |
| 2564 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2565 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2566 | if (tagged) { |
| 2567 | __ fstp(0); |
| 2568 | __ ret(kPointerSize); |
| 2569 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2570 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2571 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2572 | __ Ret(); |
| 2573 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2574 | |
| 2575 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2576 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2577 | // Update cache with new value. |
| 2578 | // We are short on registers, so use no_reg as scratch. |
| 2579 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2580 | if (tagged) { |
| 2581 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2582 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2583 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2584 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2585 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2586 | __ movdbl(Operand(esp, 0), xmm1); |
| 2587 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2588 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2589 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2590 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2591 | __ mov(Operand(ecx, 0), ebx); |
| 2592 | __ mov(Operand(ecx, kIntSize), edx); |
| 2593 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2594 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2595 | if (tagged) { |
| 2596 | __ ret(kPointerSize); |
| 2597 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2598 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2599 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2600 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2601 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2602 | // Skip cache and return answer directly, only in untagged case. |
| 2603 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2604 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2605 | __ movdbl(Operand(esp, 0), xmm1); |
| 2606 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2607 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2608 | __ fstp_d(Operand(esp, 0)); |
| 2609 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2610 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2611 | // We return the value in xmm1 without adding it to the cache, but |
| 2612 | // 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] | 2613 | { |
| 2614 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2615 | // Allocate an unused object bigger than a HeapNumber. |
| 2616 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2617 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2618 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2619 | __ Ret(); |
| 2620 | } |
| 2621 | |
| 2622 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2623 | if (tagged) { |
| 2624 | __ bind(&runtime_call_clear_stack); |
| 2625 | __ fstp(0); |
| 2626 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2627 | ExternalReference runtime = |
| 2628 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2629 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2630 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2631 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2632 | __ bind(&runtime_call_clear_stack); |
| 2633 | __ bind(&runtime_call); |
| 2634 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2635 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2636 | { |
| 2637 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2638 | __ push(eax); |
| 2639 | __ CallRuntime(RuntimeFunction(), 1); |
| 2640 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2641 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2642 | __ Ret(); |
| 2643 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | |
| 2647 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2648 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2649 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2650 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2651 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2652 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2653 | default: |
| 2654 | UNIMPLEMENTED(); |
| 2655 | return Runtime::kAbort; |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2660 | void TranscendentalCacheStub::GenerateOperation( |
| 2661 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2662 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2663 | // Input value is on FP stack, and also in ebx/edx. |
| 2664 | // Input value is possibly in xmm1. |
| 2665 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2666 | if (type == TranscendentalCache::SIN || |
| 2667 | type == TranscendentalCache::COS || |
| 2668 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2669 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2670 | // return NaN for infinities and NaN. They can share all code except |
| 2671 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2672 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2673 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2674 | // work. We must reduce it to the appropriate range. |
| 2675 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2676 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2677 | int supported_exponent_limit = |
| 2678 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2679 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2680 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2681 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2682 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2683 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2684 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2685 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2686 | __ fstp(0); |
| 2687 | // NaN is represented by 0x7ff8000000000000. |
| 2688 | __ push(Immediate(0x7ff80000)); |
| 2689 | __ push(Immediate(0)); |
| 2690 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2691 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2692 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2693 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2694 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2695 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2696 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2697 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2698 | __ fldpi(); |
| 2699 | __ fadd(0); |
| 2700 | __ fld(1); |
| 2701 | // FPU Stack: input, 2*pi, input. |
| 2702 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2703 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2704 | __ fwait(); |
| 2705 | __ fnstsw_ax(); |
| 2706 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2707 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2708 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2709 | __ fnclex(); |
| 2710 | __ bind(&no_exceptions); |
| 2711 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2712 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2713 | // Compute st(0) % st(1) |
| 2714 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2715 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2716 | __ bind(&partial_remainder_loop); |
| 2717 | __ fprem1(); |
| 2718 | __ fwait(); |
| 2719 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2720 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2721 | // If C2 is set, computation only has partial result. Loop to |
| 2722 | // continue computation. |
| 2723 | __ j(not_zero, &partial_remainder_loop); |
| 2724 | } |
| 2725 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2726 | __ fstp(2); |
| 2727 | __ fstp(0); |
| 2728 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2729 | |
| 2730 | // FPU Stack: input % 2*pi |
| 2731 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2732 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2733 | case TranscendentalCache::SIN: |
| 2734 | __ fsin(); |
| 2735 | break; |
| 2736 | case TranscendentalCache::COS: |
| 2737 | __ fcos(); |
| 2738 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2739 | case TranscendentalCache::TAN: |
| 2740 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2741 | // FP register stack. |
| 2742 | __ fptan(); |
| 2743 | __ fstp(0); // Pop FP register stack. |
| 2744 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2745 | default: |
| 2746 | UNREACHABLE(); |
| 2747 | } |
| 2748 | __ bind(&done); |
| 2749 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2750 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2751 | __ fldln2(); |
| 2752 | __ fxch(); |
| 2753 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2754 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2758 | // Input: edx, eax are the left and right objects of a bit op. |
| 2759 | // 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] | 2760 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2761 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2762 | MacroAssembler* masm, |
| 2763 | bool use_sse3, |
| 2764 | BinaryOpIC::TypeInfo left_type, |
| 2765 | BinaryOpIC::TypeInfo right_type, |
| 2766 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2767 | // Check float operands. |
| 2768 | Label arg1_is_object, check_undefined_arg1; |
| 2769 | Label arg2_is_object, check_undefined_arg2; |
| 2770 | Label load_arg2, done; |
| 2771 | |
| 2772 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2773 | if (left_type == BinaryOpIC::SMI) { |
| 2774 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2775 | } else { |
| 2776 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2777 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2778 | |
| 2779 | __ SmiUntag(edx); |
| 2780 | __ jmp(&load_arg2); |
| 2781 | |
| 2782 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2783 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2784 | Factory* factory = masm->isolate()->factory(); |
| 2785 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2786 | __ j(not_equal, conversion_failure); |
| 2787 | __ mov(edx, Immediate(0)); |
| 2788 | __ jmp(&load_arg2); |
| 2789 | |
| 2790 | __ bind(&arg1_is_object); |
| 2791 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2792 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2793 | __ j(not_equal, &check_undefined_arg1); |
| 2794 | |
| 2795 | // 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] | 2796 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2797 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2798 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2799 | } else { |
| 2800 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2801 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2802 | __ mov(edx, ecx); |
| 2803 | |
| 2804 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2805 | __ bind(&load_arg2); |
| 2806 | |
| 2807 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2808 | if (right_type == BinaryOpIC::SMI) { |
| 2809 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2810 | } else { |
| 2811 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2812 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2813 | |
| 2814 | __ SmiUntag(eax); |
| 2815 | __ mov(ecx, eax); |
| 2816 | __ jmp(&done); |
| 2817 | |
| 2818 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2819 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2820 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2821 | __ j(not_equal, conversion_failure); |
| 2822 | __ mov(ecx, Immediate(0)); |
| 2823 | __ jmp(&done); |
| 2824 | |
| 2825 | __ bind(&arg2_is_object); |
| 2826 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2827 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2828 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2829 | // 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] | 2830 | |
| 2831 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2832 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2833 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2834 | } else { |
| 2835 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2836 | } |
| 2837 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2838 | __ bind(&done); |
| 2839 | __ mov(eax, edx); |
| 2840 | } |
| 2841 | |
| 2842 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2843 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2844 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2845 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2847 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2848 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2849 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2850 | |
| 2851 | __ bind(&load_smi); |
| 2852 | __ SmiUntag(number); |
| 2853 | __ push(number); |
| 2854 | __ fild_s(Operand(esp, 0)); |
| 2855 | __ pop(number); |
| 2856 | |
| 2857 | __ bind(&done); |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2862 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2863 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2864 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2866 | |
| 2867 | __ bind(&load_eax); |
| 2868 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2869 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2871 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2872 | |
| 2873 | __ bind(&load_smi_edx); |
| 2874 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2875 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2876 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2877 | __ jmp(&load_eax); |
| 2878 | |
| 2879 | __ bind(&load_smi_eax); |
| 2880 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2881 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2882 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2883 | |
| 2884 | __ bind(&done); |
| 2885 | } |
| 2886 | |
| 2887 | |
| 2888 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2889 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2890 | 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] | 2891 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2892 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2893 | Factory* factory = masm->isolate()->factory(); |
| 2894 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2895 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2896 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2897 | __ bind(&load_eax); |
| 2898 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2899 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2900 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2901 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2902 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2903 | __ bind(&load_smi_edx); |
| 2904 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2905 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2906 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2907 | __ jmp(&load_eax); |
| 2908 | __ bind(&load_smi_eax); |
| 2909 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2910 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2911 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2912 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2913 | __ bind(&load_float_eax); |
| 2914 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2915 | __ bind(&done); |
| 2916 | } |
| 2917 | |
| 2918 | |
| 2919 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2920 | Register scratch) { |
| 2921 | const Register left = edx; |
| 2922 | const Register right = eax; |
| 2923 | __ mov(scratch, left); |
| 2924 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2925 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2926 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2927 | |
| 2928 | __ mov(scratch, right); |
| 2929 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2930 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2934 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2935 | Label* non_int32, |
| 2936 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2937 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2938 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | |
| 2942 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2943 | Label* non_int32, |
| 2944 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2945 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2946 | Register scratch, |
| 2947 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2948 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2949 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2950 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2951 | __ movmskps(scratch, xmm_scratch); |
| 2952 | // Two least significant bits should be both set. |
| 2953 | __ not_(scratch); |
| 2954 | __ test(scratch, Immediate(3)); |
| 2955 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2959 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2960 | Register scratch, |
| 2961 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2962 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2963 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2964 | __ mov(scratch, edx); |
| 2965 | } else { |
| 2966 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2967 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2968 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2969 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2970 | __ bind(&done_load_1); |
| 2971 | |
| 2972 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2973 | __ mov(scratch, eax); |
| 2974 | } else { |
| 2975 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2976 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2977 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2978 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2979 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2980 | |
| 2981 | __ bind(&load_smi_1); |
| 2982 | __ SmiUntag(scratch); |
| 2983 | __ push(scratch); |
| 2984 | __ fild_s(Operand(esp, 0)); |
| 2985 | __ pop(scratch); |
| 2986 | __ jmp(&done_load_1); |
| 2987 | |
| 2988 | __ bind(&load_smi_2); |
| 2989 | __ SmiUntag(scratch); |
| 2990 | __ push(scratch); |
| 2991 | __ fild_s(Operand(esp, 0)); |
| 2992 | __ pop(scratch); |
| 2993 | |
| 2994 | __ bind(&done); |
| 2995 | } |
| 2996 | |
| 2997 | |
| 2998 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2999 | Register scratch) { |
| 3000 | const Register left = edx; |
| 3001 | const Register right = eax; |
| 3002 | __ mov(scratch, left); |
| 3003 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 3004 | __ SmiUntag(scratch); |
| 3005 | __ push(scratch); |
| 3006 | __ fild_s(Operand(esp, 0)); |
| 3007 | |
| 3008 | __ mov(scratch, right); |
| 3009 | __ SmiUntag(scratch); |
| 3010 | __ mov(Operand(esp, 0), scratch); |
| 3011 | __ fild_s(Operand(esp, 0)); |
| 3012 | __ pop(scratch); |
| 3013 | } |
| 3014 | |
| 3015 | |
| 3016 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 3017 | Label* non_float, |
| 3018 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3019 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3020 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 3021 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3022 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3023 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3024 | Factory* factory = masm->isolate()->factory(); |
| 3025 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3026 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 3027 | |
| 3028 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3029 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3030 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3031 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3032 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 3033 | |
| 3034 | // Fall-through: Both operands are numbers. |
| 3035 | __ bind(&done); |
| 3036 | } |
| 3037 | |
| 3038 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3039 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3040 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3041 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3042 | const Register exponent = eax; |
| 3043 | const Register base = edx; |
| 3044 | const Register scratch = ecx; |
| 3045 | const XMMRegister double_result = xmm3; |
| 3046 | const XMMRegister double_base = xmm2; |
| 3047 | const XMMRegister double_exponent = xmm1; |
| 3048 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3049 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3050 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3051 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3052 | // Save 1 in double_result - we need this several times later on. |
| 3053 | __ mov(scratch, Immediate(1)); |
| 3054 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3055 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3056 | if (exponent_type_ == ON_STACK) { |
| 3057 | Label base_is_smi, unpack_exponent; |
| 3058 | // The exponent and base are supplied as arguments on the stack. |
| 3059 | // This can only happen if the stub is called from non-optimized code. |
| 3060 | // Load input parameters from stack. |
| 3061 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3062 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3063 | |
| 3064 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3065 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3066 | factory->heap_number_map()); |
| 3067 | __ j(not_equal, &call_runtime); |
| 3068 | |
| 3069 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3070 | __ jmp(&unpack_exponent, Label::kNear); |
| 3071 | |
| 3072 | __ bind(&base_is_smi); |
| 3073 | __ SmiUntag(base); |
| 3074 | __ cvtsi2sd(double_base, base); |
| 3075 | |
| 3076 | __ bind(&unpack_exponent); |
| 3077 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3078 | __ SmiUntag(exponent); |
| 3079 | __ jmp(&int_exponent); |
| 3080 | |
| 3081 | __ bind(&exponent_not_smi); |
| 3082 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3083 | factory->heap_number_map()); |
| 3084 | __ j(not_equal, &call_runtime); |
| 3085 | __ movdbl(double_exponent, |
| 3086 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3087 | } else if (exponent_type_ == TAGGED) { |
| 3088 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3089 | __ SmiUntag(exponent); |
| 3090 | __ jmp(&int_exponent); |
| 3091 | |
| 3092 | __ bind(&exponent_not_smi); |
| 3093 | __ movdbl(double_exponent, |
| 3094 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3095 | } |
| 3096 | |
| 3097 | if (exponent_type_ != INTEGER) { |
| 3098 | Label fast_power; |
| 3099 | // Detect integer exponents stored as double. |
| 3100 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3101 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3102 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3103 | __ j(equal, &call_runtime); |
| 3104 | __ cvtsi2sd(double_scratch, exponent); |
| 3105 | // Already ruled out NaNs for exponent. |
| 3106 | __ ucomisd(double_exponent, double_scratch); |
| 3107 | __ j(equal, &int_exponent); |
| 3108 | |
| 3109 | if (exponent_type_ == ON_STACK) { |
| 3110 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3111 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3112 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3113 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3114 | // Test for 0.5. |
| 3115 | // Load double_scratch with 0.5. |
| 3116 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3117 | __ movd(double_scratch, scratch); |
| 3118 | __ cvtss2sd(double_scratch, double_scratch); |
| 3119 | // Already ruled out NaNs for exponent. |
| 3120 | __ ucomisd(double_scratch, double_exponent); |
| 3121 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3122 | |
| 3123 | // Calculates square root of base. Check for the special case of |
| 3124 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3125 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3126 | // 9 bits set and the lowest 23 bits cleared. |
| 3127 | __ mov(scratch, 0xFF800000u); |
| 3128 | __ movd(double_scratch, scratch); |
| 3129 | __ cvtss2sd(double_scratch, double_scratch); |
| 3130 | __ ucomisd(double_base, double_scratch); |
| 3131 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3132 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3133 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3134 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3135 | |
| 3136 | // Set result to Infinity in the special case. |
| 3137 | __ xorps(double_result, double_result); |
| 3138 | __ subsd(double_result, double_scratch); |
| 3139 | __ jmp(&done); |
| 3140 | |
| 3141 | __ bind(&continue_sqrt); |
| 3142 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3143 | __ xorps(double_scratch, double_scratch); |
| 3144 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3145 | __ sqrtsd(double_result, double_scratch); |
| 3146 | __ jmp(&done); |
| 3147 | |
| 3148 | // Test for -0.5. |
| 3149 | __ bind(¬_plus_half); |
| 3150 | // Load double_exponent with -0.5 by substracting 1. |
| 3151 | __ subsd(double_scratch, double_result); |
| 3152 | // Already ruled out NaNs for exponent. |
| 3153 | __ ucomisd(double_scratch, double_exponent); |
| 3154 | __ j(not_equal, &fast_power, Label::kNear); |
| 3155 | |
| 3156 | // Calculates reciprocal of square root of base. Check for the special |
| 3157 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3158 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3159 | // 9 bits set and the lowest 23 bits cleared. |
| 3160 | __ mov(scratch, 0xFF800000u); |
| 3161 | __ movd(double_scratch, scratch); |
| 3162 | __ cvtss2sd(double_scratch, double_scratch); |
| 3163 | __ ucomisd(double_base, double_scratch); |
| 3164 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3165 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3166 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3167 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3168 | |
| 3169 | // Set result to 0 in the special case. |
| 3170 | __ xorps(double_result, double_result); |
| 3171 | __ jmp(&done); |
| 3172 | |
| 3173 | __ bind(&continue_rsqrt); |
| 3174 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3175 | __ xorps(double_exponent, double_exponent); |
| 3176 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3177 | __ sqrtsd(double_exponent, double_exponent); |
| 3178 | __ divsd(double_result, double_exponent); |
| 3179 | __ jmp(&done); |
| 3180 | } |
| 3181 | |
| 3182 | // Using FPU instructions to calculate power. |
| 3183 | Label fast_power_failed; |
| 3184 | __ bind(&fast_power); |
| 3185 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3186 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3187 | __ sub(esp, Immediate(kDoubleSize)); |
| 3188 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3189 | __ fld_d(Operand(esp, 0)); // E |
| 3190 | __ movdbl(Operand(esp, 0), double_base); |
| 3191 | __ fld_d(Operand(esp, 0)); // B, E |
| 3192 | |
| 3193 | // Exponent is in st(1) and base is in st(0) |
| 3194 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3195 | // FYL2X calculates st(1) * log2(st(0)) |
| 3196 | __ fyl2x(); // X |
| 3197 | __ fld(0); // X, X |
| 3198 | __ frndint(); // rnd(X), X |
| 3199 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3200 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3201 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3202 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3203 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3204 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3205 | // FSCALE calculates st(0) * 2^st(1) |
| 3206 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3207 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3208 | // Bail out to runtime in case of exceptions in the status word. |
| 3209 | __ fnstsw_ax(); |
| 3210 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3211 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3212 | __ fstp_d(Operand(esp, 0)); |
| 3213 | __ movdbl(double_result, Operand(esp, 0)); |
| 3214 | __ add(esp, Immediate(kDoubleSize)); |
| 3215 | __ jmp(&done); |
| 3216 | |
| 3217 | __ bind(&fast_power_failed); |
| 3218 | __ fninit(); |
| 3219 | __ add(esp, Immediate(kDoubleSize)); |
| 3220 | __ jmp(&call_runtime); |
| 3221 | } |
| 3222 | |
| 3223 | // Calculate power with integer exponent. |
| 3224 | __ bind(&int_exponent); |
| 3225 | const XMMRegister double_scratch2 = double_exponent; |
| 3226 | __ mov(scratch, exponent); // Back up exponent. |
| 3227 | __ movsd(double_scratch, double_base); // Back up base. |
| 3228 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3229 | |
| 3230 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3231 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3232 | __ test(scratch, scratch); |
| 3233 | __ j(positive, &no_neg, Label::kNear); |
| 3234 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3235 | __ bind(&no_neg); |
| 3236 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3237 | __ j(zero, &while_false, Label::kNear); |
| 3238 | __ shr(scratch, 1); |
| 3239 | // Above condition means CF==0 && ZF==0. This means that the |
| 3240 | // bit that has been shifted out is 0 and the result is not 0. |
| 3241 | __ j(above, &while_true, Label::kNear); |
| 3242 | __ movsd(double_result, double_scratch); |
| 3243 | __ j(zero, &while_false, Label::kNear); |
| 3244 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3245 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3246 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3247 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3248 | __ j(above, &while_true, Label::kNear); |
| 3249 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3250 | __ j(not_zero, &while_true); |
| 3251 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3252 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3253 | // scratch has the original value of the exponent - if the exponent is |
| 3254 | // negative, return 1/result. |
| 3255 | __ test(exponent, exponent); |
| 3256 | __ j(positive, &done); |
| 3257 | __ divsd(double_scratch2, double_result); |
| 3258 | __ movsd(double_result, double_scratch2); |
| 3259 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3260 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3261 | __ xorps(double_scratch2, double_scratch2); |
| 3262 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3263 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3264 | // and may not have contained the exponent value in the first place when the |
| 3265 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3266 | __ j(not_equal, &done); |
| 3267 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3268 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3269 | // Returning or bailing out. |
| 3270 | Counters* counters = masm->isolate()->counters(); |
| 3271 | if (exponent_type_ == ON_STACK) { |
| 3272 | // The arguments are still on the stack. |
| 3273 | __ bind(&call_runtime); |
| 3274 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3275 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3276 | // The stub is called from non-optimized code, which expects the result |
| 3277 | // as heap number in exponent. |
| 3278 | __ bind(&done); |
| 3279 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3280 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3281 | __ IncrementCounter(counters->math_pow(), 1); |
| 3282 | __ ret(2 * kPointerSize); |
| 3283 | } else { |
| 3284 | __ bind(&call_runtime); |
| 3285 | { |
| 3286 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3287 | __ PrepareCallCFunction(4, scratch); |
| 3288 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3289 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3290 | __ CallCFunction( |
| 3291 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3292 | } |
| 3293 | // Return value is in st(0) on ia32. |
| 3294 | // Store it into the (fixed) result register. |
| 3295 | __ sub(esp, Immediate(kDoubleSize)); |
| 3296 | __ fstp_d(Operand(esp, 0)); |
| 3297 | __ movdbl(double_result, Operand(esp, 0)); |
| 3298 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3299 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3300 | __ bind(&done); |
| 3301 | __ IncrementCounter(counters->math_pow(), 1); |
| 3302 | __ ret(0); |
| 3303 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3307 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3308 | // ----------- S t a t e ------------- |
| 3309 | // -- ecx : name |
| 3310 | // -- edx : receiver |
| 3311 | // -- esp[0] : return address |
| 3312 | // ----------------------------------- |
| 3313 | Label miss; |
| 3314 | |
| 3315 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3316 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3317 | __ j(not_equal, &miss); |
| 3318 | } |
| 3319 | |
| 3320 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3321 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3322 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3327 | // ----------- S t a t e ------------- |
| 3328 | // -- ecx : name |
| 3329 | // -- edx : receiver |
| 3330 | // -- esp[0] : return address |
| 3331 | // ----------------------------------- |
| 3332 | Label miss; |
| 3333 | |
| 3334 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3335 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3336 | __ j(not_equal, &miss); |
| 3337 | } |
| 3338 | |
| 3339 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3340 | support_wrapper_); |
| 3341 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3342 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3346 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3347 | // ----------- S t a t e ------------- |
| 3348 | // -- eax : value |
| 3349 | // -- ecx : name |
| 3350 | // -- edx : receiver |
| 3351 | // -- esp[0] : return address |
| 3352 | // ----------------------------------- |
| 3353 | // |
| 3354 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3355 | // (currently anything except for external arrays which means anything with |
| 3356 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3357 | // accepted as the most common case. |
| 3358 | |
| 3359 | Label miss; |
| 3360 | |
| 3361 | Register receiver = edx; |
| 3362 | Register value = eax; |
| 3363 | Register scratch = ebx; |
| 3364 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3365 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3366 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3367 | __ j(not_equal, &miss); |
| 3368 | } |
| 3369 | |
| 3370 | // Check that the receiver isn't a smi. |
| 3371 | __ JumpIfSmi(receiver, &miss); |
| 3372 | |
| 3373 | // Check that the object is a JS array. |
| 3374 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3375 | __ j(not_equal, &miss); |
| 3376 | |
| 3377 | // Check that elements are FixedArray. |
| 3378 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3379 | // fast elements (including COW). |
| 3380 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3381 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3382 | __ j(not_equal, &miss); |
| 3383 | |
| 3384 | // Check that the array has fast properties, otherwise the length |
| 3385 | // property might have been redefined. |
| 3386 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3387 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3388 | Heap::kHashTableMapRootIndex); |
| 3389 | __ j(equal, &miss); |
| 3390 | |
| 3391 | // Check that value is a smi. |
| 3392 | __ JumpIfNotSmi(value, &miss); |
| 3393 | |
| 3394 | // Prepare tail call to StoreIC_ArrayLength. |
| 3395 | __ pop(scratch); |
| 3396 | __ push(receiver); |
| 3397 | __ push(value); |
| 3398 | __ push(scratch); // return address |
| 3399 | |
| 3400 | ExternalReference ref = |
| 3401 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3402 | __ TailCallExternalReference(ref, 2, 1); |
| 3403 | |
| 3404 | __ bind(&miss); |
| 3405 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3406 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3410 | void LoadFieldStub::Generate(MacroAssembler* masm) { |
| 3411 | StubCompiler::DoGenerateFastPropertyLoad(masm, eax, reg_, inobject_, index_); |
| 3412 | __ ret(0); |
| 3413 | } |
| 3414 | |
| 3415 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3416 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3417 | // The key is in edx and the parameter count is in eax. |
| 3418 | |
| 3419 | // The displacement is used for skipping the frame pointer on the |
| 3420 | // stack. It is the offset of the last parameter (if any) relative |
| 3421 | // to the frame pointer. |
| 3422 | static const int kDisplacement = 1 * kPointerSize; |
| 3423 | |
| 3424 | // Check that the key is a smi. |
| 3425 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3426 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3427 | |
| 3428 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3429 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3431 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3432 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3433 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3434 | |
| 3435 | // Check index against formal parameters count limit passed in |
| 3436 | // through register eax. Use unsigned comparison to get negative |
| 3437 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3438 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3439 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3440 | |
| 3441 | // Read the argument from the stack and return it. |
| 3442 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3443 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3444 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3445 | __ neg(edx); |
| 3446 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3447 | __ ret(0); |
| 3448 | |
| 3449 | // Arguments adaptor case: Check index against actual arguments |
| 3450 | // limit found in the arguments adaptor frame. Use unsigned |
| 3451 | // comparison to get negative check for free. |
| 3452 | __ bind(&adaptor); |
| 3453 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3454 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3455 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3456 | |
| 3457 | // Read the argument from the stack and return it. |
| 3458 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3459 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3460 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3461 | __ neg(edx); |
| 3462 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3463 | __ ret(0); |
| 3464 | |
| 3465 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3466 | // by calling the runtime system. |
| 3467 | __ bind(&slow); |
| 3468 | __ pop(ebx); // Return address. |
| 3469 | __ push(edx); |
| 3470 | __ push(ebx); |
| 3471 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3472 | } |
| 3473 | |
| 3474 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3475 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3476 | // esp[0] : return address |
| 3477 | // esp[4] : number of parameters |
| 3478 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3479 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3480 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3481 | // Check if the calling frame is an arguments adaptor frame. |
| 3482 | Label runtime; |
| 3483 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3484 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3485 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3486 | __ j(not_equal, &runtime, Label::kNear); |
| 3487 | |
| 3488 | // Patch the arguments.length and the parameters pointer. |
| 3489 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3490 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3491 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3492 | StandardFrameConstants::kCallerSPOffset)); |
| 3493 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3494 | |
| 3495 | __ bind(&runtime); |
| 3496 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3497 | } |
| 3498 | |
| 3499 | |
| 3500 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3501 | // esp[0] : return address |
| 3502 | // esp[4] : number of parameters (tagged) |
| 3503 | // esp[8] : receiver displacement |
| 3504 | // esp[12] : function |
| 3505 | |
| 3506 | // ebx = parameter count (tagged) |
| 3507 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3508 | |
| 3509 | // Check if the calling frame is an arguments adaptor frame. |
| 3510 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3511 | // Generate* functions. |
| 3512 | Label runtime; |
| 3513 | Label adaptor_frame, try_allocate; |
| 3514 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3515 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3516 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3517 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3518 | |
| 3519 | // No adaptor, parameter count = argument count. |
| 3520 | __ mov(ecx, ebx); |
| 3521 | __ jmp(&try_allocate, Label::kNear); |
| 3522 | |
| 3523 | // We have an adaptor frame. Patch the parameters pointer. |
| 3524 | __ bind(&adaptor_frame); |
| 3525 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3526 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3527 | StandardFrameConstants::kCallerSPOffset)); |
| 3528 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3529 | |
| 3530 | // ebx = parameter count (tagged) |
| 3531 | // ecx = argument count (tagged) |
| 3532 | // esp[4] = parameter count (tagged) |
| 3533 | // esp[8] = address of receiver argument |
| 3534 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3535 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3536 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3537 | __ mov(ebx, ecx); |
| 3538 | |
| 3539 | __ bind(&try_allocate); |
| 3540 | |
| 3541 | // Save mapped parameter count. |
| 3542 | __ push(ebx); |
| 3543 | |
| 3544 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3545 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3546 | const int kParameterMapHeaderSize = |
| 3547 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3548 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3549 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3550 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3551 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3552 | __ bind(&no_parameter_map); |
| 3553 | |
| 3554 | // 2. Backing store. |
| 3555 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3556 | |
| 3557 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3558 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3559 | |
| 3560 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 3561 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3562 | |
| 3563 | // eax = address of new object(s) (tagged) |
| 3564 | // ecx = argument count (tagged) |
| 3565 | // esp[0] = mapped parameter count (tagged) |
| 3566 | // esp[8] = parameter count (tagged) |
| 3567 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3568 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3569 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3570 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3571 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3572 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3573 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3574 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3575 | __ mov(edi, Operand(edi, |
| 3576 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3577 | __ jmp(©, Label::kNear); |
| 3578 | |
| 3579 | __ bind(&has_mapped_parameters); |
| 3580 | __ mov(edi, Operand(edi, |
| 3581 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3582 | __ bind(©); |
| 3583 | |
| 3584 | // eax = address of new object (tagged) |
| 3585 | // ebx = mapped parameter count (tagged) |
| 3586 | // ecx = argument count (tagged) |
| 3587 | // edi = address of boilerplate object (tagged) |
| 3588 | // esp[0] = mapped parameter count (tagged) |
| 3589 | // esp[8] = parameter count (tagged) |
| 3590 | // esp[12] = address of receiver argument |
| 3591 | // Copy the JS object part. |
| 3592 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3593 | __ mov(edx, FieldOperand(edi, i)); |
| 3594 | __ mov(FieldOperand(eax, i), edx); |
| 3595 | } |
| 3596 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3597 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3598 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3599 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3600 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3601 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3602 | edx); |
| 3603 | |
| 3604 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3605 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3606 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3607 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3608 | ecx); |
| 3609 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3610 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3611 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3612 | // backing store. |
| 3613 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3614 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3615 | |
| 3616 | // eax = address of new object (tagged) |
| 3617 | // ebx = mapped parameter count (tagged) |
| 3618 | // ecx = argument count (tagged) |
| 3619 | // edi = address of parameter map or backing store (tagged) |
| 3620 | // esp[0] = mapped parameter count (tagged) |
| 3621 | // esp[8] = parameter count (tagged) |
| 3622 | // esp[12] = address of receiver argument |
| 3623 | // Free a register. |
| 3624 | __ push(eax); |
| 3625 | |
| 3626 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3627 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3628 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3629 | __ j(zero, &skip_parameter_map); |
| 3630 | |
| 3631 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3632 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3633 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3634 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3635 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3636 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3637 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3638 | |
| 3639 | // Copy the parameter slots and the holes in the arguments. |
| 3640 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3641 | // where parameters are stored in reverse order, at |
| 3642 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3643 | // The mapped parameter thus need to get indices |
| 3644 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3645 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3646 | // We loop from right to left. |
| 3647 | Label parameters_loop, parameters_test; |
| 3648 | __ push(ecx); |
| 3649 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3650 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3651 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3652 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3653 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3654 | __ mov(edx, edi); |
| 3655 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3656 | // eax = loop variable (tagged) |
| 3657 | // ebx = mapping index (tagged) |
| 3658 | // ecx = the hole value |
| 3659 | // edx = address of parameter map (tagged) |
| 3660 | // edi = address of backing store (tagged) |
| 3661 | // esp[0] = argument count (tagged) |
| 3662 | // esp[4] = address of new object (tagged) |
| 3663 | // esp[8] = mapped parameter count (tagged) |
| 3664 | // esp[16] = parameter count (tagged) |
| 3665 | // esp[20] = address of receiver argument |
| 3666 | __ jmp(¶meters_test, Label::kNear); |
| 3667 | |
| 3668 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3669 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3670 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3671 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3672 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3673 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3674 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3675 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3676 | __ pop(ecx); |
| 3677 | |
| 3678 | __ bind(&skip_parameter_map); |
| 3679 | |
| 3680 | // ecx = argument count (tagged) |
| 3681 | // edi = address of backing store (tagged) |
| 3682 | // esp[0] = address of new object (tagged) |
| 3683 | // esp[4] = mapped parameter count (tagged) |
| 3684 | // esp[12] = parameter count (tagged) |
| 3685 | // esp[16] = address of receiver argument |
| 3686 | // Copy arguments header and remaining slots (if there are any). |
| 3687 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3688 | Immediate(FACTORY->fixed_array_map())); |
| 3689 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3690 | |
| 3691 | Label arguments_loop, arguments_test; |
| 3692 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3693 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3694 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3695 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3696 | __ jmp(&arguments_test, Label::kNear); |
| 3697 | |
| 3698 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3699 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3700 | __ mov(eax, Operand(edx, 0)); |
| 3701 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3702 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3703 | |
| 3704 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3705 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3706 | __ j(less, &arguments_loop, Label::kNear); |
| 3707 | |
| 3708 | // Restore. |
| 3709 | __ pop(eax); // Address of arguments object. |
| 3710 | __ pop(ebx); // Parameter count. |
| 3711 | |
| 3712 | // Return and remove the on-stack parameters. |
| 3713 | __ ret(3 * kPointerSize); |
| 3714 | |
| 3715 | // Do the runtime call to allocate the arguments object. |
| 3716 | __ bind(&runtime); |
| 3717 | __ pop(eax); // Remove saved parameter count. |
| 3718 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3719 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | |
| 3723 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3724 | // esp[0] : return address |
| 3725 | // esp[4] : number of parameters |
| 3726 | // esp[8] : receiver displacement |
| 3727 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3728 | |
| 3729 | // Check if the calling frame is an arguments adaptor frame. |
| 3730 | Label adaptor_frame, try_allocate, runtime; |
| 3731 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3732 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3733 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3734 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3735 | |
| 3736 | // Get the length from the frame. |
| 3737 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3738 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3739 | |
| 3740 | // Patch the arguments.length and the parameters pointer. |
| 3741 | __ bind(&adaptor_frame); |
| 3742 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3743 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3744 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3745 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3746 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3747 | |
| 3748 | // Try the new space allocation. Start out with computing the size of |
| 3749 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3750 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3751 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3752 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3753 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3754 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3755 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3756 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3757 | |
| 3758 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 3759 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3760 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3761 | // Get the arguments boilerplate from the current native context. |
| 3762 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3763 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3764 | const int offset = |
| 3765 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3766 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3767 | |
| 3768 | // Copy the JS object part. |
| 3769 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3770 | __ mov(ebx, FieldOperand(edi, i)); |
| 3771 | __ mov(FieldOperand(eax, i), ebx); |
| 3772 | } |
| 3773 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3774 | // 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] | 3775 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3776 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3777 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3778 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3779 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3780 | |
| 3781 | // If there are no actual arguments, we're done. |
| 3782 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3783 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3784 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3785 | |
| 3786 | // Get the parameters pointer from the stack. |
| 3787 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3788 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3789 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3790 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3791 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3792 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3793 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3794 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3795 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3796 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3797 | // Untag the length for the loop below. |
| 3798 | __ SmiUntag(ecx); |
| 3799 | |
| 3800 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3801 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3802 | __ bind(&loop); |
| 3803 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3804 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3805 | __ add(edi, Immediate(kPointerSize)); |
| 3806 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3807 | __ dec(ecx); |
| 3808 | __ j(not_zero, &loop); |
| 3809 | |
| 3810 | // Return and remove the on-stack parameters. |
| 3811 | __ bind(&done); |
| 3812 | __ ret(3 * kPointerSize); |
| 3813 | |
| 3814 | // Do the runtime call to allocate the arguments object. |
| 3815 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3816 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3821 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3822 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3823 | // at compilation. |
| 3824 | #ifdef V8_INTERPRETED_REGEXP |
| 3825 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3826 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3827 | |
| 3828 | // Stack frame on entry. |
| 3829 | // esp[0]: return address |
| 3830 | // esp[4]: last_match_info (expected JSArray) |
| 3831 | // esp[8]: previous index |
| 3832 | // esp[12]: subject string |
| 3833 | // esp[16]: JSRegExp object |
| 3834 | |
| 3835 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3836 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3837 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3838 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3839 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3840 | Label runtime; |
| 3841 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3842 | |
| 3843 | // Ensure that a RegExp stack is allocated. |
| 3844 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3845 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3846 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3847 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3848 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3849 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3850 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3851 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3852 | |
| 3853 | // Check that the first argument is a JSRegExp object. |
| 3854 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3855 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3856 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3857 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3858 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3859 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3860 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3861 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3862 | if (FLAG_debug_code) { |
| 3863 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3864 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3865 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3866 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3867 | } |
| 3868 | |
| 3869 | // ecx: RegExp data (FixedArray) |
| 3870 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3871 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3872 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3873 | __ j(not_equal, &runtime); |
| 3874 | |
| 3875 | // ecx: RegExp data (FixedArray) |
| 3876 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3877 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3878 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3879 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3880 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3881 | STATIC_ASSERT(kSmiTag == 0); |
| 3882 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3883 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3884 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3885 | __ j(above, &runtime); |
| 3886 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3887 | // Reset offset for possibly sliced string. |
| 3888 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3889 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3890 | __ JumpIfSmi(eax, &runtime); |
| 3891 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3893 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3894 | |
| 3895 | // eax: subject string |
| 3896 | // edx: subject string |
| 3897 | // ebx: subject string instance type |
| 3898 | // ecx: RegExp data (FixedArray) |
| 3899 | // Handle subject string according to its encoding and representation: |
| 3900 | // (1) Sequential two byte? If yes, go to (9). |
| 3901 | // (2) Sequential one byte? If yes, go to (6). |
| 3902 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3903 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3904 | // Otherwise bailout. |
| 3905 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3906 | // (5b) Is subject external? If yes, go to (8). |
| 3907 | // (6) One byte sequential. Load regexp code for one byte. |
| 3908 | // (E) Carry on. |
| 3909 | /// [...] |
| 3910 | |
| 3911 | // Deferred code at the end of the stub: |
| 3912 | // (7) Not a long external string? If yes, go to (10). |
| 3913 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3914 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3915 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3916 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3917 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3918 | |
| 3919 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3920 | external_string /* 8 */, check_underlying /* 5a */, |
| 3921 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3922 | not_long_external /* 10 */; |
| 3923 | |
| 3924 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3925 | __ and_(ebx, kIsNotStringMask | |
| 3926 | kStringRepresentationMask | |
| 3927 | kStringEncodingMask | |
| 3928 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3929 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3930 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3931 | |
| 3932 | // (2) Sequential one byte? If yes, go to (6). |
| 3933 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3934 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3935 | kStringRepresentationMask | |
| 3936 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3937 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3938 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3939 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3940 | // We check whether the subject string is a cons, since sequential strings |
| 3941 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3942 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3943 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3944 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3945 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3946 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3947 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3948 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3949 | // (4) Cons string. Check that it's flat. |
| 3950 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3951 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3952 | __ j(not_equal, &runtime); |
| 3953 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3954 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3955 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3956 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3957 | |
| 3958 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3959 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3960 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3961 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3962 | // (5b) Is subject external? If yes, go to (8). |
| 3963 | __ test_b(ebx, kStringRepresentationMask); |
| 3964 | // The underlying external string is never a short external string. |
| 3965 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3966 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3967 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3968 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3969 | // eax: sequential subject string (or look-alike, external string) |
| 3970 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3972 | // (6) One byte sequential. Load regexp code for one byte. |
| 3973 | __ bind(&seq_one_byte_string); |
| 3974 | // Load previous index and check range before edx is overwritten. We have |
| 3975 | // to use edx instead of eax here because it might have been only made to |
| 3976 | // look like a sequential string when it actually is an external string. |
| 3977 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3978 | __ JumpIfNotSmi(ebx, &runtime); |
| 3979 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3980 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3981 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3982 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3983 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3984 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3985 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3986 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3987 | // Check that the irregexp code has been generated for the actual string |
| 3988 | // 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] | 3989 | // a smi (code flushing support). |
| 3990 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3991 | |
| 3992 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3993 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3994 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3995 | // 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] | 3996 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3997 | Counters* counters = masm->isolate()->counters(); |
| 3998 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3999 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4000 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4001 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4002 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4003 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4004 | // Argument 9: Pass current isolate address. |
| 4005 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4006 | Immediate(ExternalReference::isolate_address())); |
| 4007 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4008 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 4009 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4010 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4011 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4012 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 4013 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4014 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 4015 | |
| 4016 | // Argument 6: Set the number of capture registers to zero to force global |
| 4017 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 4018 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4019 | |
| 4020 | // Argument 5: static offsets vector buffer. |
| 4021 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4022 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 4023 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4024 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4025 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4026 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4027 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 4028 | |
| 4029 | // Argument 1: Original subject string. |
| 4030 | // The original subject is in the previous stack frame. Therefore we have to |
| 4031 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 4032 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 4033 | // and thereby moves up esp by one kPointerSize.) |
| 4034 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 4035 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 4036 | |
| 4037 | // esi: original subject string |
| 4038 | // eax: underlying subject string |
| 4039 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4040 | // 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] | 4041 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4042 | // Argument 4: End of string data |
| 4043 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4044 | // Prepare start and end index of the input. |
| 4045 | // Load the length from the original sliced string if that is the case. |
| 4046 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4047 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4048 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4049 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4050 | |
| 4051 | // ebx: start index of the input string |
| 4052 | // esi: end index of the input string |
| 4053 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4054 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4055 | __ j(zero, &setup_two_byte, Label::kNear); |
| 4056 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4057 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4058 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4059 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4060 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4061 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4062 | |
| 4063 | __ bind(&setup_two_byte); |
| 4064 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4065 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 4066 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4067 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 4068 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 4069 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 4070 | |
| 4071 | __ bind(&setup_rest); |
| 4072 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4073 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4074 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 4075 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4076 | |
| 4077 | // Drop arguments and come back to JS mode. |
| 4078 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4079 | |
| 4080 | // Check the result. |
| 4081 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4082 | __ cmp(eax, 1); |
| 4083 | // We expect exactly one result since we force the called regexp to behave |
| 4084 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4085 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4086 | Label failure; |
| 4087 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4088 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4089 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 4090 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4091 | __ j(not_equal, &runtime); |
| 4092 | // Result must now be exception. If there is no pending exception already a |
| 4093 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4094 | // haven't created the exception yet. Handle that in the runtime system. |
| 4095 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4096 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4097 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4098 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4099 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4100 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4101 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4102 | // For exception, throw the exception again. |
| 4103 | |
| 4104 | // Clear the pending exception variable. |
| 4105 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4106 | |
| 4107 | // Special handling of termination exceptions which are uncatchable |
| 4108 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4109 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4110 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4111 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4112 | |
| 4113 | // Handle normal exception by following handler chain. |
| 4114 | __ Throw(eax); |
| 4115 | |
| 4116 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4117 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4118 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4119 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4120 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4121 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4122 | __ ret(4 * kPointerSize); |
| 4123 | |
| 4124 | // Load RegExp data. |
| 4125 | __ bind(&success); |
| 4126 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4127 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4128 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4129 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4130 | STATIC_ASSERT(kSmiTag == 0); |
| 4131 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4132 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4133 | |
| 4134 | // edx: Number of capture registers |
| 4135 | // 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] | 4136 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4137 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4138 | __ JumpIfSmi(eax, &runtime); |
| 4139 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 4140 | __ j(not_equal, &runtime); |
| 4141 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4142 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4143 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 4144 | __ cmp(eax, factory->fixed_array_map()); |
| 4145 | __ j(not_equal, &runtime); |
| 4146 | // Check that the last match info has space for the capture registers and the |
| 4147 | // additional information. |
| 4148 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 4149 | __ SmiUntag(eax); |
| 4150 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 4151 | __ cmp(edx, eax); |
| 4152 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4153 | |
| 4154 | // ebx: last_match_info backing store (FixedArray) |
| 4155 | // edx: number of capture registers |
| 4156 | // Store the capture count. |
| 4157 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4158 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4159 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4160 | // Store last subject and last input. |
| 4161 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4162 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4163 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4164 | __ RecordWriteField(ebx, |
| 4165 | RegExpImpl::kLastSubjectOffset, |
| 4166 | eax, |
| 4167 | edi, |
| 4168 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4169 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4170 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4171 | __ RecordWriteField(ebx, |
| 4172 | RegExpImpl::kLastInputOffset, |
| 4173 | eax, |
| 4174 | edi, |
| 4175 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4176 | |
| 4177 | // Get the static offsets vector filled by the native regexp code. |
| 4178 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4179 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4181 | |
| 4182 | // ebx: last_match_info backing store (FixedArray) |
| 4183 | // ecx: offsets vector |
| 4184 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4185 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4186 | // Capture register counter starts from number of capture registers and |
| 4187 | // counts down until wraping after zero. |
| 4188 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4189 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4190 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4191 | // Read the value from the static offsets vector buffer. |
| 4192 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4193 | __ SmiTag(edi); |
| 4194 | // Store the smi value in the last match info. |
| 4195 | __ mov(FieldOperand(ebx, |
| 4196 | edx, |
| 4197 | times_pointer_size, |
| 4198 | RegExpImpl::kFirstCaptureOffset), |
| 4199 | edi); |
| 4200 | __ jmp(&next_capture); |
| 4201 | __ bind(&done); |
| 4202 | |
| 4203 | // Return last match info. |
| 4204 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4205 | __ ret(4 * kPointerSize); |
| 4206 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4207 | // Do the runtime call to execute the regexp. |
| 4208 | __ bind(&runtime); |
| 4209 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4210 | |
| 4211 | // Deferred code for string handling. |
| 4212 | // (7) Not a long external string? If yes, go to (10). |
| 4213 | __ bind(¬_seq_nor_cons); |
| 4214 | // Compare flags are still set from (3). |
| 4215 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4216 | |
| 4217 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4218 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4219 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4220 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4221 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4222 | if (FLAG_debug_code) { |
| 4223 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4224 | // Sequential strings have already been ruled out. |
| 4225 | __ test_b(ebx, kIsIndirectStringMask); |
| 4226 | __ Assert(zero, "external string expected, but not found"); |
| 4227 | } |
| 4228 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4229 | // 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] | 4230 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4231 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4232 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4233 | // (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] | 4234 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4235 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4236 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4237 | // eax: sequential subject string (or look-alike, external string) |
| 4238 | // edx: original subject string |
| 4239 | // ecx: RegExp data (FixedArray) |
| 4240 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4241 | __ bind(&seq_two_byte_string); |
| 4242 | // Load previous index and check range before edx is overwritten. We have |
| 4243 | // to use edx instead of eax here because it might have been only made to |
| 4244 | // look like a sequential string when it actually is an external string. |
| 4245 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4246 | __ JumpIfNotSmi(ebx, &runtime); |
| 4247 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4248 | __ j(above_equal, &runtime); |
| 4249 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4250 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4251 | __ jmp(&check_code); // Go to (E). |
| 4252 | |
| 4253 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4254 | __ bind(¬_long_external); |
| 4255 | // Catch non-string subject or short external string. |
| 4256 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4257 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4258 | __ j(not_zero, &runtime); |
| 4259 | |
| 4260 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4261 | // Load offset into edi and replace subject string with parent. |
| 4262 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4263 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4264 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4265 | #endif // V8_INTERPRETED_REGEXP |
| 4266 | } |
| 4267 | |
| 4268 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4269 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4270 | const int kMaxInlineLength = 100; |
| 4271 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4272 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4273 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4274 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4275 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4276 | __ j(above, &slowcase); |
| 4277 | // Smi-tagging is equivalent to multiplying by 2. |
| 4278 | STATIC_ASSERT(kSmiTag == 0); |
| 4279 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4280 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4281 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4282 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 4283 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4284 | times_pointer_size, |
| 4285 | ebx, // In: Number of elements as a smi |
| 4286 | REGISTER_VALUE_IS_SMI, |
| 4287 | eax, // Out: Start of allocation (tagged). |
| 4288 | ecx, // Out: End of allocation. |
| 4289 | edx, // Scratch register |
| 4290 | &slowcase, |
| 4291 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4292 | // eax: Start of allocated area, object-tagged. |
| 4293 | |
| 4294 | // Set JSArray map to global.regexp_result_map(). |
| 4295 | // Set empty properties FixedArray. |
| 4296 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4297 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4298 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4299 | Factory* factory = masm->isolate()->factory(); |
| 4300 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4301 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4302 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4303 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4304 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4305 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4306 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4307 | |
| 4308 | // Set input, index and length fields from arguments. |
| 4309 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4310 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4311 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4312 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4313 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4314 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4315 | |
| 4316 | // Fill out the elements FixedArray. |
| 4317 | // eax: JSArray. |
| 4318 | // ebx: FixedArray. |
| 4319 | // ecx: Number of elements in array, as smi. |
| 4320 | |
| 4321 | // Set map. |
| 4322 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4323 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4324 | // Set length. |
| 4325 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4326 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4327 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4328 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4329 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4330 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4331 | // eax: JSArray. |
| 4332 | // ecx: Number of elements to fill. |
| 4333 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4334 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4335 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4336 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4337 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4338 | __ 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] | 4339 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4340 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4341 | __ jmp(&loop); |
| 4342 | |
| 4343 | __ bind(&done); |
| 4344 | __ ret(3 * kPointerSize); |
| 4345 | |
| 4346 | __ bind(&slowcase); |
| 4347 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4348 | } |
| 4349 | |
| 4350 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4351 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4352 | Register object, |
| 4353 | Register result, |
| 4354 | Register scratch1, |
| 4355 | Register scratch2, |
| 4356 | bool object_is_smi, |
| 4357 | Label* not_found) { |
| 4358 | // Use of registers. Register result is used as a temporary. |
| 4359 | Register number_string_cache = result; |
| 4360 | Register mask = scratch1; |
| 4361 | Register scratch = scratch2; |
| 4362 | |
| 4363 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4364 | ExternalReference roots_array_start = |
| 4365 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4366 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4367 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4368 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4369 | // Make the hash mask from the length of the number string cache. It |
| 4370 | // contains two elements (number and string) for each cache entry. |
| 4371 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4372 | __ 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] | 4373 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4374 | |
| 4375 | // Calculate the entry in the number string cache. The hash value in the |
| 4376 | // number string cache for smis is just the smi value, and the hash for |
| 4377 | // doubles is the xor of the upper and lower words. See |
| 4378 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4379 | Label smi_hash_calculated; |
| 4380 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | if (object_is_smi) { |
| 4382 | __ mov(scratch, object); |
| 4383 | __ SmiUntag(scratch); |
| 4384 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4385 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4386 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4387 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4388 | __ mov(scratch, object); |
| 4389 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4390 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4391 | __ bind(¬_smi); |
| 4392 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4393 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4394 | __ j(not_equal, not_found); |
| 4395 | STATIC_ASSERT(8 == kDoubleSize); |
| 4396 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4397 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4398 | // 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] | 4399 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4400 | Register index = scratch; |
| 4401 | Register probe = mask; |
| 4402 | __ mov(probe, |
| 4403 | FieldOperand(number_string_cache, |
| 4404 | index, |
| 4405 | times_twice_pointer_size, |
| 4406 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4407 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4408 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4409 | CpuFeatureScope fscope(masm, SSE2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4410 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4411 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4412 | __ ucomisd(xmm0, xmm1); |
| 4413 | } else { |
| 4414 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4415 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4416 | __ FCmp(); |
| 4417 | } |
| 4418 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4419 | __ 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] | 4420 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | __ bind(&smi_hash_calculated); |
| 4424 | // 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] | 4425 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4426 | Register index = scratch; |
| 4427 | // Check if the entry is the smi we are looking for. |
| 4428 | __ cmp(object, |
| 4429 | FieldOperand(number_string_cache, |
| 4430 | index, |
| 4431 | times_twice_pointer_size, |
| 4432 | FixedArray::kHeaderSize)); |
| 4433 | __ j(not_equal, not_found); |
| 4434 | |
| 4435 | // Get the result from the cache. |
| 4436 | __ bind(&load_result_from_cache); |
| 4437 | __ mov(result, |
| 4438 | FieldOperand(number_string_cache, |
| 4439 | index, |
| 4440 | times_twice_pointer_size, |
| 4441 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4442 | Counters* counters = masm->isolate()->counters(); |
| 4443 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | |
| 4447 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4448 | Label runtime; |
| 4449 | |
| 4450 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4451 | |
| 4452 | // Generate code to lookup number in the number string cache. |
| 4453 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4454 | __ ret(1 * kPointerSize); |
| 4455 | |
| 4456 | __ bind(&runtime); |
| 4457 | // Handle number to string in the runtime system if not found in the cache. |
| 4458 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4459 | } |
| 4460 | |
| 4461 | |
| 4462 | static int NegativeComparisonResult(Condition cc) { |
| 4463 | ASSERT(cc != equal); |
| 4464 | ASSERT((cc == less) || (cc == less_equal) |
| 4465 | || (cc == greater) || (cc == greater_equal)); |
| 4466 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4467 | } |
| 4468 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4469 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4470 | static void CheckInputType(MacroAssembler* masm, |
| 4471 | Register input, |
| 4472 | CompareIC::State expected, |
| 4473 | Label* fail) { |
| 4474 | Label ok; |
| 4475 | if (expected == CompareIC::SMI) { |
| 4476 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4477 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4478 | __ JumpIfSmi(input, &ok); |
| 4479 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4480 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4481 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4482 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4483 | // 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] | 4484 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4485 | __ bind(&ok); |
| 4486 | } |
| 4487 | |
| 4488 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4489 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4490 | Label* label, |
| 4491 | Register object, |
| 4492 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4493 | __ JumpIfSmi(object, label); |
| 4494 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4495 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4496 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4497 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4498 | __ j(not_equal, label); |
| 4499 | } |
| 4500 | |
| 4501 | |
| 4502 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4503 | Label check_unequal_objects; |
| 4504 | Condition cc = GetCondition(); |
| 4505 | |
| 4506 | Label miss; |
| 4507 | CheckInputType(masm, edx, left_, &miss); |
| 4508 | CheckInputType(masm, eax, right_, &miss); |
| 4509 | |
| 4510 | // Compare two smis. |
| 4511 | Label non_smi, smi_done; |
| 4512 | __ mov(ecx, edx); |
| 4513 | __ or_(ecx, eax); |
| 4514 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4515 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4516 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4517 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4518 | __ bind(&smi_done); |
| 4519 | __ mov(eax, edx); |
| 4520 | __ ret(0); |
| 4521 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4522 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4523 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4524 | // it is certain that at least one operand isn't a smi. |
| 4525 | |
| 4526 | // Identical objects can be compared fast, but there are some tricky cases |
| 4527 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 4528 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 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 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 4545 | // Test for NaN. Compare heap numbers in a general way, |
| 4546 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4547 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4548 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 4549 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4550 | if (cc != equal) { |
| 4551 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4552 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4553 | __ j(above_equal, ¬_identical); |
| 4554 | } |
| 4555 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4556 | __ ret(0); |
| 4557 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4558 | |
| 4559 | __ bind(¬_identical); |
| 4560 | } |
| 4561 | |
| 4562 | // Strict equality can quickly decide whether objects are equal. |
| 4563 | // 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] | 4564 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4565 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4566 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4567 | // If we're doing a strict equality comparison, we don't have to do |
| 4568 | // type conversion, so we generate code to do fast comparison for objects |
| 4569 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4570 | // slow-case code. |
| 4571 | // If either is a Smi (we know that not both are), then they can only |
| 4572 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4573 | STATIC_ASSERT(kSmiTag == 0); |
| 4574 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4575 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4576 | __ and_(ecx, eax); |
| 4577 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4578 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4579 | // One operand is a smi. |
| 4580 | |
| 4581 | // Check whether the non-smi is a heap number. |
| 4582 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4583 | // 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] | 4584 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4586 | __ xor_(ebx, eax); |
| 4587 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4588 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4589 | // if eax was smi, ebx is now edx, else eax. |
| 4590 | |
| 4591 | // Check if the non-smi operand is a heap number. |
| 4592 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4593 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4594 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4595 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4596 | // Return non-equal (ebx is not zero) |
| 4597 | __ mov(eax, ebx); |
| 4598 | __ ret(0); |
| 4599 | |
| 4600 | __ bind(¬_smis); |
| 4601 | // If either operand is a JSObject or an oddball value, then they are not |
| 4602 | // equal since their pointers are different |
| 4603 | // There is no test for undetectability in strict equality. |
| 4604 | |
| 4605 | // Get the type of the first operand. |
| 4606 | // 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] | 4607 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4608 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4609 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4610 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4611 | |
| 4612 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4613 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4614 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4615 | __ bind(&return_not_equal); |
| 4616 | __ ret(0); |
| 4617 | |
| 4618 | __ bind(&first_non_object); |
| 4619 | // Check for oddballs: true, false, null, undefined. |
| 4620 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4621 | __ j(equal, &return_not_equal); |
| 4622 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4623 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4624 | __ j(above_equal, &return_not_equal); |
| 4625 | |
| 4626 | // Check for oddballs: true, false, null, undefined. |
| 4627 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4628 | __ j(equal, &return_not_equal); |
| 4629 | |
| 4630 | // Fall through to the general case. |
| 4631 | __ bind(&slow); |
| 4632 | } |
| 4633 | |
| 4634 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4635 | Label non_number_comparison; |
| 4636 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 4637 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4638 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4639 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4640 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4642 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4643 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4644 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4645 | // Don't base result on EFLAGS when a NaN is involved. |
| 4646 | __ j(parity_even, &unordered, Label::kNear); |
| 4647 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4648 | __ mov(eax, 0); // equal |
| 4649 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4650 | __ cmov(above, eax, ecx); |
| 4651 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4652 | __ cmov(below, eax, ecx); |
| 4653 | __ ret(0); |
| 4654 | } else { |
| 4655 | FloatingPointHelper::CheckFloatOperands( |
| 4656 | masm, &non_number_comparison, ebx); |
| 4657 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4658 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4659 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4660 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4661 | // Don't base result on EFLAGS when a NaN is involved. |
| 4662 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4663 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4664 | Label below_label, above_label; |
| 4665 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4666 | __ j(below, &below_label, Label::kNear); |
| 4667 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4668 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4669 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4670 | __ ret(0); |
| 4671 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4672 | __ bind(&below_label); |
| 4673 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4674 | __ ret(0); |
| 4675 | |
| 4676 | __ bind(&above_label); |
| 4677 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4678 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4681 | // If one of the numbers was NaN, then the result is always false. |
| 4682 | // The cc is never not-equal. |
| 4683 | __ bind(&unordered); |
| 4684 | ASSERT(cc != not_equal); |
| 4685 | if (cc == less || cc == less_equal) { |
| 4686 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4687 | } else { |
| 4688 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4689 | } |
| 4690 | __ ret(0); |
| 4691 | |
| 4692 | // The number comparison code did not provide a valid result. |
| 4693 | __ bind(&non_number_comparison); |
| 4694 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4695 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4696 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4697 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4698 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4699 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4700 | |
| 4701 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4702 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4703 | // non-zero value, which indicates not equal, so just return. |
| 4704 | __ ret(0); |
| 4705 | } |
| 4706 | |
| 4707 | __ bind(&check_for_strings); |
| 4708 | |
| 4709 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4710 | &check_unequal_objects); |
| 4711 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4712 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4713 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4714 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4715 | edx, |
| 4716 | eax, |
| 4717 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4718 | ebx); |
| 4719 | } else { |
| 4720 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4721 | edx, |
| 4722 | eax, |
| 4723 | ecx, |
| 4724 | ebx, |
| 4725 | edi); |
| 4726 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4727 | #ifdef DEBUG |
| 4728 | __ Abort("Unexpected fall-through from string comparison"); |
| 4729 | #endif |
| 4730 | |
| 4731 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4732 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4733 | // Non-strict equality. Objects are unequal if |
| 4734 | // they are both JSObjects and not undetectable, |
| 4735 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4736 | Label not_both_objects; |
| 4737 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4738 | // At most one is a smi, so we can test for smi by adding the two. |
| 4739 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4740 | // a heap object has the low bit clear. |
| 4741 | STATIC_ASSERT(kSmiTag == 0); |
| 4742 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4743 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4744 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4745 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4746 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4747 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4748 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4749 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4750 | // We do not bail out after this point. Both are JSObjects, and |
| 4751 | // they are equal if and only if both are undetectable. |
| 4752 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4753 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4754 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4755 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4756 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4757 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4758 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4759 | // The objects are both undetectable, so they both compare as the value |
| 4760 | // undefined, and are equal. |
| 4761 | __ Set(eax, Immediate(EQUAL)); |
| 4762 | __ bind(&return_unequal); |
| 4763 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4764 | // or return equal if we fell through to here. |
| 4765 | __ ret(0); // rax, rdx were pushed |
| 4766 | __ bind(¬_both_objects); |
| 4767 | } |
| 4768 | |
| 4769 | // Push arguments below the return address. |
| 4770 | __ pop(ecx); |
| 4771 | __ push(edx); |
| 4772 | __ push(eax); |
| 4773 | |
| 4774 | // Figure out which native to call and setup the arguments. |
| 4775 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4776 | if (cc == equal) { |
| 4777 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4778 | } else { |
| 4779 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4780 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | // Restore return address on the stack. |
| 4784 | __ push(ecx); |
| 4785 | |
| 4786 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4787 | // tagged as a small integer. |
| 4788 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4789 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4790 | __ bind(&miss); |
| 4791 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | |
| 4795 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4796 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4800 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4801 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4802 | } |
| 4803 | |
| 4804 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4805 | static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4806 | // Cache the called function in a global property cell. Cache states |
| 4807 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4808 | // megamorphic. |
| 4809 | // ebx : cache cell for call target |
| 4810 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4811 | ASSERT(!FLAG_optimize_constructed_arrays); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4812 | Isolate* isolate = masm->isolate(); |
| 4813 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4814 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4815 | // Load the cache state into ecx. |
| 4816 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4817 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4818 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4819 | // function without changing the state. |
| 4820 | __ cmp(ecx, edi); |
| 4821 | __ j(equal, &done, Label::kNear); |
| 4822 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4823 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4824 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4825 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4826 | // megamorphic. |
| 4827 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4828 | __ j(equal, &initialize, Label::kNear); |
| 4829 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4830 | // write-barrier is needed. |
| 4831 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4832 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4833 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4834 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4835 | // An uninitialized cache is patched with the function. |
| 4836 | __ bind(&initialize); |
| 4837 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4838 | // No need for a write barrier here - cells are rescanned. |
| 4839 | |
| 4840 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4844 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4845 | // Cache the called function in a global property cell. Cache states |
| 4846 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4847 | // megamorphic. |
| 4848 | // ebx : cache cell for call target |
| 4849 | // edi : the function to call |
| 4850 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4851 | Isolate* isolate = masm->isolate(); |
| 4852 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4853 | |
| 4854 | // Load the cache state into ecx. |
| 4855 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 4856 | |
| 4857 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4858 | // function without changing the state. |
| 4859 | __ cmp(ecx, edi); |
| 4860 | __ j(equal, &done); |
| 4861 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4862 | __ j(equal, &done); |
| 4863 | |
| 4864 | // Special handling of the Array() function, which caches not only the |
| 4865 | // monomorphic Array function but the initial ElementsKind with special |
| 4866 | // sentinels |
| 4867 | Handle<Object> terminal_kind_sentinel = |
| 4868 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4869 | LAST_FAST_ELEMENTS_KIND); |
| 4870 | __ cmp(ecx, Immediate(terminal_kind_sentinel)); |
| 4871 | __ j(above, &miss); |
| 4872 | // Load the global or builtins object from the current context |
| 4873 | __ LoadGlobalContext(ecx); |
| 4874 | // Make sure the function is the Array() function |
| 4875 | __ cmp(edi, Operand(ecx, |
| 4876 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4877 | __ j(not_equal, &megamorphic); |
| 4878 | __ jmp(&done); |
| 4879 | |
| 4880 | __ bind(&miss); |
| 4881 | |
| 4882 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4883 | // megamorphic. |
| 4884 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4885 | __ j(equal, &initialize); |
| 4886 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4887 | // write-barrier is needed. |
| 4888 | __ bind(&megamorphic); |
| 4889 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4890 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4891 | __ jmp(&done, Label::kNear); |
| 4892 | |
| 4893 | // An uninitialized cache is patched with the function or sentinel to |
| 4894 | // indicate the ElementsKind if function is the Array constructor. |
| 4895 | __ bind(&initialize); |
| 4896 | __ LoadGlobalContext(ecx); |
| 4897 | // Make sure the function is the Array() function |
| 4898 | __ cmp(edi, Operand(ecx, |
| 4899 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4900 | __ j(not_equal, ¬_array_function); |
| 4901 | |
| 4902 | // The target function is the Array constructor, install a sentinel value in |
| 4903 | // the constructor's type info cell that will track the initial ElementsKind |
| 4904 | // that should be used for the array when its constructed. |
| 4905 | Handle<Object> initial_kind_sentinel = |
| 4906 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4907 | GetInitialFastElementsKind()); |
| 4908 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4909 | Immediate(initial_kind_sentinel)); |
| 4910 | __ jmp(&done); |
| 4911 | |
| 4912 | __ bind(¬_array_function); |
| 4913 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4914 | // No need for a write barrier here - cells are rescanned. |
| 4915 | |
| 4916 | __ bind(&done); |
| 4917 | } |
| 4918 | |
| 4919 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4921 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4922 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4923 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4924 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4925 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4926 | // The receiver might implicitly be the global object. This is |
| 4927 | // indicated by passing the hole as the receiver to the call |
| 4928 | // function stub. |
| 4929 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4930 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4931 | // Get the receiver from the stack. |
| 4932 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4933 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4934 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4935 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4936 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4937 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4938 | __ mov(ecx, GlobalObjectOperand()); |
| 4939 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4940 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4941 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4944 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4945 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4946 | // Goto slow case if we do not have a function. |
| 4947 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4948 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4949 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4950 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4951 | if (FLAG_optimize_constructed_arrays) { |
| 4952 | GenerateRecordCallTarget(masm); |
| 4953 | } else { |
| 4954 | GenerateRecordCallTargetNoArray(masm); |
| 4955 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4958 | // Fast-case: Just invoke the function. |
| 4959 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4960 | |
| 4961 | if (ReceiverMightBeImplicit()) { |
| 4962 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4963 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4964 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4965 | __ InvokeFunction(edi, |
| 4966 | actual, |
| 4967 | JUMP_FUNCTION, |
| 4968 | NullCallWrapper(), |
| 4969 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4970 | __ bind(&call_as_function); |
| 4971 | } |
| 4972 | __ InvokeFunction(edi, |
| 4973 | actual, |
| 4974 | JUMP_FUNCTION, |
| 4975 | NullCallWrapper(), |
| 4976 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4977 | |
| 4978 | // Slow-case: Non-function called. |
| 4979 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4980 | if (RecordCallTarget()) { |
| 4981 | // 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] | 4982 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4983 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4984 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4985 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4986 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4987 | // Check for function proxy. |
| 4988 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4989 | __ j(not_equal, &non_function); |
| 4990 | __ pop(ecx); |
| 4991 | __ push(edi); // put proxy as additional argument under return address |
| 4992 | __ push(ecx); |
| 4993 | __ Set(eax, Immediate(argc_ + 1)); |
| 4994 | __ Set(ebx, Immediate(0)); |
| 4995 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4996 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4997 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4998 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4999 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 5000 | } |
| 5001 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5002 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 5003 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5004 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5005 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 5006 | __ Set(eax, Immediate(argc_)); |
| 5007 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5008 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5009 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5010 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5011 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 5012 | } |
| 5013 | |
| 5014 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5015 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 5016 | // eax : number of arguments |
| 5017 | // ebx : cache cell for call target |
| 5018 | // edi : constructor function |
| 5019 | Label slow, non_function_call; |
| 5020 | |
| 5021 | // Check that function is not a smi. |
| 5022 | __ JumpIfSmi(edi, &non_function_call); |
| 5023 | // Check that function is a JSFunction. |
| 5024 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 5025 | __ j(not_equal, &slow); |
| 5026 | |
| 5027 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5028 | if (FLAG_optimize_constructed_arrays) { |
| 5029 | GenerateRecordCallTarget(masm); |
| 5030 | } else { |
| 5031 | GenerateRecordCallTargetNoArray(masm); |
| 5032 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | // Jump to the function-specific construct stub. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5036 | Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; |
| 5037 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 5038 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 5039 | SharedFunctionInfo::kConstructStubOffset)); |
| 5040 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 5041 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5042 | |
| 5043 | // edi: called object |
| 5044 | // eax: number of arguments |
| 5045 | // ecx: object map |
| 5046 | Label do_call; |
| 5047 | __ bind(&slow); |
| 5048 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 5049 | __ j(not_equal, &non_function_call); |
| 5050 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 5051 | __ jmp(&do_call); |
| 5052 | |
| 5053 | __ bind(&non_function_call); |
| 5054 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 5055 | __ bind(&do_call); |
| 5056 | // Set expected number of arguments to zero (not changing eax). |
| 5057 | __ Set(ebx, Immediate(0)); |
| 5058 | Handle<Code> arguments_adaptor = |
| 5059 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 5060 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 5061 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 5062 | } |
| 5063 | |
| 5064 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 5065 | bool CEntryStub::NeedsImmovableCode() { |
| 5066 | return false; |
| 5067 | } |
| 5068 | |
| 5069 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5070 | bool CEntryStub::IsPregenerated() { |
| 5071 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 5072 | result_size_ == 1; |
| 5073 | } |
| 5074 | |
| 5075 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5076 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5077 | CEntryStub::GenerateAheadOfTime(isolate); |
| 5078 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5079 | // 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] | 5080 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5084 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5085 | if (CpuFeatures::IsSupported(SSE2)) { |
| 5086 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 5087 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 5088 | // which would lead to code stub initialization state being messed up. |
| 5089 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5090 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 5091 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5092 | } |
| 5093 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5094 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5095 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5099 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5100 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5101 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5102 | code->set_is_pregenerated(true); |
| 5103 | } |
| 5104 | |
| 5105 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5106 | static void JumpIfOOM(MacroAssembler* masm, |
| 5107 | Register value, |
| 5108 | Register scratch, |
| 5109 | Label* oom_label) { |
| 5110 | __ mov(scratch, value); |
| 5111 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 5112 | STATIC_ASSERT(kFailureTag == 3); |
| 5113 | __ and_(scratch, 0xf); |
| 5114 | __ cmp(scratch, 0xf); |
| 5115 | __ j(equal, oom_label); |
| 5116 | } |
| 5117 | |
| 5118 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5119 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5120 | Label* throw_normal_exception, |
| 5121 | Label* throw_termination_exception, |
| 5122 | Label* throw_out_of_memory_exception, |
| 5123 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5124 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5125 | // eax: result parameter for PerformGC, if any |
| 5126 | // ebx: pointer to C function (C callee-saved) |
| 5127 | // ebp: frame pointer (restored after C call) |
| 5128 | // esp: stack pointer (restored after C call) |
| 5129 | // edi: number of arguments including receiver (C callee-saved) |
| 5130 | // esi: pointer to the first argument (C callee-saved) |
| 5131 | |
| 5132 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5133 | |
| 5134 | // Check stack alignment. |
| 5135 | if (FLAG_debug_code) { |
| 5136 | __ CheckStackAlignment(); |
| 5137 | } |
| 5138 | |
| 5139 | if (do_gc) { |
| 5140 | // Pass failure code returned from last attempt as first argument to |
| 5141 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5142 | // stack alignment is known to be correct. This function takes one argument |
| 5143 | // which is passed on the stack, and we know that the stack has been |
| 5144 | // prepared to pass at least one argument. |
| 5145 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5146 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5147 | } |
| 5148 | |
| 5149 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5150 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5151 | if (always_allocate_scope) { |
| 5152 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5153 | } |
| 5154 | |
| 5155 | // Call C function. |
| 5156 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5157 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5158 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5159 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5160 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5161 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5162 | |
| 5163 | if (always_allocate_scope) { |
| 5164 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5165 | } |
| 5166 | |
| 5167 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5168 | // call as this may lead to crashes in the IC code later. |
| 5169 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5170 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5171 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5172 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5173 | __ int3(); |
| 5174 | __ bind(&okay); |
| 5175 | } |
| 5176 | |
| 5177 | // Check for failure result. |
| 5178 | Label failure_returned; |
| 5179 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5180 | __ lea(ecx, Operand(eax, 1)); |
| 5181 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5182 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5183 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5184 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5185 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5186 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5187 | |
| 5188 | // Check that there is no pending exception, otherwise we |
| 5189 | // should have returned some failure value. |
| 5190 | if (FLAG_debug_code) { |
| 5191 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5192 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5193 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5194 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5195 | // 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] | 5196 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5197 | __ int3(); |
| 5198 | __ bind(&okay); |
| 5199 | __ pop(edx); |
| 5200 | } |
| 5201 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5202 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5203 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5204 | __ ret(0); |
| 5205 | |
| 5206 | // Handling of failure. |
| 5207 | __ bind(&failure_returned); |
| 5208 | |
| 5209 | Label retry; |
| 5210 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5211 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5212 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5213 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5214 | |
| 5215 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5216 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5217 | |
| 5218 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5219 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5220 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5222 | |
| 5223 | // Special handling of termination exceptions which are uncatchable |
| 5224 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5225 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5226 | __ j(equal, throw_termination_exception); |
| 5227 | |
| 5228 | // Handle normal exception. |
| 5229 | __ jmp(throw_normal_exception); |
| 5230 | |
| 5231 | // Retry. |
| 5232 | __ bind(&retry); |
| 5233 | } |
| 5234 | |
| 5235 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5236 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5237 | // eax: number of arguments including receiver |
| 5238 | // ebx: pointer to C function (C callee-saved) |
| 5239 | // ebp: frame pointer (restored after C call) |
| 5240 | // esp: stack pointer (restored after C call) |
| 5241 | // esi: current context (C callee-saved) |
| 5242 | // edi: JS function of the caller (C callee-saved) |
| 5243 | |
| 5244 | // NOTE: Invocations of builtins may return failure objects instead |
| 5245 | // of a proper result. The builtin entry handles this by performing |
| 5246 | // a garbage collection and retrying the builtin (twice). |
| 5247 | |
| 5248 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5249 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5250 | |
| 5251 | // eax: result parameter for PerformGC, if any (setup below) |
| 5252 | // ebx: pointer to builtin function (C callee-saved) |
| 5253 | // ebp: frame pointer (restored after C call) |
| 5254 | // esp: stack pointer (restored after C call) |
| 5255 | // edi: number of arguments including receiver (C callee-saved) |
| 5256 | // esi: argv pointer (C callee-saved) |
| 5257 | |
| 5258 | Label throw_normal_exception; |
| 5259 | Label throw_termination_exception; |
| 5260 | Label throw_out_of_memory_exception; |
| 5261 | |
| 5262 | // Call into the runtime system. |
| 5263 | GenerateCore(masm, |
| 5264 | &throw_normal_exception, |
| 5265 | &throw_termination_exception, |
| 5266 | &throw_out_of_memory_exception, |
| 5267 | false, |
| 5268 | false); |
| 5269 | |
| 5270 | // Do space-specific GC and retry runtime call. |
| 5271 | GenerateCore(masm, |
| 5272 | &throw_normal_exception, |
| 5273 | &throw_termination_exception, |
| 5274 | &throw_out_of_memory_exception, |
| 5275 | true, |
| 5276 | false); |
| 5277 | |
| 5278 | // Do full GC and retry runtime call one final time. |
| 5279 | Failure* failure = Failure::InternalError(); |
| 5280 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5281 | GenerateCore(masm, |
| 5282 | &throw_normal_exception, |
| 5283 | &throw_termination_exception, |
| 5284 | &throw_out_of_memory_exception, |
| 5285 | true, |
| 5286 | true); |
| 5287 | |
| 5288 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5289 | // Set external caught exception to false. |
| 5290 | Isolate* isolate = masm->isolate(); |
| 5291 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5292 | isolate); |
| 5293 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5294 | |
| 5295 | // Set pending exception and eax to out of memory exception. |
| 5296 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5297 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5298 | Label already_have_failure; |
| 5299 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5300 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5301 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5302 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5303 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5304 | |
| 5305 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5306 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5307 | |
| 5308 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5309 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | |
| 5313 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5314 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5315 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5316 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5317 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5318 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5319 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5320 | |
| 5321 | // Push marker in two places. |
| 5322 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5323 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5324 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5325 | // Save callee-saved registers (C calling conventions). |
| 5326 | __ push(edi); |
| 5327 | __ push(esi); |
| 5328 | __ push(ebx); |
| 5329 | |
| 5330 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5331 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5332 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5333 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5334 | // 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] | 5335 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5336 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5337 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5338 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5339 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5340 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5341 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5342 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5343 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5344 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5345 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5346 | // block that sets the pending exception. |
| 5347 | __ jmp(&invoke); |
| 5348 | __ bind(&handler_entry); |
| 5349 | handler_offset_ = handler_entry.pos(); |
| 5350 | // Caught exception: Store result (exception) in the pending exception |
| 5351 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5352 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5353 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5354 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5355 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5356 | __ jmp(&exit); |
| 5357 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5358 | // Invoke: Link this frame into the handler chain. There's only one |
| 5359 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5360 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5361 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5362 | |
| 5363 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5364 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5365 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5366 | |
| 5367 | // Fake a receiver (NULL). |
| 5368 | __ push(Immediate(0)); // receiver |
| 5369 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5370 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5371 | // pop the faked function when we return. Notice that we cannot store a |
| 5372 | // reference to the trampoline code directly in this stub, because the |
| 5373 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5374 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5375 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5376 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | __ mov(edx, Immediate(construct_entry)); |
| 5378 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5379 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5380 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5381 | __ mov(edx, Immediate(entry)); |
| 5382 | } |
| 5383 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5384 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5385 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5386 | |
| 5387 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5388 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5389 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5390 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5391 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5392 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5393 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5394 | __ j(not_equal, ¬_outermost_js_2); |
| 5395 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5396 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5397 | |
| 5398 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5399 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5400 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5401 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5402 | |
| 5403 | // Restore callee-saved registers (C calling conventions). |
| 5404 | __ pop(ebx); |
| 5405 | __ pop(esi); |
| 5406 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5407 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5408 | |
| 5409 | // Restore frame pointer and return. |
| 5410 | __ pop(ebp); |
| 5411 | __ ret(0); |
| 5412 | } |
| 5413 | |
| 5414 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5415 | // Generate stub code for instanceof. |
| 5416 | // This code can patch a call site inlined cache of the instance of check, |
| 5417 | // which looks like this. |
| 5418 | // |
| 5419 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5420 | // 75 0a jne <some near label> |
| 5421 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5422 | // |
| 5423 | // If call site patching is requested the stack will have the delta from the |
| 5424 | // return address to the cmp instruction just below the return address. This |
| 5425 | // also means that call site patching can only take place with arguments in |
| 5426 | // registers. TOS looks like this when call site patching is requested |
| 5427 | // |
| 5428 | // esp[0] : return address |
| 5429 | // esp[4] : delta from return address to cmp instruction |
| 5430 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5431 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5432 | // Call site inlining and patching implies arguments in registers. |
| 5433 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5434 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5435 | // Fixed register usage throughout the stub. |
| 5436 | Register object = eax; // Object (lhs). |
| 5437 | Register map = ebx; // Map of the object. |
| 5438 | Register function = edx; // Function (rhs). |
| 5439 | Register prototype = edi; // Prototype of the function. |
| 5440 | Register scratch = ecx; |
| 5441 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5442 | // Constants describing the call site code to patch. |
| 5443 | static const int kDeltaToCmpImmediate = 2; |
| 5444 | static const int kDeltaToMov = 8; |
| 5445 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5446 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5447 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5448 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5449 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5450 | ExternalReference roots_array_start = |
| 5451 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5452 | |
| 5453 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5454 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5455 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5456 | // Get the object and function - they are always both needed. |
| 5457 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5458 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5459 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5460 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5461 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5462 | |
| 5463 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5464 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5465 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5466 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5467 | // If there is a call site cache don't look in the global cache, but do the |
| 5468 | // real lookup and update the call site cache. |
| 5469 | if (!HasCallSiteInlineCheck()) { |
| 5470 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5471 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5472 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5473 | __ cmp(function, Operand::StaticArray(scratch, |
| 5474 | times_pointer_size, |
| 5475 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5476 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5477 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5478 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5479 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5480 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5481 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5482 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5483 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5484 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5485 | __ bind(&miss); |
| 5486 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5487 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5488 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5489 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5490 | |
| 5491 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5492 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5493 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5494 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5495 | // Update the global instanceof or call site inlined cache with the current |
| 5496 | // map and function. The cached answer will be set when it is known below. |
| 5497 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5498 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5499 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5500 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5501 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5502 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5503 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5504 | } else { |
| 5505 | // The constants for the code patching are based on no push instructions |
| 5506 | // at the call site. |
| 5507 | ASSERT(HasArgsInRegisters()); |
| 5508 | // Get return address and delta to inlined map check. |
| 5509 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5510 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5511 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5512 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5513 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5514 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5515 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5516 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5517 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5518 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5519 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5520 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5521 | // Loop through the prototype chain of the object looking for the function |
| 5522 | // prototype. |
| 5523 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5524 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5525 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5526 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5527 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5528 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5529 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5530 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5531 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5532 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5533 | __ jmp(&loop); |
| 5534 | |
| 5535 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5536 | if (!HasCallSiteInlineCheck()) { |
| 5537 | __ Set(eax, Immediate(0)); |
| 5538 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5539 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5540 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5541 | } else { |
| 5542 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5543 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5544 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5545 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5546 | if (FLAG_debug_code) { |
| 5547 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5548 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5549 | } |
| 5550 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5551 | if (!ReturnTrueFalseObject()) { |
| 5552 | __ Set(eax, Immediate(0)); |
| 5553 | } |
| 5554 | } |
| 5555 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5556 | |
| 5557 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5558 | if (!HasCallSiteInlineCheck()) { |
| 5559 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5560 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5561 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5562 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5563 | } else { |
| 5564 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5565 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5566 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5567 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5568 | if (FLAG_debug_code) { |
| 5569 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5570 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5571 | } |
| 5572 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5573 | if (!ReturnTrueFalseObject()) { |
| 5574 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5575 | } |
| 5576 | } |
| 5577 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5578 | |
| 5579 | Label object_not_null, object_not_null_or_smi; |
| 5580 | __ bind(¬_js_object); |
| 5581 | // Before null, smi and string value checks, check that the rhs is a function |
| 5582 | // 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] | 5583 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5584 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5585 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5586 | |
| 5587 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5588 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5589 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5590 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5591 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5592 | |
| 5593 | __ bind(&object_not_null); |
| 5594 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5595 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5596 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5597 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5598 | |
| 5599 | __ bind(&object_not_null_or_smi); |
| 5600 | // String values is not instance of anything. |
| 5601 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5602 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5603 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5604 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | |
| 5606 | // Slow-case: Go through the JavaScript implementation. |
| 5607 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5608 | if (!ReturnTrueFalseObject()) { |
| 5609 | // Tail call the builtin which returns 0 or 1. |
| 5610 | if (HasArgsInRegisters()) { |
| 5611 | // Push arguments below return address. |
| 5612 | __ pop(scratch); |
| 5613 | __ push(object); |
| 5614 | __ push(function); |
| 5615 | __ push(scratch); |
| 5616 | } |
| 5617 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5618 | } else { |
| 5619 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5620 | { |
| 5621 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5622 | __ push(object); |
| 5623 | __ push(function); |
| 5624 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5625 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5626 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5627 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5628 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5629 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5630 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5631 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5632 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5633 | __ bind(&done); |
| 5634 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5635 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5639 | Register InstanceofStub::left() { return eax; } |
| 5640 | |
| 5641 | |
| 5642 | Register InstanceofStub::right() { return edx; } |
| 5643 | |
| 5644 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5645 | // ------------------------------------------------------------------------- |
| 5646 | // StringCharCodeAtGenerator |
| 5647 | |
| 5648 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5649 | // If the receiver is a smi trigger the non-string case. |
| 5650 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5651 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5652 | |
| 5653 | // Fetch the instance type of the receiver into result register. |
| 5654 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5655 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5656 | // If the receiver is not a string trigger the non-string case. |
| 5657 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5658 | __ j(not_zero, receiver_not_string_); |
| 5659 | |
| 5660 | // If the index is non-smi trigger the non-smi case. |
| 5661 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5662 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5663 | __ bind(&got_smi_index_); |
| 5664 | |
| 5665 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5666 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5667 | __ j(above_equal, index_out_of_range_); |
| 5668 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5669 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5670 | |
| 5671 | Factory* factory = masm->isolate()->factory(); |
| 5672 | StringCharLoadGenerator::Generate( |
| 5673 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5674 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5675 | __ SmiTag(result_); |
| 5676 | __ bind(&exit_); |
| 5677 | } |
| 5678 | |
| 5679 | |
| 5680 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5681 | MacroAssembler* masm, |
| 5682 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5683 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5684 | |
| 5685 | // Index is not a smi. |
| 5686 | __ bind(&index_not_smi_); |
| 5687 | // 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] | 5688 | __ CheckMap(index_, |
| 5689 | masm->isolate()->factory()->heap_number_map(), |
| 5690 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5691 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5692 | call_helper.BeforeCall(masm); |
| 5693 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5694 | __ push(index_); // Consumed by runtime conversion function. |
| 5695 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5696 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5697 | } else { |
| 5698 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5699 | // NumberToSmi discards numbers that are not exact integers. |
| 5700 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5701 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5702 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5703 | // Save the conversion result before the pop instructions below |
| 5704 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5705 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5706 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5707 | __ pop(object_); |
| 5708 | // Reload the instance type. |
| 5709 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5710 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5711 | call_helper.AfterCall(masm); |
| 5712 | // If index is still not a smi, it must be out of range. |
| 5713 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5714 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5715 | // Otherwise, return to the fast path. |
| 5716 | __ jmp(&got_smi_index_); |
| 5717 | |
| 5718 | // Call runtime. We get here when the receiver is a string and the |
| 5719 | // index is a number, but the code of getting the actual character |
| 5720 | // is too complex (e.g., when the string needs to be flattened). |
| 5721 | __ bind(&call_runtime_); |
| 5722 | call_helper.BeforeCall(masm); |
| 5723 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5724 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5725 | __ push(index_); |
| 5726 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5727 | if (!result_.is(eax)) { |
| 5728 | __ mov(result_, eax); |
| 5729 | } |
| 5730 | call_helper.AfterCall(masm); |
| 5731 | __ jmp(&exit_); |
| 5732 | |
| 5733 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5734 | } |
| 5735 | |
| 5736 | |
| 5737 | // ------------------------------------------------------------------------- |
| 5738 | // StringCharFromCodeGenerator |
| 5739 | |
| 5740 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5741 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5742 | STATIC_ASSERT(kSmiTag == 0); |
| 5743 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5744 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5745 | __ test(code_, |
| 5746 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5747 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5748 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5749 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5750 | Factory* factory = masm->isolate()->factory(); |
| 5751 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5752 | STATIC_ASSERT(kSmiTag == 0); |
| 5753 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5754 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5755 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5756 | __ mov(result_, FieldOperand(result_, |
| 5757 | code_, times_half_pointer_size, |
| 5758 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5759 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5760 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5761 | __ bind(&exit_); |
| 5762 | } |
| 5763 | |
| 5764 | |
| 5765 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5766 | MacroAssembler* masm, |
| 5767 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5768 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5769 | |
| 5770 | __ bind(&slow_case_); |
| 5771 | call_helper.BeforeCall(masm); |
| 5772 | __ push(code_); |
| 5773 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5774 | if (!result_.is(eax)) { |
| 5775 | __ mov(result_, eax); |
| 5776 | } |
| 5777 | call_helper.AfterCall(masm); |
| 5778 | __ jmp(&exit_); |
| 5779 | |
| 5780 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5781 | } |
| 5782 | |
| 5783 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5784 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5785 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5786 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5787 | |
| 5788 | // Load the two arguments. |
| 5789 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5790 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5791 | |
| 5792 | // 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] | 5793 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5794 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5795 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5796 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5797 | |
| 5798 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5799 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5800 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5801 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5802 | } else { |
| 5803 | // Here at least one of the arguments is definitely a string. |
| 5804 | // We convert the one that is not known to be a string. |
| 5805 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5806 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5807 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5808 | &call_builtin); |
| 5809 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5810 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5811 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5812 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5813 | &call_builtin); |
| 5814 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5815 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | // Both arguments are strings. |
| 5819 | // eax: first string |
| 5820 | // edx: second string |
| 5821 | // 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] | 5822 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5823 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5824 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5825 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5826 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5827 | // 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] | 5828 | Counters* counters = masm->isolate()->counters(); |
| 5829 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5830 | __ ret(2 * kPointerSize); |
| 5831 | __ bind(&second_not_zero_length); |
| 5832 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5833 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5834 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5835 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | // First string is empty, result is second string which is in edx. |
| 5837 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5838 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5839 | __ ret(2 * kPointerSize); |
| 5840 | |
| 5841 | // Both strings are non-empty. |
| 5842 | // eax: first string |
| 5843 | // ebx: length of first string as a smi |
| 5844 | // ecx: length of second string as a smi |
| 5845 | // edx: second string |
| 5846 | // Look at the length of the result of adding the two strings. |
| 5847 | Label string_add_flat_result, longer_than_two; |
| 5848 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5849 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5850 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5851 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5852 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5853 | // Use the string table when adding two one character strings, as it |
| 5854 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5855 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5856 | __ j(not_equal, &longer_than_two); |
| 5857 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5858 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5859 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5860 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5861 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5862 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5863 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5865 | // 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] | 5866 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5867 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5868 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5869 | masm, ebx, ecx, eax, edx, edi, |
| 5870 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5871 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5872 | __ ret(2 * kPointerSize); |
| 5873 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5874 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5875 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5876 | // Reload the arguments. |
| 5877 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5878 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5879 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5880 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5881 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5882 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5883 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5884 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5885 | // Pack both characters in ebx. |
| 5886 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5887 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5888 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5889 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5890 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5891 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5892 | |
| 5893 | __ bind(&longer_than_two); |
| 5894 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5895 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5896 | __ j(below, &string_add_flat_result); |
| 5897 | |
| 5898 | // 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] | 5899 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5900 | Label non_ascii, allocated, ascii_data; |
| 5901 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5902 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5903 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5904 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5905 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5906 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5907 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5908 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5909 | __ j(zero, &non_ascii); |
| 5910 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5911 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5912 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | __ bind(&allocated); |
| 5914 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5915 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5917 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5918 | Immediate(String::kEmptyHashField)); |
| 5919 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5920 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5921 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5922 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5923 | __ ret(2 * kPointerSize); |
| 5924 | __ bind(&non_ascii); |
| 5925 | // 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] | 5926 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5927 | // ecx: first instance type AND second instance type. |
| 5928 | // edi: second instance type. |
| 5929 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5930 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5931 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5932 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5933 | __ xor_(edi, ecx); |
| 5934 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5935 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5936 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5937 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5938 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5939 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5940 | __ jmp(&allocated); |
| 5941 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5942 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5943 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5944 | // Handle creating a flat result from either external or sequential strings. |
| 5945 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5946 | // eax: first string |
| 5947 | // ebx: length of resulting flat string as a smi |
| 5948 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5949 | Label first_prepared, second_prepared; |
| 5950 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5951 | __ bind(&string_add_flat_result); |
| 5952 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5953 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5954 | // ecx: instance type of first string |
| 5955 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5956 | __ test_b(ecx, kStringRepresentationMask); |
| 5957 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5958 | // Rule out short external string and load string resource. |
| 5959 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5960 | __ test_b(ecx, kShortExternalStringMask); |
| 5961 | __ j(not_zero, &call_runtime); |
| 5962 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5963 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5964 | __ jmp(&first_prepared, Label::kNear); |
| 5965 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5966 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5967 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5968 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5969 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5970 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5971 | // Check whether both strings have same encoding. |
| 5972 | // edi: instance type of second string |
| 5973 | __ xor_(ecx, edi); |
| 5974 | __ test_b(ecx, kStringEncodingMask); |
| 5975 | __ j(not_zero, &call_runtime); |
| 5976 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5977 | __ test_b(edi, kStringRepresentationMask); |
| 5978 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5979 | // Rule out short external string and load string resource. |
| 5980 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5981 | __ test_b(edi, kShortExternalStringMask); |
| 5982 | __ j(not_zero, &call_runtime); |
| 5983 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5984 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5985 | __ jmp(&second_prepared, Label::kNear); |
| 5986 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5987 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5988 | __ bind(&second_prepared); |
| 5989 | |
| 5990 | // Push the addresses of both strings' first characters onto the stack. |
| 5991 | __ push(edx); |
| 5992 | __ push(eax); |
| 5993 | |
| 5994 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5995 | // edi: instance type of second string |
| 5996 | // First string and second string have the same encoding. |
| 5997 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5998 | __ test_b(edi, kStringEncodingMask); |
| 5999 | __ j(zero, &non_ascii_string_add_flat_result); |
| 6000 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6001 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6002 | // ebx: length of resulting flat string as a smi |
| 6003 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6004 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6005 | // eax: result string |
| 6006 | __ mov(ecx, eax); |
| 6007 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6008 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6009 | // Load first argument's length and first character location. Account for |
| 6010 | // values currently on the stack when fetching arguments from it. |
| 6011 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6012 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6013 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6014 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6015 | // eax: result string |
| 6016 | // ecx: first character of result |
| 6017 | // edx: first char of first argument |
| 6018 | // edi: length of first argument |
| 6019 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6020 | // Load second argument's length and first character location. Account for |
| 6021 | // values currently on the stack when fetching arguments from it. |
| 6022 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6023 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6024 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6025 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6026 | // eax: result string |
| 6027 | // ecx: next character of result |
| 6028 | // edx: first char of second argument |
| 6029 | // edi: length of second argument |
| 6030 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6031 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6032 | __ ret(2 * kPointerSize); |
| 6033 | |
| 6034 | // Handle creating a flat two byte result. |
| 6035 | // eax: first string - known to be two byte |
| 6036 | // ebx: length of resulting flat string as a smi |
| 6037 | // edx: second string |
| 6038 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6039 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6040 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6041 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6042 | // eax: result string |
| 6043 | __ mov(ecx, eax); |
| 6044 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6045 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6046 | // Load second argument's length and first character location. Account for |
| 6047 | // values currently on the stack when fetching arguments from it. |
| 6048 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6049 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6050 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6051 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6052 | // eax: result string |
| 6053 | // ecx: first character of result |
| 6054 | // edx: first char of first argument |
| 6055 | // edi: length of first argument |
| 6056 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6057 | // Load second argument's length and first character location. Account for |
| 6058 | // values currently on the stack when fetching arguments from it. |
| 6059 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6060 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 6061 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6062 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | // eax: result string |
| 6064 | // ecx: next character of result |
| 6065 | // edx: first char of second argument |
| 6066 | // edi: length of second argument |
| 6067 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6068 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6069 | __ ret(2 * kPointerSize); |
| 6070 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6071 | // Recover stack pointer before jumping to runtime. |
| 6072 | __ bind(&call_runtime_drop_two); |
| 6073 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6074 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6075 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6076 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6077 | |
| 6078 | if (call_builtin.is_linked()) { |
| 6079 | __ bind(&call_builtin); |
| 6080 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 6081 | } |
| 6082 | } |
| 6083 | |
| 6084 | |
| 6085 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6086 | int stack_offset, |
| 6087 | Register arg, |
| 6088 | Register scratch1, |
| 6089 | Register scratch2, |
| 6090 | Register scratch3, |
| 6091 | Label* slow) { |
| 6092 | // First check if the argument is already a string. |
| 6093 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6094 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6095 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6096 | __ j(below, &done); |
| 6097 | |
| 6098 | // Check the number to string cache. |
| 6099 | Label not_cached; |
| 6100 | __ bind(¬_string); |
| 6101 | // Puts the cached result into scratch1. |
| 6102 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6103 | arg, |
| 6104 | scratch1, |
| 6105 | scratch2, |
| 6106 | scratch3, |
| 6107 | false, |
| 6108 | ¬_cached); |
| 6109 | __ mov(arg, scratch1); |
| 6110 | __ mov(Operand(esp, stack_offset), arg); |
| 6111 | __ jmp(&done); |
| 6112 | |
| 6113 | // Check if the argument is a safe string wrapper. |
| 6114 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6115 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6116 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6117 | __ j(not_equal, slow); |
| 6118 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6119 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6120 | __ j(zero, slow); |
| 6121 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6122 | __ mov(Operand(esp, stack_offset), arg); |
| 6123 | |
| 6124 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | |
| 6128 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6129 | Register dest, |
| 6130 | Register src, |
| 6131 | Register count, |
| 6132 | Register scratch, |
| 6133 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6134 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6135 | __ bind(&loop); |
| 6136 | // This loop just copies one character at a time, as it is only used for very |
| 6137 | // short strings. |
| 6138 | if (ascii) { |
| 6139 | __ mov_b(scratch, Operand(src, 0)); |
| 6140 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6141 | __ add(src, Immediate(1)); |
| 6142 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6143 | } else { |
| 6144 | __ mov_w(scratch, Operand(src, 0)); |
| 6145 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6146 | __ add(src, Immediate(2)); |
| 6147 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6148 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6149 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6150 | __ j(not_zero, &loop); |
| 6151 | } |
| 6152 | |
| 6153 | |
| 6154 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6155 | Register dest, |
| 6156 | Register src, |
| 6157 | Register count, |
| 6158 | Register scratch, |
| 6159 | bool ascii) { |
| 6160 | // Copy characters using rep movs of doublewords. |
| 6161 | // The destination is aligned on a 4 byte boundary because we are |
| 6162 | // copying to the beginning of a newly allocated string. |
| 6163 | ASSERT(dest.is(edi)); // rep movs destination |
| 6164 | ASSERT(src.is(esi)); // rep movs source |
| 6165 | ASSERT(count.is(ecx)); // rep movs count |
| 6166 | ASSERT(!scratch.is(dest)); |
| 6167 | ASSERT(!scratch.is(src)); |
| 6168 | ASSERT(!scratch.is(count)); |
| 6169 | |
| 6170 | // Nothing to do for zero characters. |
| 6171 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6172 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6173 | __ j(zero, &done); |
| 6174 | |
| 6175 | // Make count the number of bytes to copy. |
| 6176 | if (!ascii) { |
| 6177 | __ shl(count, 1); |
| 6178 | } |
| 6179 | |
| 6180 | // 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] | 6181 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6182 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6183 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6184 | |
| 6185 | // Copy from edi to esi using rep movs instruction. |
| 6186 | __ mov(scratch, count); |
| 6187 | __ sar(count, 2); // Number of doublewords to copy. |
| 6188 | __ cld(); |
| 6189 | __ rep_movs(); |
| 6190 | |
| 6191 | // Find number of bytes left. |
| 6192 | __ mov(count, scratch); |
| 6193 | __ and_(count, 3); |
| 6194 | |
| 6195 | // Check if there are more bytes to copy. |
| 6196 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6197 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6198 | __ j(zero, &done); |
| 6199 | |
| 6200 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6201 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6202 | __ bind(&loop); |
| 6203 | __ mov_b(scratch, Operand(src, 0)); |
| 6204 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6205 | __ add(src, Immediate(1)); |
| 6206 | __ add(dest, Immediate(1)); |
| 6207 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6208 | __ j(not_zero, &loop); |
| 6209 | |
| 6210 | __ bind(&done); |
| 6211 | } |
| 6212 | |
| 6213 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6214 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6215 | Register c1, |
| 6216 | Register c2, |
| 6217 | Register scratch1, |
| 6218 | Register scratch2, |
| 6219 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6220 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6221 | Label* not_found) { |
| 6222 | // Register scratch3 is the general scratch register in this function. |
| 6223 | Register scratch = scratch3; |
| 6224 | |
| 6225 | // 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] | 6226 | // 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] | 6227 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6228 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6229 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6230 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6231 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6232 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6233 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6234 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6235 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6236 | |
| 6237 | __ bind(¬_array_index); |
| 6238 | // Calculate the two character string hash. |
| 6239 | Register hash = scratch1; |
| 6240 | GenerateHashInit(masm, hash, c1, scratch); |
| 6241 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6242 | GenerateHashGetHash(masm, hash, scratch); |
| 6243 | |
| 6244 | // Collect the two characters in a register. |
| 6245 | Register chars = c1; |
| 6246 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6247 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6248 | |
| 6249 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6250 | // hash: hash of two character string. |
| 6251 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6252 | // Load the string table. |
| 6253 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6254 | ExternalReference roots_array_start = |
| 6255 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6256 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 6257 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6258 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6259 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6260 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6261 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6262 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6263 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6264 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6265 | |
| 6266 | // Registers |
| 6267 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6268 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6269 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6270 | // mask: capacity mask |
| 6271 | // scratch: - |
| 6272 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6273 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6275 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6276 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6277 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6278 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6279 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6280 | __ mov(scratch, hash); |
| 6281 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6282 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6283 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6284 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6285 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6286 | // Load the entry from the string table. |
| 6287 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6288 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6289 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6290 | scratch, |
| 6291 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6292 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6293 | |
| 6294 | // 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] | 6295 | Factory* factory = masm->isolate()->factory(); |
| 6296 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6297 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6298 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6299 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | |
| 6301 | // If length is not 2 the string is not a candidate. |
| 6302 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6303 | Immediate(Smi::FromInt(2))); |
| 6304 | __ j(not_equal, &next_probe[i]); |
| 6305 | |
| 6306 | // As we are out of registers save the mask on the stack and use that |
| 6307 | // register as a temporary. |
| 6308 | __ push(mask); |
| 6309 | Register temp = mask; |
| 6310 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6311 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6312 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6313 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6314 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6315 | temp, temp, &next_probe_pop_mask[i]); |
| 6316 | |
| 6317 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6318 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6319 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6320 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6321 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6322 | __ bind(&next_probe_pop_mask[i]); |
| 6323 | __ pop(mask); |
| 6324 | __ bind(&next_probe[i]); |
| 6325 | } |
| 6326 | |
| 6327 | // No matching 2 character string found by probing. |
| 6328 | __ jmp(not_found); |
| 6329 | |
| 6330 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6331 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6332 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6333 | __ pop(mask); // Pop saved mask from the stack. |
| 6334 | if (!result.is(eax)) { |
| 6335 | __ mov(eax, result); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | |
| 6340 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6341 | Register hash, |
| 6342 | Register character, |
| 6343 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6344 | // hash = (seed + character) + ((seed + character) << 10); |
| 6345 | if (Serializer::enabled()) { |
| 6346 | ExternalReference roots_array_start = |
| 6347 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6348 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6349 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6350 | times_pointer_size, |
| 6351 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6352 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6353 | __ add(scratch, character); |
| 6354 | __ mov(hash, scratch); |
| 6355 | __ shl(scratch, 10); |
| 6356 | __ add(hash, scratch); |
| 6357 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6358 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6359 | __ lea(scratch, Operand(character, seed)); |
| 6360 | __ shl(scratch, 10); |
| 6361 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6362 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6363 | // hash ^= hash >> 6; |
| 6364 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6365 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6366 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | |
| 6370 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6371 | Register hash, |
| 6372 | Register character, |
| 6373 | Register scratch) { |
| 6374 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6375 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6376 | // hash += hash << 10; |
| 6377 | __ mov(scratch, hash); |
| 6378 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6379 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6380 | // hash ^= hash >> 6; |
| 6381 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6382 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6383 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6388 | Register hash, |
| 6389 | Register scratch) { |
| 6390 | // hash += hash << 3; |
| 6391 | __ mov(scratch, hash); |
| 6392 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6393 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6394 | // hash ^= hash >> 11; |
| 6395 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6396 | __ shr(scratch, 11); |
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 | // hash += hash << 15; |
| 6399 | __ mov(scratch, hash); |
| 6400 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6401 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6402 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6403 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6404 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6405 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6406 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6407 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6408 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6409 | __ bind(&hash_not_zero); |
| 6410 | } |
| 6411 | |
| 6412 | |
| 6413 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6414 | Label runtime; |
| 6415 | |
| 6416 | // Stack frame on entry. |
| 6417 | // esp[0]: return address |
| 6418 | // esp[4]: to |
| 6419 | // esp[8]: from |
| 6420 | // esp[12]: string |
| 6421 | |
| 6422 | // Make sure first argument is a string. |
| 6423 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6424 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6425 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6426 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6427 | __ j(NegateCondition(is_string), &runtime); |
| 6428 | |
| 6429 | // eax: string |
| 6430 | // ebx: instance type |
| 6431 | |
| 6432 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6433 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6434 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6435 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6436 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6437 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6438 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6439 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6440 | // Shorter than original string's length: an actual substring. |
| 6441 | __ j(below, ¬_original_string, Label::kNear); |
| 6442 | // Longer than original string's length or negative: unsafe arguments. |
| 6443 | __ j(above, &runtime); |
| 6444 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6445 | Counters* counters = masm->isolate()->counters(); |
| 6446 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6447 | __ ret(3 * kPointerSize); |
| 6448 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6449 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6450 | Label single_char; |
| 6451 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6452 | __ j(equal, &single_char); |
| 6453 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6454 | // eax: string |
| 6455 | // ebx: instance type |
| 6456 | // ecx: sub string length (smi) |
| 6457 | // edx: from index (smi) |
| 6458 | // Deal with different string types: update the index if necessary |
| 6459 | // and put the underlying string into edi. |
| 6460 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6461 | // If the string is not indirect, it can only be sequential or external. |
| 6462 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6463 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6464 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6465 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6466 | |
| 6467 | Factory* factory = masm->isolate()->factory(); |
| 6468 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6469 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6470 | // Cons string. Check whether it is flat, then fetch first part. |
| 6471 | // Flat cons strings have an empty second part. |
| 6472 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6473 | factory->empty_string()); |
| 6474 | __ j(not_equal, &runtime); |
| 6475 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6476 | // Update instance type. |
| 6477 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6478 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6479 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6480 | |
| 6481 | __ bind(&sliced_string); |
| 6482 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6483 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6484 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6485 | // Update instance type. |
| 6486 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6487 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6488 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6489 | |
| 6490 | __ bind(&seq_or_external_string); |
| 6491 | // Sequential or external string. Just move string to the expected register. |
| 6492 | __ mov(edi, eax); |
| 6493 | |
| 6494 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6495 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6496 | if (FLAG_string_slices) { |
| 6497 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6498 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6499 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6500 | // edx: adjusted start index (smi) |
| 6501 | // ecx: length (smi) |
| 6502 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6503 | // Short slice. Copy instead of slicing. |
| 6504 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6505 | // Allocate new sliced string. At this point we do not reload the instance |
| 6506 | // type including the string encoding because we simply rely on the info |
| 6507 | // provided by the original string. It does not matter if the original |
| 6508 | // string's encoding is wrong because we always have to recheck encoding of |
| 6509 | // the newly created string's parent anyways due to externalized strings. |
| 6510 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6511 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6512 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6513 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6514 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6515 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6516 | __ jmp(&set_slice_header, Label::kNear); |
| 6517 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6518 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6519 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6520 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6521 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6522 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6523 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6524 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6525 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6526 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6527 | |
| 6528 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6531 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6532 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6533 | // edx: adjusted start index (smi) |
| 6534 | // ecx: length (smi) |
| 6535 | // The subject string can only be external or sequential string of either |
| 6536 | // encoding at this point. |
| 6537 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6538 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6539 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6540 | __ test_b(ebx, kExternalStringTag); |
| 6541 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6542 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6543 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6544 | // Rule out short external strings. |
| 6545 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6546 | __ test_b(ebx, kShortExternalStringMask); |
| 6547 | __ j(not_zero, &runtime); |
| 6548 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6549 | // 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] | 6550 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6551 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6552 | |
| 6553 | __ bind(&sequential_string); |
| 6554 | // Stash away (adjusted) index and (underlying) string. |
| 6555 | __ push(edx); |
| 6556 | __ push(edi); |
| 6557 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6558 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6559 | __ test_b(ebx, kStringEncodingMask); |
| 6560 | __ j(zero, &two_byte_sequential); |
| 6561 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6562 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6563 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6564 | |
| 6565 | // eax: result string |
| 6566 | // ecx: result string length |
| 6567 | __ mov(edx, esi); // esi used by following code. |
| 6568 | // Locate first character of result. |
| 6569 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6570 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6571 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6572 | __ pop(esi); |
| 6573 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6574 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6575 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6576 | |
| 6577 | // eax: result string |
| 6578 | // ecx: result length |
| 6579 | // edx: original value of esi |
| 6580 | // edi: first character of result |
| 6581 | // esi: character of sub string start |
| 6582 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6583 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6584 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6585 | __ ret(3 * kPointerSize); |
| 6586 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6587 | __ bind(&two_byte_sequential); |
| 6588 | // Sequential two-byte string. Allocate the result. |
| 6589 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6590 | |
| 6591 | // eax: result string |
| 6592 | // ecx: result string length |
| 6593 | __ mov(edx, esi); // esi used by following code. |
| 6594 | // Locate first character of result. |
| 6595 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6596 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6597 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6598 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6599 | __ pop(esi); |
| 6600 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6601 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6602 | // byte character. |
| 6603 | STATIC_ASSERT(kSmiTag == 0); |
| 6604 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6605 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6606 | |
| 6607 | // eax: result string |
| 6608 | // ecx: result length |
| 6609 | // edx: original value of esi |
| 6610 | // edi: first character of result |
| 6611 | // esi: character of sub string start |
| 6612 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6613 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6614 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6615 | __ ret(3 * kPointerSize); |
| 6616 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6617 | // Drop pushed values on the stack before tail call. |
| 6618 | __ bind(&runtime_drop_two); |
| 6619 | __ Drop(2); |
| 6620 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6621 | // Just jump to runtime to create the sub string. |
| 6622 | __ bind(&runtime); |
| 6623 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6624 | |
| 6625 | __ bind(&single_char); |
| 6626 | // eax: string |
| 6627 | // ebx: instance type |
| 6628 | // ecx: sub string length (smi) |
| 6629 | // edx: from index (smi) |
| 6630 | StringCharAtGenerator generator( |
| 6631 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6632 | generator.GenerateFast(masm); |
| 6633 | __ ret(3 * kPointerSize); |
| 6634 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6635 | } |
| 6636 | |
| 6637 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6638 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6639 | Register left, |
| 6640 | Register right, |
| 6641 | Register scratch1, |
| 6642 | Register scratch2) { |
| 6643 | Register length = scratch1; |
| 6644 | |
| 6645 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6646 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6647 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6648 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6649 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6650 | __ bind(&strings_not_equal); |
| 6651 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6652 | __ ret(0); |
| 6653 | |
| 6654 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6655 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6656 | __ bind(&check_zero_length); |
| 6657 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6658 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6659 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6660 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6661 | __ ret(0); |
| 6662 | |
| 6663 | // Compare characters. |
| 6664 | __ bind(&compare_chars); |
| 6665 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6666 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6667 | |
| 6668 | // Characters are equal. |
| 6669 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6670 | __ ret(0); |
| 6671 | } |
| 6672 | |
| 6673 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6674 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6675 | Register left, |
| 6676 | Register right, |
| 6677 | Register scratch1, |
| 6678 | Register scratch2, |
| 6679 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6680 | Counters* counters = masm->isolate()->counters(); |
| 6681 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6682 | |
| 6683 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6684 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6685 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6686 | __ mov(scratch3, scratch1); |
| 6687 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6688 | |
| 6689 | Register length_delta = scratch3; |
| 6690 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6691 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6692 | // 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] | 6693 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6694 | __ bind(&left_shorter); |
| 6695 | |
| 6696 | Register min_length = scratch1; |
| 6697 | |
| 6698 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6699 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6700 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6701 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6702 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6703 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6704 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6705 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6706 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6707 | |
| 6708 | // Compare lengths - strings up to min-length are equal. |
| 6709 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6710 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6711 | Label length_not_equal; |
| 6712 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6713 | |
| 6714 | // Result is EQUAL. |
| 6715 | STATIC_ASSERT(EQUAL == 0); |
| 6716 | STATIC_ASSERT(kSmiTag == 0); |
| 6717 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6718 | __ ret(0); |
| 6719 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6720 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6721 | Label result_less; |
| 6722 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6723 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6724 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6725 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6726 | __ j(above, &result_greater, Label::kNear); |
| 6727 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6728 | |
| 6729 | // Result is LESS. |
| 6730 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6731 | __ ret(0); |
| 6732 | |
| 6733 | // Result is GREATER. |
| 6734 | __ bind(&result_greater); |
| 6735 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6736 | __ ret(0); |
| 6737 | } |
| 6738 | |
| 6739 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6740 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6741 | MacroAssembler* masm, |
| 6742 | Register left, |
| 6743 | Register right, |
| 6744 | Register length, |
| 6745 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6746 | Label* chars_not_equal, |
| 6747 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6748 | // Change index to run from -length to -1 by adding length to string |
| 6749 | // start. This means that loop ends when index reaches zero, which |
| 6750 | // doesn't need an additional compare. |
| 6751 | __ SmiUntag(length); |
| 6752 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6753 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6754 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6755 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6756 | __ neg(length); |
| 6757 | Register index = length; // index = -length; |
| 6758 | |
| 6759 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6760 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6761 | __ bind(&loop); |
| 6762 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6763 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6764 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6765 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6766 | __ j(not_zero, &loop); |
| 6767 | } |
| 6768 | |
| 6769 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6770 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6771 | Label runtime; |
| 6772 | |
| 6773 | // Stack frame on entry. |
| 6774 | // esp[0]: return address |
| 6775 | // esp[4]: right string |
| 6776 | // esp[8]: left string |
| 6777 | |
| 6778 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6779 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6780 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6781 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6782 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6783 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6784 | STATIC_ASSERT(EQUAL == 0); |
| 6785 | STATIC_ASSERT(kSmiTag == 0); |
| 6786 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6787 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6788 | __ ret(2 * kPointerSize); |
| 6789 | |
| 6790 | __ bind(¬_same); |
| 6791 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6792 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6793 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6794 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6795 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6796 | // Drop arguments from the stack. |
| 6797 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6798 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6799 | __ push(ecx); |
| 6800 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6801 | |
| 6802 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6803 | // tagged as a small integer. |
| 6804 | __ bind(&runtime); |
| 6805 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6806 | } |
| 6807 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6808 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6809 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6810 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6811 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6812 | __ mov(ecx, edx); |
| 6813 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6814 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6815 | |
| 6816 | if (GetCondition() == equal) { |
| 6817 | // 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] | 6818 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6819 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6820 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6821 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6822 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6823 | // Correct sign of result in case of overflow. |
| 6824 | __ not_(edx); |
| 6825 | __ bind(&done); |
| 6826 | __ mov(eax, edx); |
| 6827 | } |
| 6828 | __ ret(0); |
| 6829 | |
| 6830 | __ bind(&miss); |
| 6831 | GenerateMiss(masm); |
| 6832 | } |
| 6833 | |
| 6834 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6835 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6836 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6837 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6838 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6839 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6840 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6841 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6842 | if (left_ == CompareIC::SMI) { |
| 6843 | __ JumpIfNotSmi(edx, &miss); |
| 6844 | } |
| 6845 | if (right_ == CompareIC::SMI) { |
| 6846 | __ JumpIfNotSmi(eax, &miss); |
| 6847 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6848 | |
| 6849 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6850 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6851 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6852 | CpuFeatureScope scope1(masm, SSE2); |
| 6853 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6854 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6855 | // Load left and right operand. |
| 6856 | Label done, left, left_smi, right_smi; |
| 6857 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6858 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6859 | masm->isolate()->factory()->heap_number_map()); |
| 6860 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6861 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6862 | __ jmp(&left, Label::kNear); |
| 6863 | __ bind(&right_smi); |
| 6864 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6865 | __ SmiUntag(ecx); |
| 6866 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6867 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6868 | __ bind(&left); |
| 6869 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6870 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6871 | masm->isolate()->factory()->heap_number_map()); |
| 6872 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6873 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6874 | __ jmp(&done); |
| 6875 | __ bind(&left_smi); |
| 6876 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6877 | __ SmiUntag(ecx); |
| 6878 | __ cvtsi2sd(xmm0, ecx); |
| 6879 | |
| 6880 | __ bind(&done); |
| 6881 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6882 | __ ucomisd(xmm0, xmm1); |
| 6883 | |
| 6884 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6885 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6886 | |
| 6887 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6888 | // Performing mov, because xor would destroy the flag register. |
| 6889 | __ mov(eax, 0); // equal |
| 6890 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6891 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6892 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6893 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6894 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6895 | } else { |
| 6896 | __ mov(ecx, edx); |
| 6897 | __ and_(ecx, eax); |
| 6898 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6899 | |
| 6900 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6901 | masm->isolate()->factory()->heap_number_map()); |
| 6902 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6903 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6904 | masm->isolate()->factory()->heap_number_map()); |
| 6905 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6906 | } |
| 6907 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6908 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6909 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6910 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6911 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6912 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6913 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6914 | __ bind(&maybe_undefined1); |
| 6915 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6916 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6917 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6918 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6919 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6920 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6921 | __ jmp(&unordered); |
| 6922 | } |
| 6923 | |
| 6924 | __ bind(&maybe_undefined2); |
| 6925 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6926 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6927 | __ j(equal, &unordered); |
| 6928 | } |
| 6929 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6930 | __ bind(&miss); |
| 6931 | GenerateMiss(masm); |
| 6932 | } |
| 6933 | |
| 6934 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6935 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6936 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6937 | ASSERT(GetCondition() == equal); |
| 6938 | |
| 6939 | // Registers containing left and right operands respectively. |
| 6940 | Register left = edx; |
| 6941 | Register right = eax; |
| 6942 | Register tmp1 = ecx; |
| 6943 | Register tmp2 = ebx; |
| 6944 | |
| 6945 | // Check that both operands are heap objects. |
| 6946 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6947 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6948 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6949 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6950 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6951 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6952 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6953 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6954 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6955 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6956 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6957 | STATIC_ASSERT(kInternalizedTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6958 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6959 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6960 | __ j(zero, &miss, Label::kNear); |
| 6961 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6962 | // Internalized strings are compared by identity. |
| 6963 | Label done; |
| 6964 | __ cmp(left, right); |
| 6965 | // Make sure eax is non-zero. At this point input operands are |
| 6966 | // guaranteed to be non-zero. |
| 6967 | ASSERT(right.is(eax)); |
| 6968 | __ j(not_equal, &done, Label::kNear); |
| 6969 | STATIC_ASSERT(EQUAL == 0); |
| 6970 | STATIC_ASSERT(kSmiTag == 0); |
| 6971 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6972 | __ bind(&done); |
| 6973 | __ ret(0); |
| 6974 | |
| 6975 | __ bind(&miss); |
| 6976 | GenerateMiss(masm); |
| 6977 | } |
| 6978 | |
| 6979 | |
| 6980 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6981 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6982 | ASSERT(GetCondition() == equal); |
| 6983 | |
| 6984 | // Registers containing left and right operands respectively. |
| 6985 | Register left = edx; |
| 6986 | Register right = eax; |
| 6987 | Register tmp1 = ecx; |
| 6988 | Register tmp2 = ebx; |
| 6989 | |
| 6990 | // Check that both operands are heap objects. |
| 6991 | Label miss; |
| 6992 | __ mov(tmp1, left); |
| 6993 | STATIC_ASSERT(kSmiTag == 0); |
| 6994 | __ and_(tmp1, right); |
| 6995 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6996 | |
| 6997 | // Check that both operands are unique names. This leaves the instance |
| 6998 | // types loaded in tmp1 and tmp2. |
| 6999 | STATIC_ASSERT(kInternalizedTag != 0); |
| 7000 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 7001 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 7002 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7003 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7004 | |
| 7005 | Label succeed1; |
| 7006 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
| 7007 | __ j(not_zero, &succeed1); |
| 7008 | __ cmpb(tmp1, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7009 | __ j(not_equal, &miss); |
| 7010 | __ bind(&succeed1); |
| 7011 | |
| 7012 | Label succeed2; |
| 7013 | __ test(tmp2, Immediate(kIsInternalizedMask)); |
| 7014 | __ j(not_zero, &succeed2); |
| 7015 | __ cmpb(tmp2, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7016 | __ j(not_equal, &miss); |
| 7017 | __ bind(&succeed2); |
| 7018 | |
| 7019 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7020 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7021 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7022 | // Make sure eax is non-zero. At this point input operands are |
| 7023 | // guaranteed to be non-zero. |
| 7024 | ASSERT(right.is(eax)); |
| 7025 | __ j(not_equal, &done, Label::kNear); |
| 7026 | STATIC_ASSERT(EQUAL == 0); |
| 7027 | STATIC_ASSERT(kSmiTag == 0); |
| 7028 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7029 | __ bind(&done); |
| 7030 | __ ret(0); |
| 7031 | |
| 7032 | __ bind(&miss); |
| 7033 | GenerateMiss(masm); |
| 7034 | } |
| 7035 | |
| 7036 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7037 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7038 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7039 | Label miss; |
| 7040 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7041 | bool equality = Token::IsEqualityOp(op_); |
| 7042 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7043 | // Registers containing left and right operands respectively. |
| 7044 | Register left = edx; |
| 7045 | Register right = eax; |
| 7046 | Register tmp1 = ecx; |
| 7047 | Register tmp2 = ebx; |
| 7048 | Register tmp3 = edi; |
| 7049 | |
| 7050 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7051 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7052 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7053 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7054 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7055 | |
| 7056 | // Check that both operands are strings. This leaves the instance |
| 7057 | // types loaded in tmp1 and tmp2. |
| 7058 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 7059 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 7060 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7061 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7062 | __ mov(tmp3, tmp1); |
| 7063 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7064 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7065 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 7066 | __ j(not_zero, &miss); |
| 7067 | |
| 7068 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7069 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7070 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7071 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7072 | STATIC_ASSERT(EQUAL == 0); |
| 7073 | STATIC_ASSERT(kSmiTag == 0); |
| 7074 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7075 | __ ret(0); |
| 7076 | |
| 7077 | // Handle not identical strings. |
| 7078 | __ bind(¬_same); |
| 7079 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7080 | // 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] | 7081 | // because we already know they are not identical. But in the case of |
| 7082 | // non-equality compare, we still need to determine the order. |
| 7083 | if (equality) { |
| 7084 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7085 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7086 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7087 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7088 | __ j(zero, &do_compare, Label::kNear); |
| 7089 | // Make sure eax is non-zero. At this point input operands are |
| 7090 | // guaranteed to be non-zero. |
| 7091 | ASSERT(right.is(eax)); |
| 7092 | __ ret(0); |
| 7093 | __ bind(&do_compare); |
| 7094 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7095 | |
| 7096 | // Check that both strings are sequential ASCII. |
| 7097 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7098 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 7099 | |
| 7100 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7101 | if (equality) { |
| 7102 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 7103 | masm, left, right, tmp1, tmp2); |
| 7104 | } else { |
| 7105 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 7106 | masm, left, right, tmp1, tmp2, tmp3); |
| 7107 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7108 | |
| 7109 | // Handle more complex cases in runtime. |
| 7110 | __ bind(&runtime); |
| 7111 | __ pop(tmp1); // Return address. |
| 7112 | __ push(left); |
| 7113 | __ push(right); |
| 7114 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7115 | if (equality) { |
| 7116 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 7117 | } else { |
| 7118 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 7119 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7120 | |
| 7121 | __ bind(&miss); |
| 7122 | GenerateMiss(masm); |
| 7123 | } |
| 7124 | |
| 7125 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7126 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7127 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7128 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7129 | __ mov(ecx, edx); |
| 7130 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7131 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7132 | |
| 7133 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7134 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7135 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7136 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7137 | |
| 7138 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7139 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7140 | __ ret(0); |
| 7141 | |
| 7142 | __ bind(&miss); |
| 7143 | GenerateMiss(masm); |
| 7144 | } |
| 7145 | |
| 7146 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7147 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7148 | Label miss; |
| 7149 | __ mov(ecx, edx); |
| 7150 | __ and_(ecx, eax); |
| 7151 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7152 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7153 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7154 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7155 | __ cmp(ecx, known_map_); |
| 7156 | __ j(not_equal, &miss, Label::kNear); |
| 7157 | __ cmp(ebx, known_map_); |
| 7158 | __ j(not_equal, &miss, Label::kNear); |
| 7159 | |
| 7160 | __ sub(eax, edx); |
| 7161 | __ ret(0); |
| 7162 | |
| 7163 | __ bind(&miss); |
| 7164 | GenerateMiss(masm); |
| 7165 | } |
| 7166 | |
| 7167 | |
| 7168 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7169 | { |
| 7170 | // Call the runtime system in a fresh internal frame. |
| 7171 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7172 | masm->isolate()); |
| 7173 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7174 | __ push(edx); // Preserve edx and eax. |
| 7175 | __ push(eax); |
| 7176 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7177 | __ push(eax); |
| 7178 | __ push(Immediate(Smi::FromInt(op_))); |
| 7179 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7180 | // Compute the entry point of the rewritten stub. |
| 7181 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7182 | __ pop(eax); |
| 7183 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7184 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7185 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7186 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7187 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7191 | // Helper function used to check that the dictionary doesn't contain |
| 7192 | // the property. This function may return false negatives, so miss_label |
| 7193 | // must always call a backup property check that is complete. |
| 7194 | // This function is safe to call if the receiver has fast properties. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7195 | // Name must be a unique name and receiver must be a heap object. |
| 7196 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7197 | Label* miss, |
| 7198 | Label* done, |
| 7199 | Register properties, |
| 7200 | Handle<Name> name, |
| 7201 | Register r0) { |
| 7202 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7203 | |
| 7204 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7205 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7206 | // undefined value), it guarantees the hash table doesn't contain the |
| 7207 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7208 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7209 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7210 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7211 | Register index = r0; |
| 7212 | // Capacity is smi 2^n. |
| 7213 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7214 | __ dec(index); |
| 7215 | __ and_(index, |
| 7216 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7217 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7218 | |
| 7219 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7220 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7221 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7222 | Register entity_name = r0; |
| 7223 | // Having undefined at this place means the name is not contained. |
| 7224 | ASSERT_EQ(kSmiTagSize, 1); |
| 7225 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7226 | kElementsStartOffset - kHeapObjectTag)); |
| 7227 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7228 | __ j(equal, done); |
| 7229 | |
| 7230 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7231 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7232 | __ j(equal, miss); |
| 7233 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7234 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7235 | // Check for the hole and skip. |
| 7236 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7237 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7238 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7239 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7240 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7241 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7242 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7243 | __ j(not_zero, &good); |
| 7244 | __ cmpb(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7245 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7246 | __ j(not_equal, miss); |
| 7247 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7248 | } |
| 7249 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7250 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7251 | __ push(Immediate(Handle<Object>(name))); |
| 7252 | __ push(Immediate(name->Hash())); |
| 7253 | __ CallStub(&stub); |
| 7254 | __ test(r0, r0); |
| 7255 | __ j(not_zero, miss); |
| 7256 | __ jmp(done); |
| 7257 | } |
| 7258 | |
| 7259 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7260 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7261 | // |done| label if a property with the given name is found leaving the |
| 7262 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7263 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7264 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7265 | Label* miss, |
| 7266 | Label* done, |
| 7267 | Register elements, |
| 7268 | Register name, |
| 7269 | Register r0, |
| 7270 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7271 | ASSERT(!elements.is(r0)); |
| 7272 | ASSERT(!elements.is(r1)); |
| 7273 | ASSERT(!name.is(r0)); |
| 7274 | ASSERT(!name.is(r1)); |
| 7275 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7276 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7277 | |
| 7278 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7279 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7280 | __ dec(r1); |
| 7281 | |
| 7282 | // Generate an unrolled loop that performs a few probes before |
| 7283 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7284 | // cover ~93% of loads from dictionaries. |
| 7285 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7286 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7287 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7288 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7289 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7290 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7291 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7292 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7293 | |
| 7294 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7295 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7296 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7297 | |
| 7298 | // Check if the key is identical to the name. |
| 7299 | __ cmp(name, Operand(elements, |
| 7300 | r0, |
| 7301 | times_4, |
| 7302 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7303 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7304 | } |
| 7305 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7306 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7307 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7308 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7309 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7310 | __ push(r0); |
| 7311 | __ CallStub(&stub); |
| 7312 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7313 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7314 | __ j(zero, miss); |
| 7315 | __ jmp(done); |
| 7316 | } |
| 7317 | |
| 7318 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7319 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7320 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7321 | // 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] | 7322 | // Stack frame on entry: |
| 7323 | // esp[0 * kPointerSize]: return address. |
| 7324 | // esp[1 * kPointerSize]: key's hash. |
| 7325 | // esp[2 * kPointerSize]: key. |
| 7326 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7327 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7328 | // result_: used as scratch. |
| 7329 | // index_: will hold an index of entry if lookup is successful. |
| 7330 | // might alias with result_. |
| 7331 | // Returns: |
| 7332 | // result_ is zero if lookup failed, non zero otherwise. |
| 7333 | |
| 7334 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7335 | |
| 7336 | Register scratch = result_; |
| 7337 | |
| 7338 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7339 | __ dec(scratch); |
| 7340 | __ SmiUntag(scratch); |
| 7341 | __ push(scratch); |
| 7342 | |
| 7343 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7344 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7345 | // undefined value), it guarantees the hash table doesn't contain the |
| 7346 | // property. It's true even if some slots represent deleted properties |
| 7347 | // (their names are the null value). |
| 7348 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7349 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7350 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7351 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7352 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7353 | } |
| 7354 | __ and_(scratch, Operand(esp, 0)); |
| 7355 | |
| 7356 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7357 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7358 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7359 | |
| 7360 | // Having undefined at this place means the name is not contained. |
| 7361 | ASSERT_EQ(kSmiTagSize, 1); |
| 7362 | __ mov(scratch, Operand(dictionary_, |
| 7363 | index_, |
| 7364 | times_pointer_size, |
| 7365 | kElementsStartOffset - kHeapObjectTag)); |
| 7366 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7367 | __ j(equal, ¬_in_dictionary); |
| 7368 | |
| 7369 | // Stop if found the property. |
| 7370 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7371 | __ j(equal, &in_dictionary); |
| 7372 | |
| 7373 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7374 | // If we hit a key that is not a unique name during negative |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7375 | // 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] | 7376 | // key we are looking for. |
| 7377 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7378 | // Check if the entry name is not a unique name. |
| 7379 | Label cont; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7380 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7381 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7382 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7383 | __ j(not_zero, &cont); |
| 7384 | __ cmpb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7385 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7386 | __ j(not_equal, &maybe_in_dictionary); |
| 7387 | __ bind(&cont); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | __ bind(&maybe_in_dictionary); |
| 7392 | // If we are doing negative lookup then probing failure should be |
| 7393 | // treated as a lookup success. For positive lookup probing failure |
| 7394 | // should be treated as lookup failure. |
| 7395 | if (mode_ == POSITIVE_LOOKUP) { |
| 7396 | __ mov(result_, Immediate(0)); |
| 7397 | __ Drop(1); |
| 7398 | __ ret(2 * kPointerSize); |
| 7399 | } |
| 7400 | |
| 7401 | __ bind(&in_dictionary); |
| 7402 | __ mov(result_, Immediate(1)); |
| 7403 | __ Drop(1); |
| 7404 | __ ret(2 * kPointerSize); |
| 7405 | |
| 7406 | __ bind(¬_in_dictionary); |
| 7407 | __ mov(result_, Immediate(0)); |
| 7408 | __ Drop(1); |
| 7409 | __ ret(2 * kPointerSize); |
| 7410 | } |
| 7411 | |
| 7412 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7413 | struct AheadOfTimeWriteBarrierStubList { |
| 7414 | Register object, value, address; |
| 7415 | RememberedSetAction action; |
| 7416 | }; |
| 7417 | |
| 7418 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7419 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7420 | |
| 7421 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7422 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7423 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7424 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7425 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7426 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7427 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7428 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7429 | // Used in StoreStubCompiler::CompileStoreField and |
| 7430 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7431 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7432 | // GenerateStoreField calls the stub with two different permutations of |
| 7433 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7434 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7435 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7436 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7437 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7438 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7439 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7440 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7441 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7442 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7443 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7444 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7445 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7446 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7447 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7448 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7449 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7450 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7451 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7452 | // FastNewClosureStub |
| 7453 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7454 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7455 | { 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] | 7456 | }; |
| 7457 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7458 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7459 | |
| 7460 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7461 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7462 | !entry->object.is(no_reg); |
| 7463 | entry++) { |
| 7464 | if (object_.is(entry->object) && |
| 7465 | value_.is(entry->value) && |
| 7466 | address_.is(entry->address) && |
| 7467 | remembered_set_action_ == entry->action && |
| 7468 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7469 | return true; |
| 7470 | } |
| 7471 | } |
| 7472 | return false; |
| 7473 | } |
| 7474 | |
| 7475 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7476 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7477 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7478 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7479 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7480 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7481 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7482 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7483 | } |
| 7484 | } |
| 7485 | |
| 7486 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7487 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7488 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7489 | !entry->object.is(no_reg); |
| 7490 | entry++) { |
| 7491 | RecordWriteStub stub(entry->object, |
| 7492 | entry->value, |
| 7493 | entry->address, |
| 7494 | entry->action, |
| 7495 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7496 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7497 | } |
| 7498 | } |
| 7499 | |
| 7500 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7501 | bool CodeStub::CanUseFPRegisters() { |
| 7502 | return CpuFeatures::IsSupported(SSE2); |
| 7503 | } |
| 7504 | |
| 7505 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7506 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7507 | // the value has just been written into the object, now this stub makes sure |
| 7508 | // we keep the GC informed. The word in the object where the value has been |
| 7509 | // written is in the address register. |
| 7510 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7511 | Label skip_to_incremental_noncompacting; |
| 7512 | Label skip_to_incremental_compacting; |
| 7513 | |
| 7514 | // The first two instructions are generated with labels so as to get the |
| 7515 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7516 | // forth between a compare instructions (a nop in this position) and the |
| 7517 | // real branch when we start and stop incremental heap marking. |
| 7518 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7519 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7520 | |
| 7521 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7522 | __ RememberedSetHelper(object_, |
| 7523 | address_, |
| 7524 | value_, |
| 7525 | save_fp_regs_mode_, |
| 7526 | MacroAssembler::kReturnAtEnd); |
| 7527 | } else { |
| 7528 | __ ret(0); |
| 7529 | } |
| 7530 | |
| 7531 | __ bind(&skip_to_incremental_noncompacting); |
| 7532 | GenerateIncremental(masm, INCREMENTAL); |
| 7533 | |
| 7534 | __ bind(&skip_to_incremental_compacting); |
| 7535 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7536 | |
| 7537 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7538 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7539 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7540 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7541 | } |
| 7542 | |
| 7543 | |
| 7544 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7545 | regs_.Save(masm); |
| 7546 | |
| 7547 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7548 | Label dont_need_remembered_set; |
| 7549 | |
| 7550 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7551 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7552 | regs_.scratch0(), |
| 7553 | &dont_need_remembered_set); |
| 7554 | |
| 7555 | __ CheckPageFlag(regs_.object(), |
| 7556 | regs_.scratch0(), |
| 7557 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7558 | not_zero, |
| 7559 | &dont_need_remembered_set); |
| 7560 | |
| 7561 | // First notify the incremental marker if necessary, then update the |
| 7562 | // remembered set. |
| 7563 | CheckNeedsToInformIncrementalMarker( |
| 7564 | masm, |
| 7565 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7566 | mode); |
| 7567 | InformIncrementalMarker(masm, mode); |
| 7568 | regs_.Restore(masm); |
| 7569 | __ RememberedSetHelper(object_, |
| 7570 | address_, |
| 7571 | value_, |
| 7572 | save_fp_regs_mode_, |
| 7573 | MacroAssembler::kReturnAtEnd); |
| 7574 | |
| 7575 | __ bind(&dont_need_remembered_set); |
| 7576 | } |
| 7577 | |
| 7578 | CheckNeedsToInformIncrementalMarker( |
| 7579 | masm, |
| 7580 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7581 | mode); |
| 7582 | InformIncrementalMarker(masm, mode); |
| 7583 | regs_.Restore(masm); |
| 7584 | __ ret(0); |
| 7585 | } |
| 7586 | |
| 7587 | |
| 7588 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7589 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7590 | int argument_count = 3; |
| 7591 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7592 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7593 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7594 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7595 | Immediate(ExternalReference::isolate_address())); |
| 7596 | |
| 7597 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7598 | if (mode == INCREMENTAL_COMPACTION) { |
| 7599 | __ CallCFunction( |
| 7600 | ExternalReference::incremental_evacuation_record_write_function( |
| 7601 | masm->isolate()), |
| 7602 | argument_count); |
| 7603 | } else { |
| 7604 | ASSERT(mode == INCREMENTAL); |
| 7605 | __ CallCFunction( |
| 7606 | ExternalReference::incremental_marking_record_write_function( |
| 7607 | masm->isolate()), |
| 7608 | argument_count); |
| 7609 | } |
| 7610 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7611 | } |
| 7612 | |
| 7613 | |
| 7614 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7615 | MacroAssembler* masm, |
| 7616 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7617 | Mode mode) { |
| 7618 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7619 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7620 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7621 | __ and_(regs_.scratch0(), regs_.object()); |
| 7622 | __ mov(regs_.scratch1(), |
| 7623 | Operand(regs_.scratch0(), |
| 7624 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7625 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7626 | __ mov(Operand(regs_.scratch0(), |
| 7627 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7628 | regs_.scratch1()); |
| 7629 | __ j(negative, &need_incremental); |
| 7630 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7631 | // Let's look at the color of the object: If it is not black we don't have |
| 7632 | // to inform the incremental marker. |
| 7633 | __ JumpIfBlack(regs_.object(), |
| 7634 | regs_.scratch0(), |
| 7635 | regs_.scratch1(), |
| 7636 | &object_is_black, |
| 7637 | Label::kNear); |
| 7638 | |
| 7639 | regs_.Restore(masm); |
| 7640 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7641 | __ RememberedSetHelper(object_, |
| 7642 | address_, |
| 7643 | value_, |
| 7644 | save_fp_regs_mode_, |
| 7645 | MacroAssembler::kReturnAtEnd); |
| 7646 | } else { |
| 7647 | __ ret(0); |
| 7648 | } |
| 7649 | |
| 7650 | __ bind(&object_is_black); |
| 7651 | |
| 7652 | // Get the value from the slot. |
| 7653 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7654 | |
| 7655 | if (mode == INCREMENTAL_COMPACTION) { |
| 7656 | Label ensure_not_white; |
| 7657 | |
| 7658 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7659 | regs_.scratch1(), // Scratch. |
| 7660 | MemoryChunk::kEvacuationCandidateMask, |
| 7661 | zero, |
| 7662 | &ensure_not_white, |
| 7663 | Label::kNear); |
| 7664 | |
| 7665 | __ CheckPageFlag(regs_.object(), |
| 7666 | regs_.scratch1(), // Scratch. |
| 7667 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7668 | not_zero, |
| 7669 | &ensure_not_white, |
| 7670 | Label::kNear); |
| 7671 | |
| 7672 | __ jmp(&need_incremental); |
| 7673 | |
| 7674 | __ bind(&ensure_not_white); |
| 7675 | } |
| 7676 | |
| 7677 | // We need an extra register for this, so we push the object register |
| 7678 | // temporarily. |
| 7679 | __ push(regs_.object()); |
| 7680 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7681 | regs_.scratch1(), // Scratch. |
| 7682 | regs_.object(), // Scratch. |
| 7683 | &need_incremental_pop_object, |
| 7684 | Label::kNear); |
| 7685 | __ pop(regs_.object()); |
| 7686 | |
| 7687 | regs_.Restore(masm); |
| 7688 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7689 | __ RememberedSetHelper(object_, |
| 7690 | address_, |
| 7691 | value_, |
| 7692 | save_fp_regs_mode_, |
| 7693 | MacroAssembler::kReturnAtEnd); |
| 7694 | } else { |
| 7695 | __ ret(0); |
| 7696 | } |
| 7697 | |
| 7698 | __ bind(&need_incremental_pop_object); |
| 7699 | __ pop(regs_.object()); |
| 7700 | |
| 7701 | __ bind(&need_incremental); |
| 7702 | |
| 7703 | // Fall through when we need to inform the incremental marker. |
| 7704 | } |
| 7705 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7706 | |
| 7707 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7708 | // ----------- S t a t e ------------- |
| 7709 | // -- eax : element value to store |
| 7710 | // -- ebx : array literal |
| 7711 | // -- edi : map of array literal |
| 7712 | // -- ecx : element index as smi |
| 7713 | // -- edx : array literal index in function |
| 7714 | // -- esp[0] : return address |
| 7715 | // ----------------------------------- |
| 7716 | |
| 7717 | Label element_done; |
| 7718 | Label double_elements; |
| 7719 | Label smi_element; |
| 7720 | Label slow_elements; |
| 7721 | Label slow_elements_from_double; |
| 7722 | Label fast_elements; |
| 7723 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7724 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7725 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7726 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7727 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7728 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7729 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7730 | // Store into the array literal requires a elements transition. Call into |
| 7731 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7732 | |
| 7733 | __ bind(&slow_elements); |
| 7734 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7735 | // call. |
| 7736 | __ push(ebx); |
| 7737 | __ push(ecx); |
| 7738 | __ push(eax); |
| 7739 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7740 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7741 | __ push(edx); |
| 7742 | __ push(edi); // Return return address so that tail call returns to right |
| 7743 | // place. |
| 7744 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7745 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7746 | __ bind(&slow_elements_from_double); |
| 7747 | __ pop(edx); |
| 7748 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7749 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7750 | // 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] | 7751 | __ bind(&fast_elements); |
| 7752 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7753 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7754 | FixedArrayBase::kHeaderSize)); |
| 7755 | __ mov(Operand(ecx, 0), eax); |
| 7756 | // Update the write barrier for the array store. |
| 7757 | __ RecordWrite(ebx, ecx, eax, |
| 7758 | kDontSaveFPRegs, |
| 7759 | EMIT_REMEMBERED_SET, |
| 7760 | OMIT_SMI_CHECK); |
| 7761 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7762 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7763 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7764 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7765 | __ bind(&smi_element); |
| 7766 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7767 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7768 | FixedArrayBase::kHeaderSize), eax); |
| 7769 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7770 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7771 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7772 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7773 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7774 | __ push(edx); |
| 7775 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7776 | __ StoreNumberToDoubleElements(eax, |
| 7777 | edx, |
| 7778 | ecx, |
| 7779 | edi, |
| 7780 | xmm0, |
| 7781 | &slow_elements_from_double, |
| 7782 | false); |
| 7783 | __ pop(edx); |
| 7784 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7785 | } |
| 7786 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7787 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7788 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7789 | ASSERT(!Serializer::enabled()); |
| 7790 | bool save_fp_regs = CpuFeatures::IsSupported(SSE2); |
| 7791 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7792 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7793 | int parameter_count_offset = |
| 7794 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7795 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7796 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7797 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 7798 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7799 | ? kPointerSize |
| 7800 | : 0; |
| 7801 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7802 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7803 | } |
| 7804 | |
| 7805 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7806 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7807 | if (entry_hook_ != NULL) { |
| 7808 | ProfileEntryHookStub stub; |
| 7809 | masm->CallStub(&stub); |
| 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | |
| 7814 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7815 | // Ecx is the only volatile register we must save. |
| 7816 | __ push(ecx); |
| 7817 | |
| 7818 | // Calculate and push the original stack pointer. |
| 7819 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7820 | __ push(eax); |
| 7821 | |
| 7822 | // Calculate and push the function address. |
| 7823 | __ mov(eax, Operand(eax, 0)); |
| 7824 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7825 | __ push(eax); |
| 7826 | |
| 7827 | // Call the entry hook. |
| 7828 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7829 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7830 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7831 | |
| 7832 | // Restore ecx. |
| 7833 | __ pop(ecx); |
| 7834 | __ ret(0); |
| 7835 | } |
| 7836 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7837 | #undef __ |
| 7838 | |
| 7839 | } } // namespace v8::internal |
| 7840 | |
| 7841 | #endif // V8_TARGET_ARCH_IA32 |