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" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 44 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 45 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 46 | Isolate* isolate, |
| 47 | CodeStubInterfaceDescriptor* descriptor) { |
| 48 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 49 | descriptor->register_param_count_ = 4; |
| 50 | descriptor->register_params_ = registers; |
| 51 | descriptor->stack_parameter_count_ = NULL; |
| 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 54 | } |
| 55 | |
| 56 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 57 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { edx, ecx }; |
| 61 | descriptor->register_param_count_ = 2; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 64 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 68 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 69 | Isolate* isolate, |
| 70 | CodeStubInterfaceDescriptor* descriptor) { |
| 71 | static Register registers[] = { eax, ebx }; |
| 72 | descriptor->register_param_count_ = 2; |
| 73 | descriptor->register_params_ = registers; |
| 74 | descriptor->deoptimization_handler_ = |
| 75 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 76 | } |
| 77 | |
| 78 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 79 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 80 | |
| 81 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 82 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 83 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 84 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 85 | __ ret(0); |
| 86 | |
| 87 | __ bind(&check_heap_number); |
| 88 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 89 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 90 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 91 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 92 | __ ret(0); |
| 93 | |
| 94 | __ bind(&call_builtin); |
| 95 | __ pop(ecx); // Pop return address. |
| 96 | __ push(eax); |
| 97 | __ push(ecx); // Push return address. |
| 98 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 99 | } |
| 100 | |
| 101 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 102 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 103 | // Create a new closure from the given function info in new |
| 104 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 105 | Counters* counters = masm->isolate()->counters(); |
| 106 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 107 | Label gc; |
| 108 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 109 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 110 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 111 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 112 | // Get the function info from the stack. |
| 113 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 114 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 115 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 116 | ? Context::FUNCTION_MAP_INDEX |
| 117 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 118 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 119 | // 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] | 120 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 121 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 122 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 123 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 124 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 125 | |
| 126 | // Initialize the rest of the function. We don't have to update the |
| 127 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 128 | Factory* factory = masm->isolate()->factory(); |
| 129 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 130 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 131 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 132 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 133 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 134 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 135 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 136 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 137 | |
| 138 | // Initialize the code pointer in the function to be the one |
| 139 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 140 | // But first check if there is an optimized version for our context. |
| 141 | Label check_optimized; |
| 142 | Label install_unoptimized; |
| 143 | if (FLAG_cache_optimized_code) { |
| 144 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 145 | __ test(ebx, ebx); |
| 146 | __ j(not_zero, &check_optimized, Label::kNear); |
| 147 | } |
| 148 | __ bind(&install_unoptimized); |
| 149 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 150 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 151 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 152 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 153 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 154 | |
| 155 | // Return and remove the on-stack parameter. |
| 156 | __ ret(1 * kPointerSize); |
| 157 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 158 | __ bind(&check_optimized); |
| 159 | |
| 160 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 161 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 162 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 163 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 164 | // Map must never be empty, so check the first elements. |
| 165 | Label install_optimized; |
| 166 | // Speculatively move code object into edx. |
| 167 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 168 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 169 | __ j(equal, &install_optimized); |
| 170 | |
| 171 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 172 | Label loop; |
| 173 | Label restore; |
| 174 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 175 | __ bind(&loop); |
| 176 | // Do not double check first entry. |
| 177 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 178 | __ j(equal, &restore); |
| 179 | __ sub(edx, Immediate(Smi::FromInt( |
| 180 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 181 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 182 | __ j(not_equal, &loop, Label::kNear); |
| 183 | // Hit: fetch the optimized code. |
| 184 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 185 | |
| 186 | __ bind(&install_optimized); |
| 187 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 188 | |
| 189 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 190 | // map and either unmangle them on marking or do nothing as the whole map is |
| 191 | // discarded on major GC anyway. |
| 192 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 193 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 194 | |
| 195 | // Now link a function into a list of optimized functions. |
| 196 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 197 | |
| 198 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 199 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 200 | |
| 201 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 202 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 203 | // it clobbers all the registers passed. |
| 204 | __ mov(edx, eax); |
| 205 | __ RecordWriteContextSlot( |
| 206 | ecx, |
| 207 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 208 | edx, |
| 209 | ebx, |
| 210 | kDontSaveFPRegs); |
| 211 | |
| 212 | // Return and remove the on-stack parameter. |
| 213 | __ ret(1 * kPointerSize); |
| 214 | |
| 215 | __ bind(&restore); |
| 216 | // Restore SharedFunctionInfo into edx. |
| 217 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 218 | __ jmp(&install_unoptimized); |
| 219 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 220 | // Create a new closure through the slower runtime call. |
| 221 | __ bind(&gc); |
| 222 | __ pop(ecx); // Temporarily remove return address. |
| 223 | __ pop(edx); |
| 224 | __ push(esi); |
| 225 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 226 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 227 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 228 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
| 232 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 233 | // Try to allocate the context in new space. |
| 234 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 235 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 236 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 237 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 238 | |
| 239 | // Get the function from the stack. |
| 240 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 241 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 242 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 243 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 244 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 245 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 246 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 247 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 248 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 249 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 250 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 251 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 252 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 253 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 254 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 255 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 256 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 257 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 258 | |
| 259 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 260 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 261 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 262 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 263 | } |
| 264 | |
| 265 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 266 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 267 | __ ret(1 * kPointerSize); |
| 268 | |
| 269 | // Need to collect. Call into runtime system. |
| 270 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 271 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 275 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 276 | // Stack layout on entry: |
| 277 | // |
| 278 | // [esp + (1 * kPointerSize)]: function |
| 279 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 280 | |
| 281 | // Try to allocate the context in new space. |
| 282 | Label gc; |
| 283 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 284 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 285 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 286 | |
| 287 | // Get the function or sentinel from the stack. |
| 288 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 289 | |
| 290 | // Get the serialized scope info from the stack. |
| 291 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 292 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 293 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 294 | Factory* factory = masm->isolate()->factory(); |
| 295 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 296 | factory->block_context_map()); |
| 297 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 298 | Immediate(Smi::FromInt(length))); |
| 299 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 300 | // 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] | 301 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 302 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 303 | // we still have to look up. |
| 304 | Label after_sentinel; |
| 305 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 306 | if (FLAG_debug_code) { |
| 307 | const char* message = "Expected 0 as a Smi sentinel"; |
| 308 | __ cmp(ecx, 0); |
| 309 | __ Assert(equal, message); |
| 310 | } |
| 311 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 312 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 313 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 314 | __ bind(&after_sentinel); |
| 315 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 316 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 317 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 318 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 319 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 320 | |
| 321 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 322 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 323 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 324 | |
| 325 | // Initialize the rest of the slots to the hole value. |
| 326 | if (slots_ == 1) { |
| 327 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 328 | factory->the_hole_value()); |
| 329 | } else { |
| 330 | __ mov(ebx, factory->the_hole_value()); |
| 331 | for (int i = 0; i < slots_; i++) { |
| 332 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | // Return and remove the on-stack parameters. |
| 337 | __ mov(esi, eax); |
| 338 | __ ret(2 * kPointerSize); |
| 339 | |
| 340 | // Need to collect. Call into runtime system. |
| 341 | __ bind(&gc); |
| 342 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 343 | } |
| 344 | |
| 345 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 346 | static void GenerateFastCloneShallowArrayCommon( |
| 347 | MacroAssembler* masm, |
| 348 | int length, |
| 349 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 350 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 351 | Label* fail) { |
| 352 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 353 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 354 | // ecx: boilerplate literal array. |
| 355 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 356 | |
| 357 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 358 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 359 | if (length > 0) { |
| 360 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 361 | ? FixedDoubleArray::SizeFor(length) |
| 362 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 363 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 364 | int size = JSArray::kSize; |
| 365 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 366 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 367 | size += AllocationSiteInfo::kSize; |
| 368 | } |
| 369 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 370 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 371 | // Allocate both the JS array and the elements array in one big |
| 372 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 373 | AllocationFlags flags = TAG_OBJECT; |
| 374 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 375 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 376 | } |
| 377 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 378 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 379 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 380 | __ mov(FieldOperand(eax, allocation_info_start), |
| 381 | Immediate(Handle<Map>(masm->isolate()->heap()-> |
| 382 | allocation_site_info_map()))); |
| 383 | __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); |
| 384 | } |
| 385 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 386 | // Copy the JS array part. |
| 387 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 388 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 389 | __ mov(ebx, FieldOperand(ecx, i)); |
| 390 | __ mov(FieldOperand(eax, i), ebx); |
| 391 | } |
| 392 | } |
| 393 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 394 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 395 | // Get hold of the elements array of the boilerplate and setup the |
| 396 | // elements pointer in the resulting object. |
| 397 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 398 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 399 | __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 400 | } else { |
| 401 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 402 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 403 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 404 | |
| 405 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 406 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 407 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 408 | __ mov(ebx, FieldOperand(ecx, i)); |
| 409 | __ mov(FieldOperand(edx, i), ebx); |
| 410 | } |
| 411 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 412 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 413 | int i; |
| 414 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 415 | __ mov(ebx, FieldOperand(ecx, i)); |
| 416 | __ mov(FieldOperand(edx, i), ebx); |
| 417 | } |
| 418 | while (i < elements_size) { |
| 419 | __ fld_d(FieldOperand(ecx, i)); |
| 420 | __ fstp_d(FieldOperand(edx, i)); |
| 421 | i += kDoubleSize; |
| 422 | } |
| 423 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 426 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 427 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 428 | |
| 429 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 430 | // Stack layout on entry: |
| 431 | // |
| 432 | // [esp + kPointerSize]: constant elements. |
| 433 | // [esp + (2 * kPointerSize)]: literal index. |
| 434 | // [esp + (3 * kPointerSize)]: literals array. |
| 435 | |
| 436 | // Load boilerplate object into ecx and check if we need to create a |
| 437 | // boilerplate. |
| 438 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 439 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 440 | STATIC_ASSERT(kPointerSize == 4); |
| 441 | STATIC_ASSERT(kSmiTagSize == 1); |
| 442 | STATIC_ASSERT(kSmiTag == 0); |
| 443 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 444 | FixedArray::kHeaderSize)); |
| 445 | Factory* factory = masm->isolate()->factory(); |
| 446 | __ cmp(ecx, factory->undefined_value()); |
| 447 | Label slow_case; |
| 448 | __ j(equal, &slow_case); |
| 449 | |
| 450 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 451 | // ecx is boilerplate object. |
| 452 | if (mode == CLONE_ANY_ELEMENTS) { |
| 453 | Label double_elements, check_fast_elements; |
| 454 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 455 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 456 | &check_fast_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 457 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 458 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 459 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 460 | __ ret(3 * kPointerSize); |
| 461 | |
| 462 | __ bind(&check_fast_elements); |
| 463 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 464 | &double_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 465 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 466 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 467 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 468 | __ ret(3 * kPointerSize); |
| 469 | |
| 470 | __ bind(&double_elements); |
| 471 | mode = CLONE_DOUBLE_ELEMENTS; |
| 472 | // Fall through to generate the code to handle double elements. |
| 473 | } |
| 474 | |
| 475 | if (FLAG_debug_code) { |
| 476 | const char* message; |
| 477 | Handle<Map> expected_map; |
| 478 | if (mode == CLONE_ELEMENTS) { |
| 479 | message = "Expected (writable) fixed array"; |
| 480 | expected_map = factory->fixed_array_map(); |
| 481 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 482 | message = "Expected (writable) fixed double array"; |
| 483 | expected_map = factory->fixed_double_array_map(); |
| 484 | } else { |
| 485 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 486 | message = "Expected copy-on-write fixed array"; |
| 487 | expected_map = factory->fixed_cow_array_map(); |
| 488 | } |
| 489 | __ push(ecx); |
| 490 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 491 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 492 | __ Assert(equal, message); |
| 493 | __ pop(ecx); |
| 494 | } |
| 495 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 496 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 497 | allocation_site_mode_, |
| 498 | &slow_case); |
| 499 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 500 | // Return and remove the on-stack parameters. |
| 501 | __ ret(3 * kPointerSize); |
| 502 | |
| 503 | __ bind(&slow_case); |
| 504 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 505 | } |
| 506 | |
| 507 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 508 | // The stub expects its argument on the stack and returns its result in tos_: |
| 509 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 510 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 511 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 512 | // 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] | 513 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 514 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 515 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 516 | const Register map = edx; |
| 517 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 518 | if (!types_.IsEmpty()) { |
| 519 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 520 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 521 | |
| 522 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 523 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 524 | |
| 525 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 526 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 527 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 528 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 529 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 530 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 531 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 532 | if (types_.Contains(SMI)) { |
| 533 | // Smis: 0 -> false, all other -> true |
| 534 | Label not_smi; |
| 535 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 536 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 537 | if (!tos_.is(argument)) { |
| 538 | __ mov(tos_, argument); |
| 539 | } |
| 540 | __ ret(1 * kPointerSize); |
| 541 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 542 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 543 | // If we need a map later and have a Smi -> patch. |
| 544 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 545 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 546 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 547 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 548 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 549 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 550 | if (types_.CanBeUndetectable()) { |
| 551 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 552 | 1 << Map::kIsUndetectable); |
| 553 | // Undetectable -> false. |
| 554 | Label not_undetectable; |
| 555 | __ j(zero, ¬_undetectable, Label::kNear); |
| 556 | __ Set(tos_, Immediate(0)); |
| 557 | __ ret(1 * kPointerSize); |
| 558 | __ bind(¬_undetectable); |
| 559 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 560 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 561 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 562 | if (types_.Contains(SPEC_OBJECT)) { |
| 563 | // spec object -> true. |
| 564 | Label not_js_object; |
| 565 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 566 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 567 | // argument contains the correct return value already. |
| 568 | if (!tos_.is(argument)) { |
| 569 | __ Set(tos_, Immediate(1)); |
| 570 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 571 | __ ret(1 * kPointerSize); |
| 572 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 573 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 574 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 575 | if (types_.Contains(STRING)) { |
| 576 | // String value -> false iff empty. |
| 577 | Label not_string; |
| 578 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 579 | __ j(above_equal, ¬_string, Label::kNear); |
| 580 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 581 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 582 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | if (types_.Contains(HEAP_NUMBER)) { |
| 586 | // heap number -> false iff +0, -0, or NaN. |
| 587 | Label not_heap_number, false_result; |
| 588 | __ cmp(map, factory->heap_number_map()); |
| 589 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 590 | __ fldz(); |
| 591 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 592 | __ FCmp(); |
| 593 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 594 | // argument contains the correct return value already. |
| 595 | if (!tos_.is(argument)) { |
| 596 | __ Set(tos_, Immediate(1)); |
| 597 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 598 | __ ret(1 * kPointerSize); |
| 599 | __ bind(&false_result); |
| 600 | __ Set(tos_, Immediate(0)); |
| 601 | __ ret(1 * kPointerSize); |
| 602 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 603 | } |
| 604 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 605 | __ bind(&patch); |
| 606 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 610 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 611 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 612 | // store the registers in any particular way, but we do have to store and |
| 613 | // restore them. |
| 614 | __ pushad(); |
| 615 | if (save_doubles_ == kSaveFPRegs) { |
| 616 | CpuFeatures::Scope scope(SSE2); |
| 617 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 618 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 619 | XMMRegister reg = XMMRegister::from_code(i); |
| 620 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 621 | } |
| 622 | } |
| 623 | const int argument_count = 1; |
| 624 | |
| 625 | AllowExternalCallThatCantCauseGC scope(masm); |
| 626 | __ PrepareCallCFunction(argument_count, ecx); |
| 627 | __ mov(Operand(esp, 0 * kPointerSize), |
| 628 | Immediate(ExternalReference::isolate_address())); |
| 629 | __ CallCFunction( |
| 630 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 631 | argument_count); |
| 632 | if (save_doubles_ == kSaveFPRegs) { |
| 633 | CpuFeatures::Scope scope(SSE2); |
| 634 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 635 | XMMRegister reg = XMMRegister::from_code(i); |
| 636 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 637 | } |
| 638 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 639 | } |
| 640 | __ popad(); |
| 641 | __ ret(0); |
| 642 | } |
| 643 | |
| 644 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 645 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 646 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 647 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 648 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 649 | const Register argument = eax; |
| 650 | if (types_.Contains(type)) { |
| 651 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 652 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 653 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 654 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 655 | if (!result) { |
| 656 | // If we have to return zero, there is no way around clearing tos_. |
| 657 | __ Set(tos_, Immediate(0)); |
| 658 | } else if (!tos_.is(argument)) { |
| 659 | // If we have to return non-zero, we can re-use the argument if it is the |
| 660 | // same register as the result, because we never see Smi-zero here. |
| 661 | __ Set(tos_, Immediate(1)); |
| 662 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 663 | __ ret(1 * kPointerSize); |
| 664 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
| 668 | |
| 669 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 670 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 671 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 672 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 673 | __ push(ecx); // Push return address. |
| 674 | // Patch the caller to an appropriate specialized stub and return the |
| 675 | // operation result to the caller of the stub. |
| 676 | __ TailCallExternalReference( |
| 677 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 678 | 3, |
| 679 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 683 | class FloatingPointHelper : public AllStatic { |
| 684 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 685 | enum ArgLocation { |
| 686 | ARGS_ON_STACK, |
| 687 | ARGS_IN_REGISTERS |
| 688 | }; |
| 689 | |
| 690 | // Code pattern for loading a floating point value. Input value must |
| 691 | // be either a smi or a heap number object (fp value). Requirements: |
| 692 | // operand in register number. Returns operand as floating point number |
| 693 | // on FPU stack. |
| 694 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 695 | |
| 696 | // Code pattern for loading floating point values. Input values must |
| 697 | // be either smi or heap number objects (fp values). Requirements: |
| 698 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 699 | // Returns operands as floating point numbers on FPU stack. |
| 700 | static void LoadFloatOperands(MacroAssembler* masm, |
| 701 | Register scratch, |
| 702 | ArgLocation arg_location = ARGS_ON_STACK); |
| 703 | |
| 704 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 705 | // Expects operands in edx, eax. |
| 706 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 707 | |
| 708 | // Test if operands are smi or number objects (fp). Requirements: |
| 709 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 710 | // operands, jumps to the non_float label otherwise. |
| 711 | static void CheckFloatOperands(MacroAssembler* masm, |
| 712 | Label* non_float, |
| 713 | Register scratch); |
| 714 | |
| 715 | // Takes the operands in edx and eax and loads them as integers in eax |
| 716 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 717 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 718 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 719 | BinaryOpIC::TypeInfo left_type, |
| 720 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 721 | Label* operand_conversion_failure); |
| 722 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 723 | // Assumes that operands are smis or heap numbers and loads them |
| 724 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 725 | // Leaves operands unchanged. |
| 726 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 727 | |
| 728 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 729 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 730 | // either operand is not a number. Operands are in edx and eax. |
| 731 | // Leaves operands unchanged. |
| 732 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 733 | |
| 734 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 735 | // Expects operands in edx, eax. |
| 736 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 737 | |
| 738 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 739 | // have int32 values. |
| 740 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 741 | Label* non_int32, |
| 742 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 743 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 744 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 745 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 746 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 747 | Label* non_int32, |
| 748 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 749 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 750 | Register scratch, |
| 751 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
| 754 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 755 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 756 | // is faster than using the built-in instructions on floating point registers. |
| 757 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 758 | // trashed registers. |
| 759 | static void IntegerConvert(MacroAssembler* masm, |
| 760 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 761 | bool use_sse3, |
| 762 | Label* conversion_failure) { |
| 763 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 764 | Label done, right_exponent, normal_exponent; |
| 765 | Register scratch = ebx; |
| 766 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 767 | // Get exponent word. |
| 768 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 769 | // Get exponent alone in scratch2. |
| 770 | __ mov(scratch2, scratch); |
| 771 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 772 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 773 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 774 | // Load ecx with zero. We use this either for the final shift or |
| 775 | // for the answer. |
| 776 | __ xor_(ecx, ecx); |
| 777 | // If the exponent is above 83, the number contains no significant |
| 778 | // bits in the range 0..2^31, so the result is zero. |
| 779 | static const uint32_t kResultIsZeroExponent = 83; |
| 780 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 781 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 782 | if (use_sse3) { |
| 783 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 784 | // 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] | 785 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 786 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 787 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 788 | // Load x87 register with heap number. |
| 789 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 790 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 791 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 792 | // Do conversion, which cannot fail because we checked the exponent. |
| 793 | __ fisttp_d(Operand(esp, 0)); |
| 794 | __ 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] | 795 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 796 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 797 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 798 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 799 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 800 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 801 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 802 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 803 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 804 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 805 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 806 | // If the exponent is higher than that then go to slow case. This catches |
| 807 | // 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] | 808 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 809 | |
| 810 | { |
| 811 | // Handle a big exponent. The only reason we have this code is that the |
| 812 | // >>> 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] | 813 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 814 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 815 | __ j(not_equal, conversion_failure); |
| 816 | // We have the big exponent, typically from >>>. This means the number is |
| 817 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 818 | __ mov(scratch2, scratch); |
| 819 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 820 | // Put back the implicit 1. |
| 821 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 822 | // Shift up the mantissa bits to take up the space the exponent used to |
| 823 | // take. We just orred in the implicit bit so that took care of one and |
| 824 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 825 | // shift distance. |
| 826 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 827 | __ shl(scratch2, big_shift_distance); |
| 828 | // Get the second half of the double. |
| 829 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 830 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 831 | // mantissa word. |
| 832 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 833 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 834 | // 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] | 835 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 836 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 837 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 838 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 842 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 843 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 844 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 845 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 846 | |
| 847 | __ bind(&right_exponent); |
| 848 | // Here ecx is the shift, scratch is the exponent word. |
| 849 | // Get the top bits of the mantissa. |
| 850 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 851 | // Put back the implicit 1. |
| 852 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 853 | // Shift up the mantissa bits to take up the space the exponent used to |
| 854 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 855 | // word. Shift them to the top bits. |
| 856 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 857 | __ shl(scratch, shift_distance); |
| 858 | // Get the second half of the double. For some exponents we don't |
| 859 | // actually need this because the bits get shifted out again, but |
| 860 | // it's probably slower to test than just to do it. |
| 861 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 862 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 863 | // mantissa word. |
| 864 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 865 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 866 | // Move down according to the exponent. |
| 867 | __ shr_cl(scratch2); |
| 868 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 869 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 870 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 871 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 872 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 873 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 874 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 875 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 876 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 877 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 878 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 879 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 883 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 884 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 885 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 886 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 887 | Register source, |
| 888 | Label* conversion_failure) { |
| 889 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 890 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 891 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 892 | } |
| 893 | |
| 894 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 895 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 896 | const char* op_name = Token::Name(op_); |
| 897 | const char* overwrite_name = NULL; // Make g++ happy. |
| 898 | switch (mode_) { |
| 899 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 900 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 901 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 902 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 903 | op_name, |
| 904 | overwrite_name, |
| 905 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | |
| 909 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 910 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 911 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 912 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 913 | GenerateTypeTransition(masm); |
| 914 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 915 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 916 | GenerateSmiStub(masm); |
| 917 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 918 | case UnaryOpIC::NUMBER: |
| 919 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 920 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 921 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 922 | GenerateGenericStub(masm); |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 928 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 929 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 930 | |
| 931 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 932 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 933 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 934 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 935 | |
| 936 | __ push(ecx); // Push return address. |
| 937 | |
| 938 | // Patch the caller to an appropriate specialized stub and return the |
| 939 | // operation result to the caller of the stub. |
| 940 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 941 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | |
| 945 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 946 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 947 | switch (op_) { |
| 948 | case Token::SUB: |
| 949 | GenerateSmiStubSub(masm); |
| 950 | break; |
| 951 | case Token::BIT_NOT: |
| 952 | GenerateSmiStubBitNot(masm); |
| 953 | break; |
| 954 | default: |
| 955 | UNREACHABLE(); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 960 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 961 | Label non_smi, undo, slow; |
| 962 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 963 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 964 | __ bind(&undo); |
| 965 | GenerateSmiCodeUndo(masm); |
| 966 | __ bind(&non_smi); |
| 967 | __ bind(&slow); |
| 968 | GenerateTypeTransition(masm); |
| 969 | } |
| 970 | |
| 971 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 972 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 973 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 974 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 975 | __ bind(&non_smi); |
| 976 | GenerateTypeTransition(masm); |
| 977 | } |
| 978 | |
| 979 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 980 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 981 | Label* non_smi, |
| 982 | Label* undo, |
| 983 | Label* slow, |
| 984 | Label::Distance non_smi_near, |
| 985 | Label::Distance undo_near, |
| 986 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 987 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 988 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 989 | |
| 990 | // 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] | 991 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 992 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 993 | |
| 994 | // 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] | 995 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 996 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 997 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 998 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 999 | __ ret(0); |
| 1000 | } |
| 1001 | |
| 1002 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1003 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1004 | MacroAssembler* masm, |
| 1005 | Label* non_smi, |
| 1006 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1007 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1008 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1009 | |
| 1010 | // Flip bits and revert inverted smi-tag. |
| 1011 | __ not_(eax); |
| 1012 | __ and_(eax, ~kSmiTagMask); |
| 1013 | __ ret(0); |
| 1014 | } |
| 1015 | |
| 1016 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1017 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1018 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1023 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1024 | switch (op_) { |
| 1025 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1026 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1029 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1030 | break; |
| 1031 | default: |
| 1032 | UNREACHABLE(); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1037 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1038 | Label non_smi, undo, slow, call_builtin; |
| 1039 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1040 | __ bind(&non_smi); |
| 1041 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1042 | __ bind(&undo); |
| 1043 | GenerateSmiCodeUndo(masm); |
| 1044 | __ bind(&slow); |
| 1045 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1046 | __ bind(&call_builtin); |
| 1047 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1051 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1052 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1053 | Label non_smi, slow; |
| 1054 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1055 | __ bind(&non_smi); |
| 1056 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1057 | __ bind(&slow); |
| 1058 | GenerateTypeTransition(masm); |
| 1059 | } |
| 1060 | |
| 1061 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1062 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1063 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1064 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1065 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1066 | __ j(not_equal, slow); |
| 1067 | |
| 1068 | if (mode_ == UNARY_OVERWRITE) { |
| 1069 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1070 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1071 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1072 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1073 | // edx: operand |
| 1074 | |
| 1075 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1076 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1077 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1078 | |
| 1079 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1080 | { |
| 1081 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1082 | __ push(edx); |
| 1083 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1084 | __ pop(edx); |
| 1085 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1086 | |
| 1087 | __ bind(&heapnumber_allocated); |
| 1088 | // eax: allocated 'empty' number |
| 1089 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1090 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1091 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1092 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1093 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1094 | } |
| 1095 | __ ret(0); |
| 1096 | } |
| 1097 | |
| 1098 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1099 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1100 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1101 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1102 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1103 | __ j(not_equal, slow); |
| 1104 | |
| 1105 | // 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] | 1106 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1107 | |
| 1108 | // 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] | 1109 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1110 | __ not_(ecx); |
| 1111 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1112 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1113 | |
| 1114 | // Tag the result as a smi and we're done. |
| 1115 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1116 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1117 | __ ret(0); |
| 1118 | |
| 1119 | // Try to store the result in a heap number. |
| 1120 | __ bind(&try_float); |
| 1121 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1122 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1123 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1124 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1125 | __ jmp(&heapnumber_allocated); |
| 1126 | |
| 1127 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1128 | { |
| 1129 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1130 | // Push the original HeapNumber on the stack. The integer value can't |
| 1131 | // be stored since it's untagged and not in the smi range (so we can't |
| 1132 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1133 | __ push(ebx); |
| 1134 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1135 | // New HeapNumber is in eax. |
| 1136 | __ pop(edx); |
| 1137 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1138 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1139 | // This conversion won't go slow-case. |
| 1140 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1141 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1142 | |
| 1143 | __ bind(&heapnumber_allocated); |
| 1144 | } |
| 1145 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1146 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1147 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1148 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1149 | } else { |
| 1150 | __ push(ecx); |
| 1151 | __ fild_s(Operand(esp, 0)); |
| 1152 | __ pop(ecx); |
| 1153 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1154 | } |
| 1155 | __ ret(0); |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1160 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1161 | switch (op_) { |
| 1162 | case Token::SUB: |
| 1163 | GenerateGenericStubSub(masm); |
| 1164 | break; |
| 1165 | case Token::BIT_NOT: |
| 1166 | GenerateGenericStubBitNot(masm); |
| 1167 | break; |
| 1168 | default: |
| 1169 | UNREACHABLE(); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1174 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1175 | Label non_smi, undo, slow; |
| 1176 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1177 | __ bind(&non_smi); |
| 1178 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1179 | __ bind(&undo); |
| 1180 | GenerateSmiCodeUndo(masm); |
| 1181 | __ bind(&slow); |
| 1182 | GenerateGenericCodeFallback(masm); |
| 1183 | } |
| 1184 | |
| 1185 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1186 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1187 | Label non_smi, slow; |
| 1188 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1189 | __ bind(&non_smi); |
| 1190 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1191 | __ bind(&slow); |
| 1192 | GenerateGenericCodeFallback(masm); |
| 1193 | } |
| 1194 | |
| 1195 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1196 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1197 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1198 | __ pop(ecx); // pop return address. |
| 1199 | __ push(eax); |
| 1200 | __ push(ecx); // push return address |
| 1201 | switch (op_) { |
| 1202 | case Token::SUB: |
| 1203 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1204 | break; |
| 1205 | case Token::BIT_NOT: |
| 1206 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1207 | break; |
| 1208 | default: |
| 1209 | UNREACHABLE(); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1214 | void BinaryOpStub::Initialize() { |
| 1215 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1216 | } |
| 1217 | |
| 1218 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1219 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1220 | __ pop(ecx); // Save return address. |
| 1221 | __ push(edx); |
| 1222 | __ push(eax); |
| 1223 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1224 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1225 | |
| 1226 | __ push(ecx); // Push return address. |
| 1227 | |
| 1228 | // Patch the caller to an appropriate specialized stub and return the |
| 1229 | // operation result to the caller of the stub. |
| 1230 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1231 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1232 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1233 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1234 | 1); |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | // Prepare for a type transition runtime call when the args are already on |
| 1239 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1240 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1241 | __ pop(ecx); // Save return address. |
| 1242 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1243 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1244 | |
| 1245 | __ push(ecx); // Push return address. |
| 1246 | |
| 1247 | // Patch the caller to an appropriate specialized stub and return the |
| 1248 | // operation result to the caller of the stub. |
| 1249 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1250 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1251 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1252 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1253 | 1); |
| 1254 | } |
| 1255 | |
| 1256 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1257 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1258 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1259 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1260 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1261 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1263 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1264 | Comment load_comment(masm, "-- Load arguments"); |
| 1265 | Register left = edx; |
| 1266 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1267 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | left = eax; |
| 1269 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1270 | __ mov(ebx, eax); |
| 1271 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | |
| 1275 | // 2. Prepare the smi check of both operands by oring them together. |
| 1276 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1277 | Label not_smis; |
| 1278 | Register combined = ecx; |
| 1279 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1280 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1281 | case Token::BIT_OR: |
| 1282 | // Perform the operation into eax and smi check the result. Preserve |
| 1283 | // eax in case the result is not a smi. |
| 1284 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1285 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1286 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1287 | combined = right; |
| 1288 | break; |
| 1289 | |
| 1290 | case Token::BIT_XOR: |
| 1291 | case Token::BIT_AND: |
| 1292 | case Token::ADD: |
| 1293 | case Token::SUB: |
| 1294 | case Token::MUL: |
| 1295 | case Token::DIV: |
| 1296 | case Token::MOD: |
| 1297 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1298 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | break; |
| 1300 | |
| 1301 | case Token::SHL: |
| 1302 | case Token::SAR: |
| 1303 | case Token::SHR: |
| 1304 | // Move the right operand into ecx for the shift operation, use eax |
| 1305 | // for the smi check register. |
| 1306 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1307 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1308 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | combined = right; |
| 1310 | break; |
| 1311 | |
| 1312 | default: |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | // 3. Perform the smi check of the operands. |
| 1317 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1318 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1319 | |
| 1320 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1321 | // eax and check the result if necessary. |
| 1322 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1323 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1324 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1325 | case Token::BIT_OR: |
| 1326 | // Nothing to do. |
| 1327 | break; |
| 1328 | |
| 1329 | case Token::BIT_XOR: |
| 1330 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1331 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1332 | break; |
| 1333 | |
| 1334 | case Token::BIT_AND: |
| 1335 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1336 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1337 | break; |
| 1338 | |
| 1339 | case Token::SHL: |
| 1340 | // Remove tags from operands (but keep sign). |
| 1341 | __ SmiUntag(left); |
| 1342 | __ SmiUntag(ecx); |
| 1343 | // Perform the operation. |
| 1344 | __ shl_cl(left); |
| 1345 | // Check that the *signed* result fits in a smi. |
| 1346 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1347 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1348 | // Tag the result and store it in register eax. |
| 1349 | __ SmiTag(left); |
| 1350 | __ mov(eax, left); |
| 1351 | break; |
| 1352 | |
| 1353 | case Token::SAR: |
| 1354 | // Remove tags from operands (but keep sign). |
| 1355 | __ SmiUntag(left); |
| 1356 | __ SmiUntag(ecx); |
| 1357 | // Perform the operation. |
| 1358 | __ sar_cl(left); |
| 1359 | // Tag the result and store it in register eax. |
| 1360 | __ SmiTag(left); |
| 1361 | __ mov(eax, left); |
| 1362 | break; |
| 1363 | |
| 1364 | case Token::SHR: |
| 1365 | // Remove tags from operands (but keep sign). |
| 1366 | __ SmiUntag(left); |
| 1367 | __ SmiUntag(ecx); |
| 1368 | // Perform the operation. |
| 1369 | __ shr_cl(left); |
| 1370 | // Check that the *unsigned* result fits in a smi. |
| 1371 | // Neither of the two high-order bits can be set: |
| 1372 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1373 | // - 0x40000000: this number would convert to negative when |
| 1374 | // Smi tagging these two cases can only happen with shifts |
| 1375 | // by 0 or 1 when handed a valid smi. |
| 1376 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1377 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1378 | // Tag the result and store it in register eax. |
| 1379 | __ SmiTag(left); |
| 1380 | __ mov(eax, left); |
| 1381 | break; |
| 1382 | |
| 1383 | case Token::ADD: |
| 1384 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1385 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1386 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1387 | break; |
| 1388 | |
| 1389 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1390 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1391 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1392 | __ mov(eax, left); |
| 1393 | break; |
| 1394 | |
| 1395 | case Token::MUL: |
| 1396 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1397 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1398 | // We can't revert the multiplication if the result is not a smi |
| 1399 | // so save the right operand. |
| 1400 | __ mov(ebx, right); |
| 1401 | // Remove tag from one of the operands (but keep sign). |
| 1402 | __ SmiUntag(right); |
| 1403 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1404 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1405 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1406 | // Check for negative zero result. Use combined = left | right. |
| 1407 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1408 | break; |
| 1409 | |
| 1410 | case Token::DIV: |
| 1411 | // We can't revert the division if the result is not a smi so |
| 1412 | // save the left operand. |
| 1413 | __ mov(edi, left); |
| 1414 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1415 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1416 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1417 | // Sign extend left into edx:eax. |
| 1418 | ASSERT(left.is(eax)); |
| 1419 | __ cdq(); |
| 1420 | // Divide edx:eax by right. |
| 1421 | __ idiv(right); |
| 1422 | // Check for the corner case of dividing the most negative smi by |
| 1423 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1424 | // instruction. |
| 1425 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1426 | __ cmp(eax, 0x40000000); |
| 1427 | __ j(equal, &use_fp_on_smis); |
| 1428 | // Check for negative zero result. Use combined = left | right. |
| 1429 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1430 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1431 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | __ j(not_zero, &use_fp_on_smis); |
| 1433 | // Tag the result and store it in register eax. |
| 1434 | __ SmiTag(eax); |
| 1435 | break; |
| 1436 | |
| 1437 | case Token::MOD: |
| 1438 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1439 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1440 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1441 | |
| 1442 | // Sign extend left into edx:eax. |
| 1443 | ASSERT(left.is(eax)); |
| 1444 | __ cdq(); |
| 1445 | // Divide edx:eax by right. |
| 1446 | __ idiv(right); |
| 1447 | // Check for negative zero result. Use combined = left | right. |
| 1448 | __ NegativeZeroTest(edx, combined, slow); |
| 1449 | // Move remainder to register eax. |
| 1450 | __ mov(eax, edx); |
| 1451 | break; |
| 1452 | |
| 1453 | default: |
| 1454 | UNREACHABLE(); |
| 1455 | } |
| 1456 | |
| 1457 | // 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] | 1458 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1459 | case Token::ADD: |
| 1460 | case Token::SUB: |
| 1461 | case Token::MUL: |
| 1462 | case Token::DIV: |
| 1463 | __ ret(0); |
| 1464 | break; |
| 1465 | case Token::MOD: |
| 1466 | case Token::BIT_OR: |
| 1467 | case Token::BIT_AND: |
| 1468 | case Token::BIT_XOR: |
| 1469 | case Token::SAR: |
| 1470 | case Token::SHL: |
| 1471 | case Token::SHR: |
| 1472 | __ ret(2 * kPointerSize); |
| 1473 | break; |
| 1474 | default: |
| 1475 | UNREACHABLE(); |
| 1476 | } |
| 1477 | |
| 1478 | // 6. For some operations emit inline code to perform floating point |
| 1479 | // operations on known smis (e.g., if the result of the operation |
| 1480 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1481 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1482 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1483 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1484 | // Undo the effects of some operations, and some register moves. |
| 1485 | case Token::SHL: |
| 1486 | // The arguments are saved on the stack, and only used from there. |
| 1487 | break; |
| 1488 | case Token::ADD: |
| 1489 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1490 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | case Token::SUB: |
| 1493 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1494 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | case Token::MUL: |
| 1497 | // Right was clobbered but a copy is in ebx. |
| 1498 | __ mov(right, ebx); |
| 1499 | break; |
| 1500 | case Token::DIV: |
| 1501 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1502 | // division. They should be in eax, ebx for jump to not_smi. |
| 1503 | __ mov(eax, edi); |
| 1504 | break; |
| 1505 | default: |
| 1506 | // No other operators jump to use_fp_on_smis. |
| 1507 | break; |
| 1508 | } |
| 1509 | __ jmp(¬_smis); |
| 1510 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1511 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1512 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1513 | case Token::SHL: |
| 1514 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1515 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1516 | __ bind(&use_fp_on_smis); |
| 1517 | // Result we want is in left == edx, so we can put the allocated heap |
| 1518 | // number in eax. |
| 1519 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1520 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1521 | // It's OK to overwrite the arguments on the stack because we |
| 1522 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1523 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1524 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1525 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1526 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1527 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1528 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1529 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1530 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1531 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1532 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1533 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1534 | } else { |
| 1535 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1536 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1537 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1538 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1539 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1540 | __ ret(2 * kPointerSize); |
| 1541 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | case Token::ADD: |
| 1545 | case Token::SUB: |
| 1546 | case Token::MUL: |
| 1547 | case Token::DIV: { |
| 1548 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1549 | __ bind(&use_fp_on_smis); |
| 1550 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1551 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1552 | case Token::ADD: |
| 1553 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1554 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | break; |
| 1556 | case Token::SUB: |
| 1557 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1558 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | case Token::MUL: |
| 1561 | // Right was clobbered but a copy is in ebx. |
| 1562 | __ mov(right, ebx); |
| 1563 | break; |
| 1564 | case Token::DIV: |
| 1565 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1566 | // division. |
| 1567 | __ mov(edx, edi); |
| 1568 | __ mov(eax, right); |
| 1569 | break; |
| 1570 | default: UNREACHABLE(); |
| 1571 | break; |
| 1572 | } |
| 1573 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1574 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1575 | CpuFeatures::Scope use_sse2(SSE2); |
| 1576 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1577 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1578 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1579 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1580 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1581 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1582 | default: UNREACHABLE(); |
| 1583 | } |
| 1584 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1585 | } else { // SSE2 not available, use FPU. |
| 1586 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1587 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1588 | case Token::ADD: __ faddp(1); break; |
| 1589 | case Token::SUB: __ fsubp(1); break; |
| 1590 | case Token::MUL: __ fmulp(1); break; |
| 1591 | case Token::DIV: __ fdivp(1); break; |
| 1592 | default: UNREACHABLE(); |
| 1593 | } |
| 1594 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1595 | } |
| 1596 | __ mov(eax, ecx); |
| 1597 | __ ret(0); |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | default: |
| 1602 | break; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1607 | // edx and eax. |
| 1608 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1609 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1610 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1611 | case Token::BIT_OR: |
| 1612 | case Token::SHL: |
| 1613 | case Token::SAR: |
| 1614 | case Token::SHR: |
| 1615 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1616 | // check. |
| 1617 | __ mov(eax, ecx); |
| 1618 | break; |
| 1619 | |
| 1620 | case Token::DIV: |
| 1621 | case Token::MOD: |
| 1622 | // Operands are in eax, ebx at this point. |
| 1623 | __ mov(edx, eax); |
| 1624 | __ mov(eax, ebx); |
| 1625 | break; |
| 1626 | |
| 1627 | default: |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1633 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | Label call_runtime; |
| 1635 | |
| 1636 | switch (op_) { |
| 1637 | case Token::ADD: |
| 1638 | case Token::SUB: |
| 1639 | case Token::MUL: |
| 1640 | case Token::DIV: |
| 1641 | break; |
| 1642 | case Token::MOD: |
| 1643 | case Token::BIT_OR: |
| 1644 | case Token::BIT_AND: |
| 1645 | case Token::BIT_XOR: |
| 1646 | case Token::SAR: |
| 1647 | case Token::SHL: |
| 1648 | case Token::SHR: |
| 1649 | GenerateRegisterArgsPush(masm); |
| 1650 | break; |
| 1651 | default: |
| 1652 | UNREACHABLE(); |
| 1653 | } |
| 1654 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1655 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1656 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1657 | BinaryOpStub_GenerateSmiCode( |
| 1658 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1659 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1660 | BinaryOpStub_GenerateSmiCode( |
| 1661 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1662 | } |
| 1663 | __ bind(&call_runtime); |
| 1664 | switch (op_) { |
| 1665 | case Token::ADD: |
| 1666 | case Token::SUB: |
| 1667 | case Token::MUL: |
| 1668 | case Token::DIV: |
| 1669 | GenerateTypeTransition(masm); |
| 1670 | break; |
| 1671 | case Token::MOD: |
| 1672 | case Token::BIT_OR: |
| 1673 | case Token::BIT_AND: |
| 1674 | case Token::BIT_XOR: |
| 1675 | case Token::SAR: |
| 1676 | case Token::SHL: |
| 1677 | case Token::SHR: |
| 1678 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1679 | break; |
| 1680 | default: |
| 1681 | UNREACHABLE(); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1686 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1687 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1688 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1689 | ASSERT(op_ == Token::ADD); |
| 1690 | // If both arguments are strings, call the string add stub. |
| 1691 | // Otherwise, do a transition. |
| 1692 | |
| 1693 | // Registers containing left and right operands respectively. |
| 1694 | Register left = edx; |
| 1695 | Register right = eax; |
| 1696 | |
| 1697 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1698 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1699 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1700 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1701 | |
| 1702 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1703 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1704 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1705 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1706 | |
| 1707 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1708 | GenerateRegisterArgsPush(masm); |
| 1709 | __ TailCallStub(&string_add_stub); |
| 1710 | |
| 1711 | __ bind(&call_runtime); |
| 1712 | GenerateTypeTransition(masm); |
| 1713 | } |
| 1714 | |
| 1715 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1716 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1717 | Label* alloc_failure, |
| 1718 | OverwriteMode mode); |
| 1719 | |
| 1720 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1721 | // Input: |
| 1722 | // edx: left operand (tagged) |
| 1723 | // eax: right operand (tagged) |
| 1724 | // Output: |
| 1725 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1726 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1727 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1728 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1729 | |
| 1730 | // Floating point case. |
| 1731 | switch (op_) { |
| 1732 | case Token::ADD: |
| 1733 | case Token::SUB: |
| 1734 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1735 | case Token::DIV: |
| 1736 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1737 | Label not_floats; |
| 1738 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1739 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1740 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1741 | // It could be that only SMIs have been seen at either the left |
| 1742 | // or the right operand. For precise type feedback, patch the IC |
| 1743 | // again if this changes. |
| 1744 | // In theory, we would need the same check in the non-SSE2 case, |
| 1745 | // but since we don't support Crankshaft on such hardware we can |
| 1746 | // afford not to care about precise type feedback. |
| 1747 | if (left_type_ == BinaryOpIC::SMI) { |
| 1748 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1749 | } |
| 1750 | if (right_type_ == BinaryOpIC::SMI) { |
| 1751 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1752 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1753 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1754 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1755 | if (op_ == Token::MOD) { |
| 1756 | GenerateRegisterArgsPush(masm); |
| 1757 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1758 | } else { |
| 1759 | switch (op_) { |
| 1760 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1761 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1762 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1763 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1764 | default: UNREACHABLE(); |
| 1765 | } |
| 1766 | // Check result type if it is currently Int32. |
| 1767 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1768 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1769 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1770 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1771 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1772 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1773 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1774 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | } else { // SSE2 not available, use FPU. |
| 1776 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1777 | FloatingPointHelper::LoadFloatOperands( |
| 1778 | masm, |
| 1779 | ecx, |
| 1780 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1781 | if (op_ == Token::MOD) { |
| 1782 | // The operands are now on the FPU stack, but we don't need them. |
| 1783 | __ fstp(0); |
| 1784 | __ fstp(0); |
| 1785 | GenerateRegisterArgsPush(masm); |
| 1786 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1787 | } else { |
| 1788 | switch (op_) { |
| 1789 | case Token::ADD: __ faddp(1); break; |
| 1790 | case Token::SUB: __ fsubp(1); break; |
| 1791 | case Token::MUL: __ fmulp(1); break; |
| 1792 | case Token::DIV: __ fdivp(1); break; |
| 1793 | default: UNREACHABLE(); |
| 1794 | } |
| 1795 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1796 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1797 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1798 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1799 | __ ret(0); |
| 1800 | __ bind(&after_alloc_failure); |
| 1801 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1802 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1803 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | __ bind(¬_floats); |
| 1807 | __ bind(¬_int32); |
| 1808 | GenerateTypeTransition(masm); |
| 1809 | break; |
| 1810 | } |
| 1811 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1812 | case Token::BIT_OR: |
| 1813 | case Token::BIT_AND: |
| 1814 | case Token::BIT_XOR: |
| 1815 | case Token::SAR: |
| 1816 | case Token::SHL: |
| 1817 | case Token::SHR: { |
| 1818 | GenerateRegisterArgsPush(masm); |
| 1819 | Label not_floats; |
| 1820 | Label not_int32; |
| 1821 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1822 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1823 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1824 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1825 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1826 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1827 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1828 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1829 | case Token::SAR: __ sar_cl(eax); break; |
| 1830 | case Token::SHL: __ shl_cl(eax); break; |
| 1831 | case Token::SHR: __ shr_cl(eax); break; |
| 1832 | default: UNREACHABLE(); |
| 1833 | } |
| 1834 | if (op_ == Token::SHR) { |
| 1835 | // Check if result is non-negative and fits in a smi. |
| 1836 | __ test(eax, Immediate(0xc0000000)); |
| 1837 | __ j(not_zero, &call_runtime); |
| 1838 | } else { |
| 1839 | // Check if result fits in a smi. |
| 1840 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1841 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1842 | } |
| 1843 | // Tag smi result and return. |
| 1844 | __ SmiTag(eax); |
| 1845 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1846 | |
| 1847 | // All ops except SHR return a signed int32 that we load in |
| 1848 | // a HeapNumber. |
| 1849 | if (op_ != Token::SHR) { |
| 1850 | __ bind(&non_smi_result); |
| 1851 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1852 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1853 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1854 | switch (mode_) { |
| 1855 | case OVERWRITE_LEFT: |
| 1856 | case OVERWRITE_RIGHT: |
| 1857 | // If the operand was an object, we skip the |
| 1858 | // allocation of a heap number. |
| 1859 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1860 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1861 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1862 | // Fall through! |
| 1863 | case NO_OVERWRITE: |
| 1864 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1865 | __ bind(&skip_allocation); |
| 1866 | break; |
| 1867 | default: UNREACHABLE(); |
| 1868 | } |
| 1869 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1870 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1871 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1872 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1873 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1874 | } else { |
| 1875 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1876 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1877 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1878 | } |
| 1879 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1880 | } |
| 1881 | |
| 1882 | __ bind(¬_floats); |
| 1883 | __ bind(¬_int32); |
| 1884 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1885 | break; |
| 1886 | } |
| 1887 | default: UNREACHABLE(); break; |
| 1888 | } |
| 1889 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1890 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1891 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1892 | __ bind(&call_runtime); |
| 1893 | |
| 1894 | switch (op_) { |
| 1895 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1896 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1897 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1898 | case Token::DIV: |
| 1899 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | break; |
| 1901 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1902 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1903 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1904 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1905 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1907 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1908 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | default: |
| 1911 | UNREACHABLE(); |
| 1912 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1913 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1917 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1918 | if (op_ == Token::ADD) { |
| 1919 | // Handle string addition here, because it is the only operation |
| 1920 | // that does not do a ToNumber conversion on the operands. |
| 1921 | GenerateAddStrings(masm); |
| 1922 | } |
| 1923 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1924 | Factory* factory = masm->isolate()->factory(); |
| 1925 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1926 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1927 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1928 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1929 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1930 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1931 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1932 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1933 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1934 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1935 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1936 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1937 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1938 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1939 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1940 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1941 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1942 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1943 | } |
| 1944 | __ bind(&done); |
| 1945 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1946 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 1950 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1951 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1952 | |
| 1953 | // Floating point case. |
| 1954 | switch (op_) { |
| 1955 | case Token::ADD: |
| 1956 | case Token::SUB: |
| 1957 | case Token::MUL: |
| 1958 | case Token::DIV: { |
| 1959 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1960 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1961 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1962 | |
| 1963 | // It could be that only SMIs have been seen at either the left |
| 1964 | // or the right operand. For precise type feedback, patch the IC |
| 1965 | // again if this changes. |
| 1966 | // In theory, we would need the same check in the non-SSE2 case, |
| 1967 | // but since we don't support Crankshaft on such hardware we can |
| 1968 | // afford not to care about precise type feedback. |
| 1969 | if (left_type_ == BinaryOpIC::SMI) { |
| 1970 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1971 | } |
| 1972 | if (right_type_ == BinaryOpIC::SMI) { |
| 1973 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1974 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1975 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1976 | if (left_type_ == BinaryOpIC::INT32) { |
| 1977 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1978 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1979 | } |
| 1980 | if (right_type_ == BinaryOpIC::INT32) { |
| 1981 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1982 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1983 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1984 | |
| 1985 | switch (op_) { |
| 1986 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1987 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1988 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1989 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1990 | default: UNREACHABLE(); |
| 1991 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1992 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1993 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1994 | __ ret(0); |
| 1995 | } else { // SSE2 not available, use FPU. |
| 1996 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1997 | FloatingPointHelper::LoadFloatOperands( |
| 1998 | masm, |
| 1999 | ecx, |
| 2000 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2001 | switch (op_) { |
| 2002 | case Token::ADD: __ faddp(1); break; |
| 2003 | case Token::SUB: __ fsubp(1); break; |
| 2004 | case Token::MUL: __ fmulp(1); break; |
| 2005 | case Token::DIV: __ fdivp(1); break; |
| 2006 | default: UNREACHABLE(); |
| 2007 | } |
| 2008 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2009 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2010 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2011 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2012 | __ ret(0); |
| 2013 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2014 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | __ jmp(&call_runtime); |
| 2016 | } |
| 2017 | |
| 2018 | __ bind(¬_floats); |
| 2019 | GenerateTypeTransition(masm); |
| 2020 | break; |
| 2021 | } |
| 2022 | |
| 2023 | case Token::MOD: { |
| 2024 | // For MOD we go directly to runtime in the non-smi case. |
| 2025 | break; |
| 2026 | } |
| 2027 | case Token::BIT_OR: |
| 2028 | case Token::BIT_AND: |
| 2029 | case Token::BIT_XOR: |
| 2030 | case Token::SAR: |
| 2031 | case Token::SHL: |
| 2032 | case Token::SHR: { |
| 2033 | GenerateRegisterArgsPush(masm); |
| 2034 | Label not_floats; |
| 2035 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2036 | // We do not check the input arguments here, as any value is |
| 2037 | // unconditionally truncated to an int32 anyway. To get the |
| 2038 | // right optimized code, int32 type feedback is just right. |
| 2039 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2040 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2041 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2042 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2043 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2044 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2045 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2046 | case Token::SAR: __ sar_cl(eax); break; |
| 2047 | case Token::SHL: __ shl_cl(eax); break; |
| 2048 | case Token::SHR: __ shr_cl(eax); break; |
| 2049 | default: UNREACHABLE(); |
| 2050 | } |
| 2051 | if (op_ == Token::SHR) { |
| 2052 | // Check if result is non-negative and fits in a smi. |
| 2053 | __ test(eax, Immediate(0xc0000000)); |
| 2054 | __ j(not_zero, &call_runtime); |
| 2055 | } else { |
| 2056 | // Check if result fits in a smi. |
| 2057 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2058 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2059 | } |
| 2060 | // Tag smi result and return. |
| 2061 | __ SmiTag(eax); |
| 2062 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2063 | |
| 2064 | // All ops except SHR return a signed int32 that we load in |
| 2065 | // a HeapNumber. |
| 2066 | if (op_ != Token::SHR) { |
| 2067 | __ bind(&non_smi_result); |
| 2068 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2069 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2070 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2071 | switch (mode_) { |
| 2072 | case OVERWRITE_LEFT: |
| 2073 | case OVERWRITE_RIGHT: |
| 2074 | // If the operand was an object, we skip the |
| 2075 | // allocation of a heap number. |
| 2076 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2077 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2078 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2079 | // Fall through! |
| 2080 | case NO_OVERWRITE: |
| 2081 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2082 | __ bind(&skip_allocation); |
| 2083 | break; |
| 2084 | default: UNREACHABLE(); |
| 2085 | } |
| 2086 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2087 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2088 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2089 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2090 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2091 | } else { |
| 2092 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2093 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2094 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2095 | } |
| 2096 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2097 | } |
| 2098 | |
| 2099 | __ bind(¬_floats); |
| 2100 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2101 | break; |
| 2102 | } |
| 2103 | default: UNREACHABLE(); break; |
| 2104 | } |
| 2105 | |
| 2106 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2107 | // use the runtime system to get the correct result. |
| 2108 | __ bind(&call_runtime); |
| 2109 | |
| 2110 | switch (op_) { |
| 2111 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2112 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2115 | case Token::MOD: |
| 2116 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2119 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2120 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2121 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2122 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2123 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | default: |
| 2126 | UNREACHABLE(); |
| 2127 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2128 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2132 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2133 | Label call_runtime; |
| 2134 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2135 | Counters* counters = masm->isolate()->counters(); |
| 2136 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2137 | |
| 2138 | switch (op_) { |
| 2139 | case Token::ADD: |
| 2140 | case Token::SUB: |
| 2141 | case Token::MUL: |
| 2142 | case Token::DIV: |
| 2143 | break; |
| 2144 | case Token::MOD: |
| 2145 | case Token::BIT_OR: |
| 2146 | case Token::BIT_AND: |
| 2147 | case Token::BIT_XOR: |
| 2148 | case Token::SAR: |
| 2149 | case Token::SHL: |
| 2150 | case Token::SHR: |
| 2151 | GenerateRegisterArgsPush(masm); |
| 2152 | break; |
| 2153 | default: |
| 2154 | UNREACHABLE(); |
| 2155 | } |
| 2156 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2157 | BinaryOpStub_GenerateSmiCode( |
| 2158 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | |
| 2160 | // Floating point case. |
| 2161 | switch (op_) { |
| 2162 | case Token::ADD: |
| 2163 | case Token::SUB: |
| 2164 | case Token::MUL: |
| 2165 | case Token::DIV: { |
| 2166 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2167 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2168 | CpuFeatures::Scope use_sse2(SSE2); |
| 2169 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2170 | |
| 2171 | switch (op_) { |
| 2172 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2173 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2174 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2175 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2176 | default: UNREACHABLE(); |
| 2177 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2178 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2179 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2180 | __ ret(0); |
| 2181 | } else { // SSE2 not available, use FPU. |
| 2182 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2183 | FloatingPointHelper::LoadFloatOperands( |
| 2184 | masm, |
| 2185 | ecx, |
| 2186 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2187 | switch (op_) { |
| 2188 | case Token::ADD: __ faddp(1); break; |
| 2189 | case Token::SUB: __ fsubp(1); break; |
| 2190 | case Token::MUL: __ fmulp(1); break; |
| 2191 | case Token::DIV: __ fdivp(1); break; |
| 2192 | default: UNREACHABLE(); |
| 2193 | } |
| 2194 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2195 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2196 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2197 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2198 | __ ret(0); |
| 2199 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2200 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2201 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | } |
| 2203 | __ bind(¬_floats); |
| 2204 | break; |
| 2205 | } |
| 2206 | case Token::MOD: { |
| 2207 | // For MOD we go directly to runtime in the non-smi case. |
| 2208 | break; |
| 2209 | } |
| 2210 | case Token::BIT_OR: |
| 2211 | case Token::BIT_AND: |
| 2212 | case Token::BIT_XOR: |
| 2213 | case Token::SAR: |
| 2214 | case Token::SHL: |
| 2215 | case Token::SHR: { |
| 2216 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2217 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2218 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2219 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2220 | BinaryOpIC::GENERIC, |
| 2221 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2222 | &call_runtime); |
| 2223 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2224 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2225 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2226 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2227 | case Token::SAR: __ sar_cl(eax); break; |
| 2228 | case Token::SHL: __ shl_cl(eax); break; |
| 2229 | case Token::SHR: __ shr_cl(eax); break; |
| 2230 | default: UNREACHABLE(); |
| 2231 | } |
| 2232 | if (op_ == Token::SHR) { |
| 2233 | // Check if result is non-negative and fits in a smi. |
| 2234 | __ test(eax, Immediate(0xc0000000)); |
| 2235 | __ j(not_zero, &call_runtime); |
| 2236 | } else { |
| 2237 | // Check if result fits in a smi. |
| 2238 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2239 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2240 | } |
| 2241 | // Tag smi result and return. |
| 2242 | __ SmiTag(eax); |
| 2243 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2244 | |
| 2245 | // All ops except SHR return a signed int32 that we load in |
| 2246 | // a HeapNumber. |
| 2247 | if (op_ != Token::SHR) { |
| 2248 | __ bind(&non_smi_result); |
| 2249 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2250 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2251 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2252 | switch (mode_) { |
| 2253 | case OVERWRITE_LEFT: |
| 2254 | case OVERWRITE_RIGHT: |
| 2255 | // If the operand was an object, we skip the |
| 2256 | // allocation of a heap number. |
| 2257 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2258 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2259 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2260 | // Fall through! |
| 2261 | case NO_OVERWRITE: |
| 2262 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2263 | __ bind(&skip_allocation); |
| 2264 | break; |
| 2265 | default: UNREACHABLE(); |
| 2266 | } |
| 2267 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2268 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2269 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2270 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2271 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2272 | } else { |
| 2273 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2274 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2275 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2276 | } |
| 2277 | __ ret(2 * kPointerSize); |
| 2278 | } |
| 2279 | break; |
| 2280 | } |
| 2281 | default: UNREACHABLE(); break; |
| 2282 | } |
| 2283 | |
| 2284 | // If all else fails, use the runtime system to get the correct |
| 2285 | // result. |
| 2286 | __ bind(&call_runtime); |
| 2287 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2288 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2289 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2290 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2291 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2293 | case Token::DIV: |
| 2294 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2295 | break; |
| 2296 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2297 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2298 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2299 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2300 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2301 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2302 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | break; |
| 2304 | default: |
| 2305 | UNREACHABLE(); |
| 2306 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2307 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2311 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2312 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2313 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2314 | |
| 2315 | // Registers containing left and right operands respectively. |
| 2316 | Register left = edx; |
| 2317 | Register right = eax; |
| 2318 | |
| 2319 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2320 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2321 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2322 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2323 | |
| 2324 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2325 | GenerateRegisterArgsPush(masm); |
| 2326 | __ TailCallStub(&string_add_left_stub); |
| 2327 | |
| 2328 | // Left operand is not a string, test right. |
| 2329 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2330 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2331 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2332 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2333 | |
| 2334 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2335 | GenerateRegisterArgsPush(masm); |
| 2336 | __ TailCallStub(&string_add_right_stub); |
| 2337 | |
| 2338 | // Neither argument is a string. |
| 2339 | __ bind(&call_runtime); |
| 2340 | } |
| 2341 | |
| 2342 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2343 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2344 | Label* alloc_failure, |
| 2345 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2346 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2347 | switch (mode) { |
| 2348 | case OVERWRITE_LEFT: { |
| 2349 | // If the argument in edx is already an object, we skip the |
| 2350 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2351 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2352 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2353 | // for the possible runtime call. |
| 2354 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2355 | // Now edx can be overwritten losing one of the arguments as we are |
| 2356 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2357 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2358 | __ bind(&skip_allocation); |
| 2359 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2360 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | } |
| 2363 | case OVERWRITE_RIGHT: |
| 2364 | // If the argument in eax is already an object, we skip the |
| 2365 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2366 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2367 | // Fall through! |
| 2368 | case NO_OVERWRITE: |
| 2369 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2370 | // for the possible runtime call. |
| 2371 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2372 | // Now eax can be overwritten losing one of the arguments as we are |
| 2373 | // now done and will not need it any more. |
| 2374 | __ mov(eax, ebx); |
| 2375 | __ bind(&skip_allocation); |
| 2376 | break; |
| 2377 | default: UNREACHABLE(); |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2382 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2383 | __ pop(ecx); |
| 2384 | __ push(edx); |
| 2385 | __ push(eax); |
| 2386 | __ push(ecx); |
| 2387 | } |
| 2388 | |
| 2389 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2390 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2391 | // TAGGED case: |
| 2392 | // Input: |
| 2393 | // esp[4]: tagged number input argument (should be number). |
| 2394 | // esp[0]: return address. |
| 2395 | // Output: |
| 2396 | // eax: tagged double result. |
| 2397 | // UNTAGGED case: |
| 2398 | // Input:: |
| 2399 | // esp[0]: return address. |
| 2400 | // xmm1: untagged double input argument |
| 2401 | // Output: |
| 2402 | // xmm1: untagged double result. |
| 2403 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2404 | Label runtime_call; |
| 2405 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2406 | Label skip_cache; |
| 2407 | const bool tagged = (argument_type_ == TAGGED); |
| 2408 | if (tagged) { |
| 2409 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2410 | Label input_not_smi; |
| 2411 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2412 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2413 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2414 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2415 | // Then load the low and high words of the double into ebx, edx. |
| 2416 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2417 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2418 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2419 | __ mov(Operand(esp, 0), eax); |
| 2420 | __ fild_s(Operand(esp, 0)); |
| 2421 | __ fst_d(Operand(esp, 0)); |
| 2422 | __ pop(edx); |
| 2423 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2424 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2425 | __ bind(&input_not_smi); |
| 2426 | // Check if input is a HeapNumber. |
| 2427 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2428 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2429 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2430 | __ j(not_equal, &runtime_call); |
| 2431 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2432 | // low and high words into ebx, edx. |
| 2433 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2434 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2435 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2436 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2437 | __ bind(&loaded); |
| 2438 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2439 | CpuFeatures::Scope scope(SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2440 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2441 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2442 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2443 | } else { |
| 2444 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2445 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2446 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2447 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | // ebx = low 32 bits of double value |
| 2452 | // edx = high 32 bits of double value |
| 2453 | // Compute hash (the shifts are arithmetic): |
| 2454 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2455 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2456 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2457 | __ mov(eax, ecx); |
| 2458 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2459 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2460 | __ mov(eax, ecx); |
| 2461 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2462 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2463 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2464 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2465 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2466 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2467 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2468 | // ebx = low 32 bits of double value. |
| 2469 | // edx = high 32 bits of double value. |
| 2470 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2471 | ExternalReference cache_array = |
| 2472 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2473 | __ mov(eax, Immediate(cache_array)); |
| 2474 | int cache_array_index = |
| 2475 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2476 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2477 | // Eax points to the cache for the type type_. |
| 2478 | // 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] | 2479 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2480 | __ j(zero, &runtime_call_clear_stack); |
| 2481 | #ifdef DEBUG |
| 2482 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2483 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2484 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2485 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2486 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2487 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2488 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2489 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2490 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2491 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2492 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2493 | } |
| 2494 | #endif |
| 2495 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2496 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2497 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2498 | // 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] | 2499 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2500 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2501 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2502 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2503 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2504 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2505 | Counters* counters = masm->isolate()->counters(); |
| 2506 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2507 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2508 | if (tagged) { |
| 2509 | __ fstp(0); |
| 2510 | __ ret(kPointerSize); |
| 2511 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2512 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2513 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2514 | __ Ret(); |
| 2515 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2516 | |
| 2517 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2518 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2519 | // Update cache with new value. |
| 2520 | // We are short on registers, so use no_reg as scratch. |
| 2521 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2522 | if (tagged) { |
| 2523 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2524 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2525 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2526 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2527 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2528 | __ movdbl(Operand(esp, 0), xmm1); |
| 2529 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2530 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2531 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2532 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2533 | __ mov(Operand(ecx, 0), ebx); |
| 2534 | __ mov(Operand(ecx, kIntSize), edx); |
| 2535 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2536 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2537 | if (tagged) { |
| 2538 | __ ret(kPointerSize); |
| 2539 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2540 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2541 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2542 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2543 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2544 | // Skip cache and return answer directly, only in untagged case. |
| 2545 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2546 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2547 | __ movdbl(Operand(esp, 0), xmm1); |
| 2548 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2549 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2550 | __ fstp_d(Operand(esp, 0)); |
| 2551 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2552 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2553 | // We return the value in xmm1 without adding it to the cache, but |
| 2554 | // 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] | 2555 | { |
| 2556 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2557 | // Allocate an unused object bigger than a HeapNumber. |
| 2558 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2559 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2560 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2561 | __ Ret(); |
| 2562 | } |
| 2563 | |
| 2564 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2565 | if (tagged) { |
| 2566 | __ bind(&runtime_call_clear_stack); |
| 2567 | __ fstp(0); |
| 2568 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2569 | ExternalReference runtime = |
| 2570 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2571 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2572 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2573 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2574 | __ bind(&runtime_call_clear_stack); |
| 2575 | __ bind(&runtime_call); |
| 2576 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2577 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2578 | { |
| 2579 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2580 | __ push(eax); |
| 2581 | __ CallRuntime(RuntimeFunction(), 1); |
| 2582 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2583 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2584 | __ Ret(); |
| 2585 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2590 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2591 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2592 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2593 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2594 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2595 | default: |
| 2596 | UNIMPLEMENTED(); |
| 2597 | return Runtime::kAbort; |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2602 | void TranscendentalCacheStub::GenerateOperation( |
| 2603 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2604 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2605 | // Input value is on FP stack, and also in ebx/edx. |
| 2606 | // Input value is possibly in xmm1. |
| 2607 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2608 | if (type == TranscendentalCache::SIN || |
| 2609 | type == TranscendentalCache::COS || |
| 2610 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2611 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2612 | // return NaN for infinities and NaN. They can share all code except |
| 2613 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2614 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2615 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2616 | // work. We must reduce it to the appropriate range. |
| 2617 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2618 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2619 | int supported_exponent_limit = |
| 2620 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2621 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2622 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2623 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2624 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2625 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2626 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2627 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2628 | __ fstp(0); |
| 2629 | // NaN is represented by 0x7ff8000000000000. |
| 2630 | __ push(Immediate(0x7ff80000)); |
| 2631 | __ push(Immediate(0)); |
| 2632 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2633 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2634 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2635 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2636 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2637 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2638 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2639 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2640 | __ fldpi(); |
| 2641 | __ fadd(0); |
| 2642 | __ fld(1); |
| 2643 | // FPU Stack: input, 2*pi, input. |
| 2644 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2645 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2646 | __ fwait(); |
| 2647 | __ fnstsw_ax(); |
| 2648 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2649 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2650 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2651 | __ fnclex(); |
| 2652 | __ bind(&no_exceptions); |
| 2653 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2654 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2655 | // Compute st(0) % st(1) |
| 2656 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2657 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2658 | __ bind(&partial_remainder_loop); |
| 2659 | __ fprem1(); |
| 2660 | __ fwait(); |
| 2661 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2662 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2663 | // If C2 is set, computation only has partial result. Loop to |
| 2664 | // continue computation. |
| 2665 | __ j(not_zero, &partial_remainder_loop); |
| 2666 | } |
| 2667 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2668 | __ fstp(2); |
| 2669 | __ fstp(0); |
| 2670 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2671 | |
| 2672 | // FPU Stack: input % 2*pi |
| 2673 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2674 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2675 | case TranscendentalCache::SIN: |
| 2676 | __ fsin(); |
| 2677 | break; |
| 2678 | case TranscendentalCache::COS: |
| 2679 | __ fcos(); |
| 2680 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2681 | case TranscendentalCache::TAN: |
| 2682 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2683 | // FP register stack. |
| 2684 | __ fptan(); |
| 2685 | __ fstp(0); // Pop FP register stack. |
| 2686 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2687 | default: |
| 2688 | UNREACHABLE(); |
| 2689 | } |
| 2690 | __ bind(&done); |
| 2691 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2692 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2693 | __ fldln2(); |
| 2694 | __ fxch(); |
| 2695 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2696 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2700 | // Input: edx, eax are the left and right objects of a bit op. |
| 2701 | // 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] | 2702 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2703 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2704 | MacroAssembler* masm, |
| 2705 | bool use_sse3, |
| 2706 | BinaryOpIC::TypeInfo left_type, |
| 2707 | BinaryOpIC::TypeInfo right_type, |
| 2708 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2709 | // Check float operands. |
| 2710 | Label arg1_is_object, check_undefined_arg1; |
| 2711 | Label arg2_is_object, check_undefined_arg2; |
| 2712 | Label load_arg2, done; |
| 2713 | |
| 2714 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2715 | if (left_type == BinaryOpIC::SMI) { |
| 2716 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2717 | } else { |
| 2718 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2719 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2720 | |
| 2721 | __ SmiUntag(edx); |
| 2722 | __ jmp(&load_arg2); |
| 2723 | |
| 2724 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2725 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2726 | Factory* factory = masm->isolate()->factory(); |
| 2727 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2728 | __ j(not_equal, conversion_failure); |
| 2729 | __ mov(edx, Immediate(0)); |
| 2730 | __ jmp(&load_arg2); |
| 2731 | |
| 2732 | __ bind(&arg1_is_object); |
| 2733 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2734 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2735 | __ j(not_equal, &check_undefined_arg1); |
| 2736 | |
| 2737 | // 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] | 2738 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2739 | CpuFeatures::Scope use_sse2(SSE2); |
| 2740 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2741 | } else { |
| 2742 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2743 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2744 | __ mov(edx, ecx); |
| 2745 | |
| 2746 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2747 | __ bind(&load_arg2); |
| 2748 | |
| 2749 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2750 | if (right_type == BinaryOpIC::SMI) { |
| 2751 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2752 | } else { |
| 2753 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2754 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2755 | |
| 2756 | __ SmiUntag(eax); |
| 2757 | __ mov(ecx, eax); |
| 2758 | __ jmp(&done); |
| 2759 | |
| 2760 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2761 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2762 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2763 | __ j(not_equal, conversion_failure); |
| 2764 | __ mov(ecx, Immediate(0)); |
| 2765 | __ jmp(&done); |
| 2766 | |
| 2767 | __ bind(&arg2_is_object); |
| 2768 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2769 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2770 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2771 | // 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] | 2772 | |
| 2773 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2774 | CpuFeatures::Scope use_sse2(SSE2); |
| 2775 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2776 | } else { |
| 2777 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2778 | } |
| 2779 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2780 | __ bind(&done); |
| 2781 | __ mov(eax, edx); |
| 2782 | } |
| 2783 | |
| 2784 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2785 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2786 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2787 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2788 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2789 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2790 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2791 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2792 | |
| 2793 | __ bind(&load_smi); |
| 2794 | __ SmiUntag(number); |
| 2795 | __ push(number); |
| 2796 | __ fild_s(Operand(esp, 0)); |
| 2797 | __ pop(number); |
| 2798 | |
| 2799 | __ bind(&done); |
| 2800 | } |
| 2801 | |
| 2802 | |
| 2803 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2804 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2805 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2806 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2807 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2808 | |
| 2809 | __ bind(&load_eax); |
| 2810 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2811 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2812 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2813 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2814 | |
| 2815 | __ bind(&load_smi_edx); |
| 2816 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2817 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2818 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2819 | __ jmp(&load_eax); |
| 2820 | |
| 2821 | __ bind(&load_smi_eax); |
| 2822 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2823 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2825 | |
| 2826 | __ bind(&done); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2831 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2832 | 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] | 2833 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2834 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2835 | Factory* factory = masm->isolate()->factory(); |
| 2836 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2837 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2838 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2839 | __ bind(&load_eax); |
| 2840 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2841 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2842 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2843 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2844 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2845 | __ bind(&load_smi_edx); |
| 2846 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2847 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2848 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2849 | __ jmp(&load_eax); |
| 2850 | __ bind(&load_smi_eax); |
| 2851 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2852 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2853 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2854 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2855 | __ bind(&load_float_eax); |
| 2856 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2857 | __ bind(&done); |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2862 | Register scratch) { |
| 2863 | const Register left = edx; |
| 2864 | const Register right = eax; |
| 2865 | __ mov(scratch, left); |
| 2866 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2867 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2868 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2869 | |
| 2870 | __ mov(scratch, right); |
| 2871 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2872 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2876 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2877 | Label* non_int32, |
| 2878 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2879 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2880 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | |
| 2884 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2885 | Label* non_int32, |
| 2886 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2887 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2888 | Register scratch, |
| 2889 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2890 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2891 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2892 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2893 | __ movmskps(scratch, xmm_scratch); |
| 2894 | // Two least significant bits should be both set. |
| 2895 | __ not_(scratch); |
| 2896 | __ test(scratch, Immediate(3)); |
| 2897 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2901 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2902 | Register scratch, |
| 2903 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2904 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2905 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2906 | __ mov(scratch, edx); |
| 2907 | } else { |
| 2908 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2909 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2910 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2911 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2912 | __ bind(&done_load_1); |
| 2913 | |
| 2914 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2915 | __ mov(scratch, eax); |
| 2916 | } else { |
| 2917 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2918 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2919 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2920 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2921 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2922 | |
| 2923 | __ bind(&load_smi_1); |
| 2924 | __ SmiUntag(scratch); |
| 2925 | __ push(scratch); |
| 2926 | __ fild_s(Operand(esp, 0)); |
| 2927 | __ pop(scratch); |
| 2928 | __ jmp(&done_load_1); |
| 2929 | |
| 2930 | __ bind(&load_smi_2); |
| 2931 | __ SmiUntag(scratch); |
| 2932 | __ push(scratch); |
| 2933 | __ fild_s(Operand(esp, 0)); |
| 2934 | __ pop(scratch); |
| 2935 | |
| 2936 | __ bind(&done); |
| 2937 | } |
| 2938 | |
| 2939 | |
| 2940 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2941 | Register scratch) { |
| 2942 | const Register left = edx; |
| 2943 | const Register right = eax; |
| 2944 | __ mov(scratch, left); |
| 2945 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2946 | __ SmiUntag(scratch); |
| 2947 | __ push(scratch); |
| 2948 | __ fild_s(Operand(esp, 0)); |
| 2949 | |
| 2950 | __ mov(scratch, right); |
| 2951 | __ SmiUntag(scratch); |
| 2952 | __ mov(Operand(esp, 0), scratch); |
| 2953 | __ fild_s(Operand(esp, 0)); |
| 2954 | __ pop(scratch); |
| 2955 | } |
| 2956 | |
| 2957 | |
| 2958 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2959 | Label* non_float, |
| 2960 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2961 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2962 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2963 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2964 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2965 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2966 | Factory* factory = masm->isolate()->factory(); |
| 2967 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2968 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2969 | |
| 2970 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2971 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2972 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2973 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2974 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2975 | |
| 2976 | // Fall-through: Both operands are numbers. |
| 2977 | __ bind(&done); |
| 2978 | } |
| 2979 | |
| 2980 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2981 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2982 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2983 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2984 | const Register exponent = eax; |
| 2985 | const Register base = edx; |
| 2986 | const Register scratch = ecx; |
| 2987 | const XMMRegister double_result = xmm3; |
| 2988 | const XMMRegister double_base = xmm2; |
| 2989 | const XMMRegister double_exponent = xmm1; |
| 2990 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2991 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2992 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2993 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2994 | // Save 1 in double_result - we need this several times later on. |
| 2995 | __ mov(scratch, Immediate(1)); |
| 2996 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2997 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2998 | if (exponent_type_ == ON_STACK) { |
| 2999 | Label base_is_smi, unpack_exponent; |
| 3000 | // The exponent and base are supplied as arguments on the stack. |
| 3001 | // This can only happen if the stub is called from non-optimized code. |
| 3002 | // Load input parameters from stack. |
| 3003 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3004 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3005 | |
| 3006 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3007 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3008 | factory->heap_number_map()); |
| 3009 | __ j(not_equal, &call_runtime); |
| 3010 | |
| 3011 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3012 | __ jmp(&unpack_exponent, Label::kNear); |
| 3013 | |
| 3014 | __ bind(&base_is_smi); |
| 3015 | __ SmiUntag(base); |
| 3016 | __ cvtsi2sd(double_base, base); |
| 3017 | |
| 3018 | __ bind(&unpack_exponent); |
| 3019 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3020 | __ SmiUntag(exponent); |
| 3021 | __ jmp(&int_exponent); |
| 3022 | |
| 3023 | __ bind(&exponent_not_smi); |
| 3024 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3025 | factory->heap_number_map()); |
| 3026 | __ j(not_equal, &call_runtime); |
| 3027 | __ movdbl(double_exponent, |
| 3028 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3029 | } else if (exponent_type_ == TAGGED) { |
| 3030 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3031 | __ SmiUntag(exponent); |
| 3032 | __ jmp(&int_exponent); |
| 3033 | |
| 3034 | __ bind(&exponent_not_smi); |
| 3035 | __ movdbl(double_exponent, |
| 3036 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3037 | } |
| 3038 | |
| 3039 | if (exponent_type_ != INTEGER) { |
| 3040 | Label fast_power; |
| 3041 | // Detect integer exponents stored as double. |
| 3042 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3043 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3044 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3045 | __ j(equal, &call_runtime); |
| 3046 | __ cvtsi2sd(double_scratch, exponent); |
| 3047 | // Already ruled out NaNs for exponent. |
| 3048 | __ ucomisd(double_exponent, double_scratch); |
| 3049 | __ j(equal, &int_exponent); |
| 3050 | |
| 3051 | if (exponent_type_ == ON_STACK) { |
| 3052 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3053 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3054 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3055 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3056 | // Test for 0.5. |
| 3057 | // Load double_scratch with 0.5. |
| 3058 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3059 | __ movd(double_scratch, scratch); |
| 3060 | __ cvtss2sd(double_scratch, double_scratch); |
| 3061 | // Already ruled out NaNs for exponent. |
| 3062 | __ ucomisd(double_scratch, double_exponent); |
| 3063 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3064 | |
| 3065 | // Calculates square root of base. Check for the special case of |
| 3066 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3067 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3068 | // 9 bits set and the lowest 23 bits cleared. |
| 3069 | __ mov(scratch, 0xFF800000u); |
| 3070 | __ movd(double_scratch, scratch); |
| 3071 | __ cvtss2sd(double_scratch, double_scratch); |
| 3072 | __ ucomisd(double_base, double_scratch); |
| 3073 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3074 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3075 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3076 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3077 | |
| 3078 | // Set result to Infinity in the special case. |
| 3079 | __ xorps(double_result, double_result); |
| 3080 | __ subsd(double_result, double_scratch); |
| 3081 | __ jmp(&done); |
| 3082 | |
| 3083 | __ bind(&continue_sqrt); |
| 3084 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3085 | __ xorps(double_scratch, double_scratch); |
| 3086 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3087 | __ sqrtsd(double_result, double_scratch); |
| 3088 | __ jmp(&done); |
| 3089 | |
| 3090 | // Test for -0.5. |
| 3091 | __ bind(¬_plus_half); |
| 3092 | // Load double_exponent with -0.5 by substracting 1. |
| 3093 | __ subsd(double_scratch, double_result); |
| 3094 | // Already ruled out NaNs for exponent. |
| 3095 | __ ucomisd(double_scratch, double_exponent); |
| 3096 | __ j(not_equal, &fast_power, Label::kNear); |
| 3097 | |
| 3098 | // Calculates reciprocal of square root of base. Check for the special |
| 3099 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3100 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3101 | // 9 bits set and the lowest 23 bits cleared. |
| 3102 | __ mov(scratch, 0xFF800000u); |
| 3103 | __ movd(double_scratch, scratch); |
| 3104 | __ cvtss2sd(double_scratch, double_scratch); |
| 3105 | __ ucomisd(double_base, double_scratch); |
| 3106 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3107 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3108 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3109 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3110 | |
| 3111 | // Set result to 0 in the special case. |
| 3112 | __ xorps(double_result, double_result); |
| 3113 | __ jmp(&done); |
| 3114 | |
| 3115 | __ bind(&continue_rsqrt); |
| 3116 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3117 | __ xorps(double_exponent, double_exponent); |
| 3118 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3119 | __ sqrtsd(double_exponent, double_exponent); |
| 3120 | __ divsd(double_result, double_exponent); |
| 3121 | __ jmp(&done); |
| 3122 | } |
| 3123 | |
| 3124 | // Using FPU instructions to calculate power. |
| 3125 | Label fast_power_failed; |
| 3126 | __ bind(&fast_power); |
| 3127 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3128 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3129 | __ sub(esp, Immediate(kDoubleSize)); |
| 3130 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3131 | __ fld_d(Operand(esp, 0)); // E |
| 3132 | __ movdbl(Operand(esp, 0), double_base); |
| 3133 | __ fld_d(Operand(esp, 0)); // B, E |
| 3134 | |
| 3135 | // Exponent is in st(1) and base is in st(0) |
| 3136 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3137 | // FYL2X calculates st(1) * log2(st(0)) |
| 3138 | __ fyl2x(); // X |
| 3139 | __ fld(0); // X, X |
| 3140 | __ frndint(); // rnd(X), X |
| 3141 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3142 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3143 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3144 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3145 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3146 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3147 | // FSCALE calculates st(0) * 2^st(1) |
| 3148 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3149 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3150 | // Bail out to runtime in case of exceptions in the status word. |
| 3151 | __ fnstsw_ax(); |
| 3152 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3153 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3154 | __ fstp_d(Operand(esp, 0)); |
| 3155 | __ movdbl(double_result, Operand(esp, 0)); |
| 3156 | __ add(esp, Immediate(kDoubleSize)); |
| 3157 | __ jmp(&done); |
| 3158 | |
| 3159 | __ bind(&fast_power_failed); |
| 3160 | __ fninit(); |
| 3161 | __ add(esp, Immediate(kDoubleSize)); |
| 3162 | __ jmp(&call_runtime); |
| 3163 | } |
| 3164 | |
| 3165 | // Calculate power with integer exponent. |
| 3166 | __ bind(&int_exponent); |
| 3167 | const XMMRegister double_scratch2 = double_exponent; |
| 3168 | __ mov(scratch, exponent); // Back up exponent. |
| 3169 | __ movsd(double_scratch, double_base); // Back up base. |
| 3170 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3171 | |
| 3172 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3173 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3174 | __ test(scratch, scratch); |
| 3175 | __ j(positive, &no_neg, Label::kNear); |
| 3176 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3177 | __ bind(&no_neg); |
| 3178 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3179 | __ j(zero, &while_false, Label::kNear); |
| 3180 | __ shr(scratch, 1); |
| 3181 | // Above condition means CF==0 && ZF==0. This means that the |
| 3182 | // bit that has been shifted out is 0 and the result is not 0. |
| 3183 | __ j(above, &while_true, Label::kNear); |
| 3184 | __ movsd(double_result, double_scratch); |
| 3185 | __ j(zero, &while_false, Label::kNear); |
| 3186 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3187 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3188 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3189 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3190 | __ j(above, &while_true, Label::kNear); |
| 3191 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3192 | __ j(not_zero, &while_true); |
| 3193 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3194 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3195 | // scratch has the original value of the exponent - if the exponent is |
| 3196 | // negative, return 1/result. |
| 3197 | __ test(exponent, exponent); |
| 3198 | __ j(positive, &done); |
| 3199 | __ divsd(double_scratch2, double_result); |
| 3200 | __ movsd(double_result, double_scratch2); |
| 3201 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3202 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3203 | __ xorps(double_scratch2, double_scratch2); |
| 3204 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3205 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3206 | // and may not have contained the exponent value in the first place when the |
| 3207 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3208 | __ j(not_equal, &done); |
| 3209 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3210 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3211 | // Returning or bailing out. |
| 3212 | Counters* counters = masm->isolate()->counters(); |
| 3213 | if (exponent_type_ == ON_STACK) { |
| 3214 | // The arguments are still on the stack. |
| 3215 | __ bind(&call_runtime); |
| 3216 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3217 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3218 | // The stub is called from non-optimized code, which expects the result |
| 3219 | // as heap number in exponent. |
| 3220 | __ bind(&done); |
| 3221 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3222 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3223 | __ IncrementCounter(counters->math_pow(), 1); |
| 3224 | __ ret(2 * kPointerSize); |
| 3225 | } else { |
| 3226 | __ bind(&call_runtime); |
| 3227 | { |
| 3228 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3229 | __ PrepareCallCFunction(4, scratch); |
| 3230 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3231 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3232 | __ CallCFunction( |
| 3233 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3234 | } |
| 3235 | // Return value is in st(0) on ia32. |
| 3236 | // Store it into the (fixed) result register. |
| 3237 | __ sub(esp, Immediate(kDoubleSize)); |
| 3238 | __ fstp_d(Operand(esp, 0)); |
| 3239 | __ movdbl(double_result, Operand(esp, 0)); |
| 3240 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3241 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3242 | __ bind(&done); |
| 3243 | __ IncrementCounter(counters->math_pow(), 1); |
| 3244 | __ ret(0); |
| 3245 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3249 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3250 | // ----------- S t a t e ------------- |
| 3251 | // -- ecx : name |
| 3252 | // -- edx : receiver |
| 3253 | // -- esp[0] : return address |
| 3254 | // ----------------------------------- |
| 3255 | Label miss; |
| 3256 | |
| 3257 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3258 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3259 | __ j(not_equal, &miss); |
| 3260 | } |
| 3261 | |
| 3262 | StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss); |
| 3263 | __ bind(&miss); |
| 3264 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3265 | } |
| 3266 | |
| 3267 | |
| 3268 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3269 | // ----------- S t a t e ------------- |
| 3270 | // -- ecx : name |
| 3271 | // -- edx : receiver |
| 3272 | // -- esp[0] : return address |
| 3273 | // ----------------------------------- |
| 3274 | Label miss; |
| 3275 | |
| 3276 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3277 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_symbol())); |
| 3278 | __ j(not_equal, &miss); |
| 3279 | } |
| 3280 | |
| 3281 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3282 | __ bind(&miss); |
| 3283 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3284 | } |
| 3285 | |
| 3286 | |
| 3287 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3288 | // ----------- S t a t e ------------- |
| 3289 | // -- ecx : name |
| 3290 | // -- edx : receiver |
| 3291 | // -- esp[0] : return address |
| 3292 | // ----------------------------------- |
| 3293 | Label miss; |
| 3294 | |
| 3295 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3296 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3297 | __ j(not_equal, &miss); |
| 3298 | } |
| 3299 | |
| 3300 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3301 | support_wrapper_); |
| 3302 | __ bind(&miss); |
| 3303 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3304 | } |
| 3305 | |
| 3306 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3307 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3308 | // ----------- S t a t e ------------- |
| 3309 | // -- eax : value |
| 3310 | // -- ecx : name |
| 3311 | // -- edx : receiver |
| 3312 | // -- esp[0] : return address |
| 3313 | // ----------------------------------- |
| 3314 | // |
| 3315 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3316 | // (currently anything except for external arrays which means anything with |
| 3317 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3318 | // accepted as the most common case. |
| 3319 | |
| 3320 | Label miss; |
| 3321 | |
| 3322 | Register receiver = edx; |
| 3323 | Register value = eax; |
| 3324 | Register scratch = ebx; |
| 3325 | |
| 3326 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3327 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3328 | __ j(not_equal, &miss); |
| 3329 | } |
| 3330 | |
| 3331 | // Check that the receiver isn't a smi. |
| 3332 | __ JumpIfSmi(receiver, &miss); |
| 3333 | |
| 3334 | // Check that the object is a JS array. |
| 3335 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3336 | __ j(not_equal, &miss); |
| 3337 | |
| 3338 | // Check that elements are FixedArray. |
| 3339 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3340 | // fast elements (including COW). |
| 3341 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3342 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3343 | __ j(not_equal, &miss); |
| 3344 | |
| 3345 | // Check that the array has fast properties, otherwise the length |
| 3346 | // property might have been redefined. |
| 3347 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3348 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3349 | Heap::kHashTableMapRootIndex); |
| 3350 | __ j(equal, &miss); |
| 3351 | |
| 3352 | // Check that value is a smi. |
| 3353 | __ JumpIfNotSmi(value, &miss); |
| 3354 | |
| 3355 | // Prepare tail call to StoreIC_ArrayLength. |
| 3356 | __ pop(scratch); |
| 3357 | __ push(receiver); |
| 3358 | __ push(value); |
| 3359 | __ push(scratch); // return address |
| 3360 | |
| 3361 | ExternalReference ref = |
| 3362 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3363 | __ TailCallExternalReference(ref, 2, 1); |
| 3364 | |
| 3365 | __ bind(&miss); |
| 3366 | |
| 3367 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 3368 | } |
| 3369 | |
| 3370 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3371 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3372 | // The key is in edx and the parameter count is in eax. |
| 3373 | |
| 3374 | // The displacement is used for skipping the frame pointer on the |
| 3375 | // stack. It is the offset of the last parameter (if any) relative |
| 3376 | // to the frame pointer. |
| 3377 | static const int kDisplacement = 1 * kPointerSize; |
| 3378 | |
| 3379 | // Check that the key is a smi. |
| 3380 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3381 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3382 | |
| 3383 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3384 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3385 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3386 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3387 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3388 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3389 | |
| 3390 | // Check index against formal parameters count limit passed in |
| 3391 | // through register eax. Use unsigned comparison to get negative |
| 3392 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3393 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3394 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3395 | |
| 3396 | // Read the argument from the stack and return it. |
| 3397 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3398 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3399 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3400 | __ neg(edx); |
| 3401 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3402 | __ ret(0); |
| 3403 | |
| 3404 | // Arguments adaptor case: Check index against actual arguments |
| 3405 | // limit found in the arguments adaptor frame. Use unsigned |
| 3406 | // comparison to get negative check for free. |
| 3407 | __ bind(&adaptor); |
| 3408 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3409 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3410 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3411 | |
| 3412 | // Read the argument from the stack and return it. |
| 3413 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3414 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3415 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3416 | __ neg(edx); |
| 3417 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3418 | __ ret(0); |
| 3419 | |
| 3420 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3421 | // by calling the runtime system. |
| 3422 | __ bind(&slow); |
| 3423 | __ pop(ebx); // Return address. |
| 3424 | __ push(edx); |
| 3425 | __ push(ebx); |
| 3426 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3427 | } |
| 3428 | |
| 3429 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3430 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3431 | // esp[0] : return address |
| 3432 | // esp[4] : number of parameters |
| 3433 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3434 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3435 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3436 | // Check if the calling frame is an arguments adaptor frame. |
| 3437 | Label runtime; |
| 3438 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3439 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3440 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3441 | __ j(not_equal, &runtime, Label::kNear); |
| 3442 | |
| 3443 | // Patch the arguments.length and the parameters pointer. |
| 3444 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3445 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3446 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3447 | StandardFrameConstants::kCallerSPOffset)); |
| 3448 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3449 | |
| 3450 | __ bind(&runtime); |
| 3451 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3452 | } |
| 3453 | |
| 3454 | |
| 3455 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3456 | // esp[0] : return address |
| 3457 | // esp[4] : number of parameters (tagged) |
| 3458 | // esp[8] : receiver displacement |
| 3459 | // esp[12] : function |
| 3460 | |
| 3461 | // ebx = parameter count (tagged) |
| 3462 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3463 | |
| 3464 | // Check if the calling frame is an arguments adaptor frame. |
| 3465 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3466 | // Generate* functions. |
| 3467 | Label runtime; |
| 3468 | Label adaptor_frame, try_allocate; |
| 3469 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3470 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3471 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3472 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3473 | |
| 3474 | // No adaptor, parameter count = argument count. |
| 3475 | __ mov(ecx, ebx); |
| 3476 | __ jmp(&try_allocate, Label::kNear); |
| 3477 | |
| 3478 | // We have an adaptor frame. Patch the parameters pointer. |
| 3479 | __ bind(&adaptor_frame); |
| 3480 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3481 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3482 | StandardFrameConstants::kCallerSPOffset)); |
| 3483 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3484 | |
| 3485 | // ebx = parameter count (tagged) |
| 3486 | // ecx = argument count (tagged) |
| 3487 | // esp[4] = parameter count (tagged) |
| 3488 | // esp[8] = address of receiver argument |
| 3489 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3490 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3491 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3492 | __ mov(ebx, ecx); |
| 3493 | |
| 3494 | __ bind(&try_allocate); |
| 3495 | |
| 3496 | // Save mapped parameter count. |
| 3497 | __ push(ebx); |
| 3498 | |
| 3499 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3500 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3501 | const int kParameterMapHeaderSize = |
| 3502 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3503 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3504 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3505 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3506 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3507 | __ bind(&no_parameter_map); |
| 3508 | |
| 3509 | // 2. Backing store. |
| 3510 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3511 | |
| 3512 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3513 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3514 | |
| 3515 | // Do the allocation of all three objects in one go. |
| 3516 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3517 | |
| 3518 | // eax = address of new object(s) (tagged) |
| 3519 | // ecx = argument count (tagged) |
| 3520 | // esp[0] = mapped parameter count (tagged) |
| 3521 | // esp[8] = parameter count (tagged) |
| 3522 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3523 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3524 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3525 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3526 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3527 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3528 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3529 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3530 | __ mov(edi, Operand(edi, |
| 3531 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3532 | __ jmp(©, Label::kNear); |
| 3533 | |
| 3534 | __ bind(&has_mapped_parameters); |
| 3535 | __ mov(edi, Operand(edi, |
| 3536 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3537 | __ bind(©); |
| 3538 | |
| 3539 | // eax = address of new object (tagged) |
| 3540 | // ebx = mapped parameter count (tagged) |
| 3541 | // ecx = argument count (tagged) |
| 3542 | // edi = address of boilerplate object (tagged) |
| 3543 | // esp[0] = mapped parameter count (tagged) |
| 3544 | // esp[8] = parameter count (tagged) |
| 3545 | // esp[12] = address of receiver argument |
| 3546 | // Copy the JS object part. |
| 3547 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3548 | __ mov(edx, FieldOperand(edi, i)); |
| 3549 | __ mov(FieldOperand(eax, i), edx); |
| 3550 | } |
| 3551 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3552 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3553 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3554 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3555 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3556 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3557 | edx); |
| 3558 | |
| 3559 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3560 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3561 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3562 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3563 | ecx); |
| 3564 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3565 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3566 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3567 | // backing store. |
| 3568 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3569 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3570 | |
| 3571 | // eax = address of new object (tagged) |
| 3572 | // ebx = mapped parameter count (tagged) |
| 3573 | // ecx = argument count (tagged) |
| 3574 | // edi = address of parameter map or backing store (tagged) |
| 3575 | // esp[0] = mapped parameter count (tagged) |
| 3576 | // esp[8] = parameter count (tagged) |
| 3577 | // esp[12] = address of receiver argument |
| 3578 | // Free a register. |
| 3579 | __ push(eax); |
| 3580 | |
| 3581 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3582 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3583 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3584 | __ j(zero, &skip_parameter_map); |
| 3585 | |
| 3586 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3587 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3588 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3589 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3590 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3591 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3592 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3593 | |
| 3594 | // Copy the parameter slots and the holes in the arguments. |
| 3595 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3596 | // where parameters are stored in reverse order, at |
| 3597 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3598 | // The mapped parameter thus need to get indices |
| 3599 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3600 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3601 | // We loop from right to left. |
| 3602 | Label parameters_loop, parameters_test; |
| 3603 | __ push(ecx); |
| 3604 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3605 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3606 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3607 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3608 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3609 | __ mov(edx, edi); |
| 3610 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3611 | // eax = loop variable (tagged) |
| 3612 | // ebx = mapping index (tagged) |
| 3613 | // ecx = the hole value |
| 3614 | // edx = address of parameter map (tagged) |
| 3615 | // edi = address of backing store (tagged) |
| 3616 | // esp[0] = argument count (tagged) |
| 3617 | // esp[4] = address of new object (tagged) |
| 3618 | // esp[8] = mapped parameter count (tagged) |
| 3619 | // esp[16] = parameter count (tagged) |
| 3620 | // esp[20] = address of receiver argument |
| 3621 | __ jmp(¶meters_test, Label::kNear); |
| 3622 | |
| 3623 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3624 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3625 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3626 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3627 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3628 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3629 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3630 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3631 | __ pop(ecx); |
| 3632 | |
| 3633 | __ bind(&skip_parameter_map); |
| 3634 | |
| 3635 | // ecx = argument count (tagged) |
| 3636 | // edi = address of backing store (tagged) |
| 3637 | // esp[0] = address of new object (tagged) |
| 3638 | // esp[4] = mapped parameter count (tagged) |
| 3639 | // esp[12] = parameter count (tagged) |
| 3640 | // esp[16] = address of receiver argument |
| 3641 | // Copy arguments header and remaining slots (if there are any). |
| 3642 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3643 | Immediate(FACTORY->fixed_array_map())); |
| 3644 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3645 | |
| 3646 | Label arguments_loop, arguments_test; |
| 3647 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3648 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3649 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3650 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3651 | __ jmp(&arguments_test, Label::kNear); |
| 3652 | |
| 3653 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3654 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3655 | __ mov(eax, Operand(edx, 0)); |
| 3656 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3657 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3658 | |
| 3659 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3660 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3661 | __ j(less, &arguments_loop, Label::kNear); |
| 3662 | |
| 3663 | // Restore. |
| 3664 | __ pop(eax); // Address of arguments object. |
| 3665 | __ pop(ebx); // Parameter count. |
| 3666 | |
| 3667 | // Return and remove the on-stack parameters. |
| 3668 | __ ret(3 * kPointerSize); |
| 3669 | |
| 3670 | // Do the runtime call to allocate the arguments object. |
| 3671 | __ bind(&runtime); |
| 3672 | __ pop(eax); // Remove saved parameter count. |
| 3673 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3674 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | |
| 3678 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3679 | // esp[0] : return address |
| 3680 | // esp[4] : number of parameters |
| 3681 | // esp[8] : receiver displacement |
| 3682 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3683 | |
| 3684 | // Check if the calling frame is an arguments adaptor frame. |
| 3685 | Label adaptor_frame, try_allocate, runtime; |
| 3686 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3687 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3688 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3689 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3690 | |
| 3691 | // Get the length from the frame. |
| 3692 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3693 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3694 | |
| 3695 | // Patch the arguments.length and the parameters pointer. |
| 3696 | __ bind(&adaptor_frame); |
| 3697 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3698 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3699 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3700 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3701 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3702 | |
| 3703 | // Try the new space allocation. Start out with computing the size of |
| 3704 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3705 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3706 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3707 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3708 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3709 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3710 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3711 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3712 | |
| 3713 | // Do the allocation of both objects in one go. |
| 3714 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3715 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3716 | // Get the arguments boilerplate from the current native context. |
| 3717 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3718 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3719 | const int offset = |
| 3720 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3721 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3722 | |
| 3723 | // Copy the JS object part. |
| 3724 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3725 | __ mov(ebx, FieldOperand(edi, i)); |
| 3726 | __ mov(FieldOperand(eax, i), ebx); |
| 3727 | } |
| 3728 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3729 | // 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] | 3730 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3731 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3732 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3733 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3734 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3735 | |
| 3736 | // If there are no actual arguments, we're done. |
| 3737 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3738 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3739 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3740 | |
| 3741 | // Get the parameters pointer from the stack. |
| 3742 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3743 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3744 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3745 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3746 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3747 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3748 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3749 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3750 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3751 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3752 | // Untag the length for the loop below. |
| 3753 | __ SmiUntag(ecx); |
| 3754 | |
| 3755 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3756 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3757 | __ bind(&loop); |
| 3758 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3759 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3760 | __ add(edi, Immediate(kPointerSize)); |
| 3761 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3762 | __ dec(ecx); |
| 3763 | __ j(not_zero, &loop); |
| 3764 | |
| 3765 | // Return and remove the on-stack parameters. |
| 3766 | __ bind(&done); |
| 3767 | __ ret(3 * kPointerSize); |
| 3768 | |
| 3769 | // Do the runtime call to allocate the arguments object. |
| 3770 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3771 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3776 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3777 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3778 | // at compilation. |
| 3779 | #ifdef V8_INTERPRETED_REGEXP |
| 3780 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3781 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3782 | |
| 3783 | // Stack frame on entry. |
| 3784 | // esp[0]: return address |
| 3785 | // esp[4]: last_match_info (expected JSArray) |
| 3786 | // esp[8]: previous index |
| 3787 | // esp[12]: subject string |
| 3788 | // esp[16]: JSRegExp object |
| 3789 | |
| 3790 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3791 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3792 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3793 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3794 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3795 | Label runtime; |
| 3796 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3797 | |
| 3798 | // Ensure that a RegExp stack is allocated. |
| 3799 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3800 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3801 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3802 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3803 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3804 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3805 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3806 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3807 | |
| 3808 | // Check that the first argument is a JSRegExp object. |
| 3809 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3810 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3811 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3812 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3813 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3814 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3815 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3816 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3817 | if (FLAG_debug_code) { |
| 3818 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3819 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3820 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3821 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3822 | } |
| 3823 | |
| 3824 | // ecx: RegExp data (FixedArray) |
| 3825 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3826 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3827 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3828 | __ j(not_equal, &runtime); |
| 3829 | |
| 3830 | // ecx: RegExp data (FixedArray) |
| 3831 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3832 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3833 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3834 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3835 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3836 | STATIC_ASSERT(kSmiTag == 0); |
| 3837 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3838 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3839 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3840 | __ j(above, &runtime); |
| 3841 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3842 | // Reset offset for possibly sliced string. |
| 3843 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3844 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3845 | __ JumpIfSmi(eax, &runtime); |
| 3846 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3847 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3848 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3849 | |
| 3850 | // eax: subject string |
| 3851 | // edx: subject string |
| 3852 | // ebx: subject string instance type |
| 3853 | // ecx: RegExp data (FixedArray) |
| 3854 | // Handle subject string according to its encoding and representation: |
| 3855 | // (1) Sequential two byte? If yes, go to (9). |
| 3856 | // (2) Sequential one byte? If yes, go to (6). |
| 3857 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3858 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3859 | // Otherwise bailout. |
| 3860 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3861 | // (5b) Is subject external? If yes, go to (8). |
| 3862 | // (6) One byte sequential. Load regexp code for one byte. |
| 3863 | // (E) Carry on. |
| 3864 | /// [...] |
| 3865 | |
| 3866 | // Deferred code at the end of the stub: |
| 3867 | // (7) Not a long external string? If yes, go to (10). |
| 3868 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3869 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3870 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3871 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3872 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3873 | |
| 3874 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3875 | external_string /* 8 */, check_underlying /* 5a */, |
| 3876 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3877 | not_long_external /* 10 */; |
| 3878 | |
| 3879 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3880 | __ and_(ebx, kIsNotStringMask | |
| 3881 | kStringRepresentationMask | |
| 3882 | kStringEncodingMask | |
| 3883 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3884 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3885 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3886 | |
| 3887 | // (2) Sequential one byte? If yes, go to (6). |
| 3888 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3889 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3890 | kStringRepresentationMask | |
| 3891 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3892 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3893 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3894 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3895 | // We check whether the subject string is a cons, since sequential strings |
| 3896 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3897 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3898 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3899 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3900 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3901 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3902 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3903 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3904 | // (4) Cons string. Check that it's flat. |
| 3905 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3906 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | __ j(not_equal, &runtime); |
| 3908 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3909 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3910 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3911 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3912 | |
| 3913 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3914 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3915 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3916 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3917 | // (5b) Is subject external? If yes, go to (8). |
| 3918 | __ test_b(ebx, kStringRepresentationMask); |
| 3919 | // The underlying external string is never a short external string. |
| 3920 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3921 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3922 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3923 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3924 | // eax: sequential subject string (or look-alike, external string) |
| 3925 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3926 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3927 | // (6) One byte sequential. Load regexp code for one byte. |
| 3928 | __ bind(&seq_one_byte_string); |
| 3929 | // Load previous index and check range before edx is overwritten. We have |
| 3930 | // to use edx instead of eax here because it might have been only made to |
| 3931 | // look like a sequential string when it actually is an external string. |
| 3932 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3933 | __ JumpIfNotSmi(ebx, &runtime); |
| 3934 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3935 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3936 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3937 | __ Set(ecx, Immediate(1)); // Type is one byte. |
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 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3940 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3941 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3942 | // Check that the irregexp code has been generated for the actual string |
| 3943 | // 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] | 3944 | // a smi (code flushing support). |
| 3945 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3946 | |
| 3947 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3948 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3949 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3950 | // 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] | 3951 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3952 | Counters* counters = masm->isolate()->counters(); |
| 3953 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3954 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3955 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3956 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3957 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3958 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3959 | // Argument 9: Pass current isolate address. |
| 3960 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3961 | Immediate(ExternalReference::isolate_address())); |
| 3962 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3963 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3964 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3965 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3966 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3967 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3968 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3969 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3970 | |
| 3971 | // Argument 6: Set the number of capture registers to zero to force global |
| 3972 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3973 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3974 | |
| 3975 | // Argument 5: static offsets vector buffer. |
| 3976 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3977 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3978 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3979 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3980 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3981 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3982 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3983 | |
| 3984 | // Argument 1: Original subject string. |
| 3985 | // The original subject is in the previous stack frame. Therefore we have to |
| 3986 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3987 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3988 | // and thereby moves up esp by one kPointerSize.) |
| 3989 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3990 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3991 | |
| 3992 | // esi: original subject string |
| 3993 | // eax: underlying subject string |
| 3994 | // ebx: previous index |
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 | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3996 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3997 | // Argument 4: End of string data |
| 3998 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3999 | // Prepare start and end index of the input. |
| 4000 | // Load the length from the original sliced string if that is the case. |
| 4001 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4002 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4003 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4004 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4005 | |
| 4006 | // ebx: start index of the input string |
| 4007 | // esi: end index of the input string |
| 4008 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4009 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4010 | __ j(zero, &setup_two_byte, Label::kNear); |
| 4011 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4012 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4013 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4014 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4015 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4016 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4017 | |
| 4018 | __ bind(&setup_two_byte); |
| 4019 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4020 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 4021 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4022 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 4023 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 4024 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 4025 | |
| 4026 | __ bind(&setup_rest); |
| 4027 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4028 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4029 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 4030 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4031 | |
| 4032 | // Drop arguments and come back to JS mode. |
| 4033 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4034 | |
| 4035 | // Check the result. |
| 4036 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4037 | __ cmp(eax, 1); |
| 4038 | // We expect exactly one result since we force the called regexp to behave |
| 4039 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4040 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4041 | Label failure; |
| 4042 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4043 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4044 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 4045 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4046 | __ j(not_equal, &runtime); |
| 4047 | // Result must now be exception. If there is no pending exception already a |
| 4048 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4049 | // haven't created the exception yet. Handle that in the runtime system. |
| 4050 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4051 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4052 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4053 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4054 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4055 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4056 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4057 | // For exception, throw the exception again. |
| 4058 | |
| 4059 | // Clear the pending exception variable. |
| 4060 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4061 | |
| 4062 | // Special handling of termination exceptions which are uncatchable |
| 4063 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4064 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4065 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4066 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4067 | |
| 4068 | // Handle normal exception by following handler chain. |
| 4069 | __ Throw(eax); |
| 4070 | |
| 4071 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4072 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4073 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4074 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4075 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4076 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4077 | __ ret(4 * kPointerSize); |
| 4078 | |
| 4079 | // Load RegExp data. |
| 4080 | __ bind(&success); |
| 4081 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4082 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4083 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4084 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4085 | STATIC_ASSERT(kSmiTag == 0); |
| 4086 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4087 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4088 | |
| 4089 | // edx: Number of capture registers |
| 4090 | // 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] | 4091 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4092 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4093 | __ JumpIfSmi(eax, &runtime); |
| 4094 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 4095 | __ j(not_equal, &runtime); |
| 4096 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4097 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4098 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 4099 | __ cmp(eax, factory->fixed_array_map()); |
| 4100 | __ j(not_equal, &runtime); |
| 4101 | // Check that the last match info has space for the capture registers and the |
| 4102 | // additional information. |
| 4103 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 4104 | __ SmiUntag(eax); |
| 4105 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 4106 | __ cmp(edx, eax); |
| 4107 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4108 | |
| 4109 | // ebx: last_match_info backing store (FixedArray) |
| 4110 | // edx: number of capture registers |
| 4111 | // Store the capture count. |
| 4112 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4113 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4114 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4115 | // Store last subject and last input. |
| 4116 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4117 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4118 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4119 | __ RecordWriteField(ebx, |
| 4120 | RegExpImpl::kLastSubjectOffset, |
| 4121 | eax, |
| 4122 | edi, |
| 4123 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4124 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4125 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4126 | __ RecordWriteField(ebx, |
| 4127 | RegExpImpl::kLastInputOffset, |
| 4128 | eax, |
| 4129 | edi, |
| 4130 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4131 | |
| 4132 | // Get the static offsets vector filled by the native regexp code. |
| 4133 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4134 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4135 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4136 | |
| 4137 | // ebx: last_match_info backing store (FixedArray) |
| 4138 | // ecx: offsets vector |
| 4139 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4140 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4141 | // Capture register counter starts from number of capture registers and |
| 4142 | // counts down until wraping after zero. |
| 4143 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4144 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4145 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4146 | // Read the value from the static offsets vector buffer. |
| 4147 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4148 | __ SmiTag(edi); |
| 4149 | // Store the smi value in the last match info. |
| 4150 | __ mov(FieldOperand(ebx, |
| 4151 | edx, |
| 4152 | times_pointer_size, |
| 4153 | RegExpImpl::kFirstCaptureOffset), |
| 4154 | edi); |
| 4155 | __ jmp(&next_capture); |
| 4156 | __ bind(&done); |
| 4157 | |
| 4158 | // Return last match info. |
| 4159 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4160 | __ ret(4 * kPointerSize); |
| 4161 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4162 | // Do the runtime call to execute the regexp. |
| 4163 | __ bind(&runtime); |
| 4164 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4165 | |
| 4166 | // Deferred code for string handling. |
| 4167 | // (7) Not a long external string? If yes, go to (10). |
| 4168 | __ bind(¬_seq_nor_cons); |
| 4169 | // Compare flags are still set from (3). |
| 4170 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4171 | |
| 4172 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4173 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4174 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4175 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4176 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4177 | if (FLAG_debug_code) { |
| 4178 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4179 | // Sequential strings have already been ruled out. |
| 4180 | __ test_b(ebx, kIsIndirectStringMask); |
| 4181 | __ Assert(zero, "external string expected, but not found"); |
| 4182 | } |
| 4183 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4184 | // 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] | 4185 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4186 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4187 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4188 | // (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] | 4189 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4190 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4191 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4192 | // eax: sequential subject string (or look-alike, external string) |
| 4193 | // edx: original subject string |
| 4194 | // ecx: RegExp data (FixedArray) |
| 4195 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4196 | __ bind(&seq_two_byte_string); |
| 4197 | // Load previous index and check range before edx is overwritten. We have |
| 4198 | // to use edx instead of eax here because it might have been only made to |
| 4199 | // look like a sequential string when it actually is an external string. |
| 4200 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4201 | __ JumpIfNotSmi(ebx, &runtime); |
| 4202 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4203 | __ j(above_equal, &runtime); |
| 4204 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4205 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4206 | __ jmp(&check_code); // Go to (E). |
| 4207 | |
| 4208 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4209 | __ bind(¬_long_external); |
| 4210 | // Catch non-string subject or short external string. |
| 4211 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4212 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4213 | __ j(not_zero, &runtime); |
| 4214 | |
| 4215 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4216 | // Load offset into edi and replace subject string with parent. |
| 4217 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4218 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4219 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4220 | #endif // V8_INTERPRETED_REGEXP |
| 4221 | } |
| 4222 | |
| 4223 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4224 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4225 | const int kMaxInlineLength = 100; |
| 4226 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4227 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4228 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4229 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4230 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4231 | __ j(above, &slowcase); |
| 4232 | // Smi-tagging is equivalent to multiplying by 2. |
| 4233 | STATIC_ASSERT(kSmiTag == 0); |
| 4234 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4235 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4236 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4237 | // Elements: [Map][Length][..elements..] |
| 4238 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4239 | times_pointer_size, |
| 4240 | ebx, // In: Number of elements as a smi |
| 4241 | REGISTER_VALUE_IS_SMI, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4242 | eax, // Out: Start of allocation (tagged). |
| 4243 | ecx, // Out: End of allocation. |
| 4244 | edx, // Scratch register |
| 4245 | &slowcase, |
| 4246 | TAG_OBJECT); |
| 4247 | // eax: Start of allocated area, object-tagged. |
| 4248 | |
| 4249 | // Set JSArray map to global.regexp_result_map(). |
| 4250 | // Set empty properties FixedArray. |
| 4251 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4252 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4253 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4254 | Factory* factory = masm->isolate()->factory(); |
| 4255 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4256 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4257 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4258 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4259 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4260 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4261 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4262 | |
| 4263 | // Set input, index and length fields from arguments. |
| 4264 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4265 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4266 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4267 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4268 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4269 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4270 | |
| 4271 | // Fill out the elements FixedArray. |
| 4272 | // eax: JSArray. |
| 4273 | // ebx: FixedArray. |
| 4274 | // ecx: Number of elements in array, as smi. |
| 4275 | |
| 4276 | // Set map. |
| 4277 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4278 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4279 | // Set length. |
| 4280 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4281 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4282 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4283 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4284 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4285 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4286 | // eax: JSArray. |
| 4287 | // ecx: Number of elements to fill. |
| 4288 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4289 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4290 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4291 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4292 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4293 | __ 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] | 4294 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4295 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4296 | __ jmp(&loop); |
| 4297 | |
| 4298 | __ bind(&done); |
| 4299 | __ ret(3 * kPointerSize); |
| 4300 | |
| 4301 | __ bind(&slowcase); |
| 4302 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4303 | } |
| 4304 | |
| 4305 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4306 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4307 | Register object, |
| 4308 | Register result, |
| 4309 | Register scratch1, |
| 4310 | Register scratch2, |
| 4311 | bool object_is_smi, |
| 4312 | Label* not_found) { |
| 4313 | // Use of registers. Register result is used as a temporary. |
| 4314 | Register number_string_cache = result; |
| 4315 | Register mask = scratch1; |
| 4316 | Register scratch = scratch2; |
| 4317 | |
| 4318 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4319 | ExternalReference roots_array_start = |
| 4320 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4321 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4322 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4323 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4324 | // Make the hash mask from the length of the number string cache. It |
| 4325 | // contains two elements (number and string) for each cache entry. |
| 4326 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4327 | __ 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] | 4328 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4329 | |
| 4330 | // Calculate the entry in the number string cache. The hash value in the |
| 4331 | // number string cache for smis is just the smi value, and the hash for |
| 4332 | // doubles is the xor of the upper and lower words. See |
| 4333 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4334 | Label smi_hash_calculated; |
| 4335 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4336 | if (object_is_smi) { |
| 4337 | __ mov(scratch, object); |
| 4338 | __ SmiUntag(scratch); |
| 4339 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4340 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4341 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4342 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4343 | __ mov(scratch, object); |
| 4344 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4345 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4346 | __ bind(¬_smi); |
| 4347 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4348 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4349 | __ j(not_equal, not_found); |
| 4350 | STATIC_ASSERT(8 == kDoubleSize); |
| 4351 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4352 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4353 | // 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] | 4354 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4355 | Register index = scratch; |
| 4356 | Register probe = mask; |
| 4357 | __ mov(probe, |
| 4358 | FieldOperand(number_string_cache, |
| 4359 | index, |
| 4360 | times_twice_pointer_size, |
| 4361 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4362 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4363 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4364 | CpuFeatures::Scope fscope(SSE2); |
| 4365 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4366 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4367 | __ ucomisd(xmm0, xmm1); |
| 4368 | } else { |
| 4369 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4370 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4371 | __ FCmp(); |
| 4372 | } |
| 4373 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4374 | __ 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] | 4375 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | __ bind(&smi_hash_calculated); |
| 4379 | // 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] | 4380 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | Register index = scratch; |
| 4382 | // Check if the entry is the smi we are looking for. |
| 4383 | __ cmp(object, |
| 4384 | FieldOperand(number_string_cache, |
| 4385 | index, |
| 4386 | times_twice_pointer_size, |
| 4387 | FixedArray::kHeaderSize)); |
| 4388 | __ j(not_equal, not_found); |
| 4389 | |
| 4390 | // Get the result from the cache. |
| 4391 | __ bind(&load_result_from_cache); |
| 4392 | __ mov(result, |
| 4393 | FieldOperand(number_string_cache, |
| 4394 | index, |
| 4395 | times_twice_pointer_size, |
| 4396 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4397 | Counters* counters = masm->isolate()->counters(); |
| 4398 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | |
| 4402 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4403 | Label runtime; |
| 4404 | |
| 4405 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4406 | |
| 4407 | // Generate code to lookup number in the number string cache. |
| 4408 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4409 | __ ret(1 * kPointerSize); |
| 4410 | |
| 4411 | __ bind(&runtime); |
| 4412 | // Handle number to string in the runtime system if not found in the cache. |
| 4413 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4414 | } |
| 4415 | |
| 4416 | |
| 4417 | static int NegativeComparisonResult(Condition cc) { |
| 4418 | ASSERT(cc != equal); |
| 4419 | ASSERT((cc == less) || (cc == less_equal) |
| 4420 | || (cc == greater) || (cc == greater_equal)); |
| 4421 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4422 | } |
| 4423 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4424 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4425 | static void CheckInputType(MacroAssembler* masm, |
| 4426 | Register input, |
| 4427 | CompareIC::State expected, |
| 4428 | Label* fail) { |
| 4429 | Label ok; |
| 4430 | if (expected == CompareIC::SMI) { |
| 4431 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4432 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4433 | __ JumpIfSmi(input, &ok); |
| 4434 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4435 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4436 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4437 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4438 | // We could be strict about symbol/string here, but as long as |
| 4439 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4440 | __ bind(&ok); |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | static void BranchIfNonSymbol(MacroAssembler* masm, |
| 4445 | Label* label, |
| 4446 | Register object, |
| 4447 | Register scratch) { |
| 4448 | __ JumpIfSmi(object, label); |
| 4449 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4450 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4451 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4452 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4453 | __ j(not_equal, label); |
| 4454 | } |
| 4455 | |
| 4456 | |
| 4457 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4458 | Label check_unequal_objects; |
| 4459 | Condition cc = GetCondition(); |
| 4460 | |
| 4461 | Label miss; |
| 4462 | CheckInputType(masm, edx, left_, &miss); |
| 4463 | CheckInputType(masm, eax, right_, &miss); |
| 4464 | |
| 4465 | // Compare two smis. |
| 4466 | Label non_smi, smi_done; |
| 4467 | __ mov(ecx, edx); |
| 4468 | __ or_(ecx, eax); |
| 4469 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4470 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4471 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4472 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4473 | __ bind(&smi_done); |
| 4474 | __ mov(eax, edx); |
| 4475 | __ ret(0); |
| 4476 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4477 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4478 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4479 | // it is certain that at least one operand isn't a smi. |
| 4480 | |
| 4481 | // Identical objects can be compared fast, but there are some tricky cases |
| 4482 | // for NaN and undefined. |
| 4483 | { |
| 4484 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4485 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4486 | __ j(not_equal, ¬_identical); |
| 4487 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4488 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4489 | // Check for undefined. undefined OP undefined is false even though |
| 4490 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4491 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4492 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4493 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4494 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4495 | __ ret(0); |
| 4496 | __ bind(&check_for_nan); |
| 4497 | } |
| 4498 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4499 | // Test for NaN. Sadly, we can't just compare to factory->nan_value(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4500 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4501 | Label heap_number; |
| 4502 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4503 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4504 | __ j(equal, &heap_number, Label::kNear); |
| 4505 | if (cc != equal) { |
| 4506 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4507 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4508 | __ j(above_equal, ¬_identical); |
| 4509 | } |
| 4510 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4511 | __ ret(0); |
| 4512 | |
| 4513 | __ bind(&heap_number); |
| 4514 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4515 | // it's not NaN. |
| 4516 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4517 | // and not all mantissa bits (0..51) clear. |
| 4518 | // We only accept QNaNs, which have bit 51 set. |
| 4519 | // Read top bits of double representation (second word of value). |
| 4520 | |
| 4521 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4522 | // all bits in the mask are set. We only need to check the word |
| 4523 | // that contains the exponent and high bit of the mantissa. |
| 4524 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4525 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 4526 | __ Set(eax, Immediate(0)); |
| 4527 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4528 | // bits. |
| 4529 | __ add(edx, edx); |
| 4530 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4531 | if (cc == equal) { |
| 4532 | STATIC_ASSERT(EQUAL != 1); |
| 4533 | __ setcc(above_equal, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4534 | __ ret(0); |
| 4535 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4536 | Label nan; |
| 4537 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4538 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4539 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4540 | __ bind(&nan); |
| 4541 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 4542 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | __ bind(¬_identical); |
| 4546 | } |
| 4547 | |
| 4548 | // Strict equality can quickly decide whether objects are equal. |
| 4549 | // 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] | 4550 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4551 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4552 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4553 | // If we're doing a strict equality comparison, we don't have to do |
| 4554 | // type conversion, so we generate code to do fast comparison for objects |
| 4555 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4556 | // slow-case code. |
| 4557 | // If either is a Smi (we know that not both are), then they can only |
| 4558 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4559 | STATIC_ASSERT(kSmiTag == 0); |
| 4560 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4561 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4562 | __ and_(ecx, eax); |
| 4563 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4564 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4565 | // One operand is a smi. |
| 4566 | |
| 4567 | // Check whether the non-smi is a heap number. |
| 4568 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4569 | // 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] | 4570 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4571 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4572 | __ xor_(ebx, eax); |
| 4573 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4574 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4575 | // if eax was smi, ebx is now edx, else eax. |
| 4576 | |
| 4577 | // Check if the non-smi operand is a heap number. |
| 4578 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4579 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4580 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4581 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4582 | // Return non-equal (ebx is not zero) |
| 4583 | __ mov(eax, ebx); |
| 4584 | __ ret(0); |
| 4585 | |
| 4586 | __ bind(¬_smis); |
| 4587 | // If either operand is a JSObject or an oddball value, then they are not |
| 4588 | // equal since their pointers are different |
| 4589 | // There is no test for undetectability in strict equality. |
| 4590 | |
| 4591 | // Get the type of the first operand. |
| 4592 | // 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] | 4593 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4594 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4595 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4596 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4597 | |
| 4598 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4599 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4600 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4601 | __ bind(&return_not_equal); |
| 4602 | __ ret(0); |
| 4603 | |
| 4604 | __ bind(&first_non_object); |
| 4605 | // Check for oddballs: true, false, null, undefined. |
| 4606 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4607 | __ j(equal, &return_not_equal); |
| 4608 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4609 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4610 | __ j(above_equal, &return_not_equal); |
| 4611 | |
| 4612 | // Check for oddballs: true, false, null, undefined. |
| 4613 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4614 | __ j(equal, &return_not_equal); |
| 4615 | |
| 4616 | // Fall through to the general case. |
| 4617 | __ bind(&slow); |
| 4618 | } |
| 4619 | |
| 4620 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4621 | Label non_number_comparison; |
| 4622 | Label unordered; |
| 4623 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4624 | CpuFeatures::Scope use_sse2(SSE2); |
| 4625 | CpuFeatures::Scope use_cmov(CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4626 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4627 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4628 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4629 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4630 | // Don't base result on EFLAGS when a NaN is involved. |
| 4631 | __ j(parity_even, &unordered, Label::kNear); |
| 4632 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4633 | __ mov(eax, 0); // equal |
| 4634 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4635 | __ cmov(above, eax, ecx); |
| 4636 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4637 | __ cmov(below, eax, ecx); |
| 4638 | __ ret(0); |
| 4639 | } else { |
| 4640 | FloatingPointHelper::CheckFloatOperands( |
| 4641 | masm, &non_number_comparison, ebx); |
| 4642 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4643 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4644 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4645 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4646 | // Don't base result on EFLAGS when a NaN is involved. |
| 4647 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4648 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4649 | Label below_label, above_label; |
| 4650 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4651 | __ j(below, &below_label, Label::kNear); |
| 4652 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4653 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4654 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4655 | __ ret(0); |
| 4656 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4657 | __ bind(&below_label); |
| 4658 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4659 | __ ret(0); |
| 4660 | |
| 4661 | __ bind(&above_label); |
| 4662 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4663 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4666 | // If one of the numbers was NaN, then the result is always false. |
| 4667 | // The cc is never not-equal. |
| 4668 | __ bind(&unordered); |
| 4669 | ASSERT(cc != not_equal); |
| 4670 | if (cc == less || cc == less_equal) { |
| 4671 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4672 | } else { |
| 4673 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4674 | } |
| 4675 | __ ret(0); |
| 4676 | |
| 4677 | // The number comparison code did not provide a valid result. |
| 4678 | __ bind(&non_number_comparison); |
| 4679 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4680 | // Fast negative check for symbol-to-symbol equality. |
| 4681 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4682 | if (cc == equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4683 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4684 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4685 | |
| 4686 | // We've already checked for object identity, so if both operands |
| 4687 | // are symbols they aren't equal. Register eax already holds a |
| 4688 | // non-zero value, which indicates not equal, so just return. |
| 4689 | __ ret(0); |
| 4690 | } |
| 4691 | |
| 4692 | __ bind(&check_for_strings); |
| 4693 | |
| 4694 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4695 | &check_unequal_objects); |
| 4696 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4697 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4698 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4699 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4700 | edx, |
| 4701 | eax, |
| 4702 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4703 | ebx); |
| 4704 | } else { |
| 4705 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4706 | edx, |
| 4707 | eax, |
| 4708 | ecx, |
| 4709 | ebx, |
| 4710 | edi); |
| 4711 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4712 | #ifdef DEBUG |
| 4713 | __ Abort("Unexpected fall-through from string comparison"); |
| 4714 | #endif |
| 4715 | |
| 4716 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4717 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4718 | // Non-strict equality. Objects are unequal if |
| 4719 | // they are both JSObjects and not undetectable, |
| 4720 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4721 | Label not_both_objects; |
| 4722 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4723 | // At most one is a smi, so we can test for smi by adding the two. |
| 4724 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4725 | // a heap object has the low bit clear. |
| 4726 | STATIC_ASSERT(kSmiTag == 0); |
| 4727 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4728 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4729 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4730 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4731 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4732 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4733 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4734 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4735 | // We do not bail out after this point. Both are JSObjects, and |
| 4736 | // they are equal if and only if both are undetectable. |
| 4737 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4738 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4739 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4740 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4741 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4742 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4743 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4744 | // The objects are both undetectable, so they both compare as the value |
| 4745 | // undefined, and are equal. |
| 4746 | __ Set(eax, Immediate(EQUAL)); |
| 4747 | __ bind(&return_unequal); |
| 4748 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4749 | // or return equal if we fell through to here. |
| 4750 | __ ret(0); // rax, rdx were pushed |
| 4751 | __ bind(¬_both_objects); |
| 4752 | } |
| 4753 | |
| 4754 | // Push arguments below the return address. |
| 4755 | __ pop(ecx); |
| 4756 | __ push(edx); |
| 4757 | __ push(eax); |
| 4758 | |
| 4759 | // Figure out which native to call and setup the arguments. |
| 4760 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4761 | if (cc == equal) { |
| 4762 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4763 | } else { |
| 4764 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4765 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | // Restore return address on the stack. |
| 4769 | __ push(ecx); |
| 4770 | |
| 4771 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4772 | // tagged as a small integer. |
| 4773 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4774 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4775 | __ bind(&miss); |
| 4776 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | |
| 4780 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4781 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4785 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4786 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4787 | } |
| 4788 | |
| 4789 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4790 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4791 | // Cache the called function in a global property cell. Cache states |
| 4792 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4793 | // megamorphic. |
| 4794 | // ebx : cache cell for call target |
| 4795 | // edi : the function to call |
| 4796 | Isolate* isolate = masm->isolate(); |
| 4797 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4798 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4799 | // Load the cache state into ecx. |
| 4800 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4801 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4802 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4803 | // function without changing the state. |
| 4804 | __ cmp(ecx, edi); |
| 4805 | __ j(equal, &done, Label::kNear); |
| 4806 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4807 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4808 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4809 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4810 | // megamorphic. |
| 4811 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4812 | __ j(equal, &initialize, Label::kNear); |
| 4813 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4814 | // write-barrier is needed. |
| 4815 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4816 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4817 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4818 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4819 | // An uninitialized cache is patched with the function. |
| 4820 | __ bind(&initialize); |
| 4821 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4822 | // No need for a write barrier here - cells are rescanned. |
| 4823 | |
| 4824 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4828 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4829 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4830 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4831 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4832 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4833 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4834 | // The receiver might implicitly be the global object. This is |
| 4835 | // indicated by passing the hole as the receiver to the call |
| 4836 | // function stub. |
| 4837 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4838 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4839 | // Get the receiver from the stack. |
| 4840 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4841 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4842 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4843 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4844 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4845 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4846 | __ mov(ecx, GlobalObjectOperand()); |
| 4847 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4848 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4849 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4852 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4853 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4854 | // Goto slow case if we do not have a function. |
| 4855 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4856 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4857 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4858 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4859 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4862 | // Fast-case: Just invoke the function. |
| 4863 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4864 | |
| 4865 | if (ReceiverMightBeImplicit()) { |
| 4866 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4867 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4868 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4869 | __ InvokeFunction(edi, |
| 4870 | actual, |
| 4871 | JUMP_FUNCTION, |
| 4872 | NullCallWrapper(), |
| 4873 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4874 | __ bind(&call_as_function); |
| 4875 | } |
| 4876 | __ InvokeFunction(edi, |
| 4877 | actual, |
| 4878 | JUMP_FUNCTION, |
| 4879 | NullCallWrapper(), |
| 4880 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4881 | |
| 4882 | // Slow-case: Non-function called. |
| 4883 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4884 | if (RecordCallTarget()) { |
| 4885 | // 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] | 4886 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4887 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4888 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4889 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4890 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4891 | // Check for function proxy. |
| 4892 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4893 | __ j(not_equal, &non_function); |
| 4894 | __ pop(ecx); |
| 4895 | __ push(edi); // put proxy as additional argument under return address |
| 4896 | __ push(ecx); |
| 4897 | __ Set(eax, Immediate(argc_ + 1)); |
| 4898 | __ Set(ebx, Immediate(0)); |
| 4899 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4900 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4901 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4902 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4903 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4904 | } |
| 4905 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4906 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4907 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4908 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4909 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4910 | __ Set(eax, Immediate(argc_)); |
| 4911 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4912 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4913 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4914 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4915 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4916 | } |
| 4917 | |
| 4918 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4919 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4920 | // eax : number of arguments |
| 4921 | // ebx : cache cell for call target |
| 4922 | // edi : constructor function |
| 4923 | Label slow, non_function_call; |
| 4924 | |
| 4925 | // Check that function is not a smi. |
| 4926 | __ JumpIfSmi(edi, &non_function_call); |
| 4927 | // Check that function is a JSFunction. |
| 4928 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4929 | __ j(not_equal, &slow); |
| 4930 | |
| 4931 | if (RecordCallTarget()) { |
| 4932 | GenerateRecordCallTarget(masm); |
| 4933 | } |
| 4934 | |
| 4935 | // Jump to the function-specific construct stub. |
| 4936 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4937 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4938 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4939 | __ jmp(ebx); |
| 4940 | |
| 4941 | // edi: called object |
| 4942 | // eax: number of arguments |
| 4943 | // ecx: object map |
| 4944 | Label do_call; |
| 4945 | __ bind(&slow); |
| 4946 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4947 | __ j(not_equal, &non_function_call); |
| 4948 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4949 | __ jmp(&do_call); |
| 4950 | |
| 4951 | __ bind(&non_function_call); |
| 4952 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4953 | __ bind(&do_call); |
| 4954 | // Set expected number of arguments to zero (not changing eax). |
| 4955 | __ Set(ebx, Immediate(0)); |
| 4956 | Handle<Code> arguments_adaptor = |
| 4957 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4958 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4959 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4960 | } |
| 4961 | |
| 4962 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4963 | bool CEntryStub::NeedsImmovableCode() { |
| 4964 | return false; |
| 4965 | } |
| 4966 | |
| 4967 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4968 | bool CEntryStub::IsPregenerated() { |
| 4969 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4970 | result_size_ == 1; |
| 4971 | } |
| 4972 | |
| 4973 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4974 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4975 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4976 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4977 | // 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^] | 4978 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4982 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4983 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4984 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4985 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4986 | // which would lead to code stub initialization state being messed up. |
| 4987 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4988 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4989 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4990 | } |
| 4991 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4992 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4993 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4997 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4998 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 4999 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5000 | code->set_is_pregenerated(true); |
| 5001 | } |
| 5002 | |
| 5003 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5004 | static void JumpIfOOM(MacroAssembler* masm, |
| 5005 | Register value, |
| 5006 | Register scratch, |
| 5007 | Label* oom_label) { |
| 5008 | __ mov(scratch, value); |
| 5009 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 5010 | STATIC_ASSERT(kFailureTag == 3); |
| 5011 | __ and_(scratch, 0xf); |
| 5012 | __ cmp(scratch, 0xf); |
| 5013 | __ j(equal, oom_label); |
| 5014 | } |
| 5015 | |
| 5016 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5017 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5018 | Label* throw_normal_exception, |
| 5019 | Label* throw_termination_exception, |
| 5020 | Label* throw_out_of_memory_exception, |
| 5021 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5022 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5023 | // eax: result parameter for PerformGC, if any |
| 5024 | // ebx: pointer to C function (C callee-saved) |
| 5025 | // ebp: frame pointer (restored after C call) |
| 5026 | // esp: stack pointer (restored after C call) |
| 5027 | // edi: number of arguments including receiver (C callee-saved) |
| 5028 | // esi: pointer to the first argument (C callee-saved) |
| 5029 | |
| 5030 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5031 | |
| 5032 | // Check stack alignment. |
| 5033 | if (FLAG_debug_code) { |
| 5034 | __ CheckStackAlignment(); |
| 5035 | } |
| 5036 | |
| 5037 | if (do_gc) { |
| 5038 | // Pass failure code returned from last attempt as first argument to |
| 5039 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5040 | // stack alignment is known to be correct. This function takes one argument |
| 5041 | // which is passed on the stack, and we know that the stack has been |
| 5042 | // prepared to pass at least one argument. |
| 5043 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5044 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5045 | } |
| 5046 | |
| 5047 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5048 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5049 | if (always_allocate_scope) { |
| 5050 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5051 | } |
| 5052 | |
| 5053 | // Call C function. |
| 5054 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5055 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5056 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5057 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5058 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5059 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5060 | |
| 5061 | if (always_allocate_scope) { |
| 5062 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5063 | } |
| 5064 | |
| 5065 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5066 | // call as this may lead to crashes in the IC code later. |
| 5067 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5068 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5069 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5070 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5071 | __ int3(); |
| 5072 | __ bind(&okay); |
| 5073 | } |
| 5074 | |
| 5075 | // Check for failure result. |
| 5076 | Label failure_returned; |
| 5077 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5078 | __ lea(ecx, Operand(eax, 1)); |
| 5079 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5080 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5081 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5082 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5083 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5084 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5085 | |
| 5086 | // Check that there is no pending exception, otherwise we |
| 5087 | // should have returned some failure value. |
| 5088 | if (FLAG_debug_code) { |
| 5089 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5090 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5091 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5092 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5093 | // 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] | 5094 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5095 | __ int3(); |
| 5096 | __ bind(&okay); |
| 5097 | __ pop(edx); |
| 5098 | } |
| 5099 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5100 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5101 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5102 | __ ret(0); |
| 5103 | |
| 5104 | // Handling of failure. |
| 5105 | __ bind(&failure_returned); |
| 5106 | |
| 5107 | Label retry; |
| 5108 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5109 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5110 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5111 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5112 | |
| 5113 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5114 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5115 | |
| 5116 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5117 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5118 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5119 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5120 | |
| 5121 | // Special handling of termination exceptions which are uncatchable |
| 5122 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5123 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5124 | __ j(equal, throw_termination_exception); |
| 5125 | |
| 5126 | // Handle normal exception. |
| 5127 | __ jmp(throw_normal_exception); |
| 5128 | |
| 5129 | // Retry. |
| 5130 | __ bind(&retry); |
| 5131 | } |
| 5132 | |
| 5133 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5134 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5135 | // eax: number of arguments including receiver |
| 5136 | // ebx: pointer to C function (C callee-saved) |
| 5137 | // ebp: frame pointer (restored after C call) |
| 5138 | // esp: stack pointer (restored after C call) |
| 5139 | // esi: current context (C callee-saved) |
| 5140 | // edi: JS function of the caller (C callee-saved) |
| 5141 | |
| 5142 | // NOTE: Invocations of builtins may return failure objects instead |
| 5143 | // of a proper result. The builtin entry handles this by performing |
| 5144 | // a garbage collection and retrying the builtin (twice). |
| 5145 | |
| 5146 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5147 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5148 | |
| 5149 | // eax: result parameter for PerformGC, if any (setup below) |
| 5150 | // ebx: pointer to builtin function (C callee-saved) |
| 5151 | // ebp: frame pointer (restored after C call) |
| 5152 | // esp: stack pointer (restored after C call) |
| 5153 | // edi: number of arguments including receiver (C callee-saved) |
| 5154 | // esi: argv pointer (C callee-saved) |
| 5155 | |
| 5156 | Label throw_normal_exception; |
| 5157 | Label throw_termination_exception; |
| 5158 | Label throw_out_of_memory_exception; |
| 5159 | |
| 5160 | // Call into the runtime system. |
| 5161 | GenerateCore(masm, |
| 5162 | &throw_normal_exception, |
| 5163 | &throw_termination_exception, |
| 5164 | &throw_out_of_memory_exception, |
| 5165 | false, |
| 5166 | false); |
| 5167 | |
| 5168 | // Do space-specific GC and retry runtime call. |
| 5169 | GenerateCore(masm, |
| 5170 | &throw_normal_exception, |
| 5171 | &throw_termination_exception, |
| 5172 | &throw_out_of_memory_exception, |
| 5173 | true, |
| 5174 | false); |
| 5175 | |
| 5176 | // Do full GC and retry runtime call one final time. |
| 5177 | Failure* failure = Failure::InternalError(); |
| 5178 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5179 | GenerateCore(masm, |
| 5180 | &throw_normal_exception, |
| 5181 | &throw_termination_exception, |
| 5182 | &throw_out_of_memory_exception, |
| 5183 | true, |
| 5184 | true); |
| 5185 | |
| 5186 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5187 | // Set external caught exception to false. |
| 5188 | Isolate* isolate = masm->isolate(); |
| 5189 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5190 | isolate); |
| 5191 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5192 | |
| 5193 | // Set pending exception and eax to out of memory exception. |
| 5194 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5195 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5196 | Label already_have_failure; |
| 5197 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5198 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5199 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5200 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5201 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5202 | |
| 5203 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5204 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5205 | |
| 5206 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5207 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5212 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5213 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5214 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5215 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5216 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5217 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5218 | |
| 5219 | // Push marker in two places. |
| 5220 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5221 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5222 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5223 | // Save callee-saved registers (C calling conventions). |
| 5224 | __ push(edi); |
| 5225 | __ push(esi); |
| 5226 | __ push(ebx); |
| 5227 | |
| 5228 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5229 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5230 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5231 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | // 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] | 5233 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5234 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5235 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5236 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5237 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5238 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5239 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5240 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5241 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5242 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5243 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5244 | // block that sets the pending exception. |
| 5245 | __ jmp(&invoke); |
| 5246 | __ bind(&handler_entry); |
| 5247 | handler_offset_ = handler_entry.pos(); |
| 5248 | // Caught exception: Store result (exception) in the pending exception |
| 5249 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5250 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5251 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5252 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5253 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5254 | __ jmp(&exit); |
| 5255 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5256 | // Invoke: Link this frame into the handler chain. There's only one |
| 5257 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5258 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5259 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5260 | |
| 5261 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5262 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5264 | |
| 5265 | // Fake a receiver (NULL). |
| 5266 | __ push(Immediate(0)); // receiver |
| 5267 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5268 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5269 | // pop the faked function when we return. Notice that we cannot store a |
| 5270 | // reference to the trampoline code directly in this stub, because the |
| 5271 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5272 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5273 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5274 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5275 | __ mov(edx, Immediate(construct_entry)); |
| 5276 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5277 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5278 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5279 | __ mov(edx, Immediate(entry)); |
| 5280 | } |
| 5281 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5282 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5283 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5284 | |
| 5285 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5286 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5287 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5288 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5289 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5290 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5291 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5292 | __ j(not_equal, ¬_outermost_js_2); |
| 5293 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5294 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5295 | |
| 5296 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5297 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5298 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5299 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | |
| 5301 | // Restore callee-saved registers (C calling conventions). |
| 5302 | __ pop(ebx); |
| 5303 | __ pop(esi); |
| 5304 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5305 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5306 | |
| 5307 | // Restore frame pointer and return. |
| 5308 | __ pop(ebp); |
| 5309 | __ ret(0); |
| 5310 | } |
| 5311 | |
| 5312 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5313 | // Generate stub code for instanceof. |
| 5314 | // This code can patch a call site inlined cache of the instance of check, |
| 5315 | // which looks like this. |
| 5316 | // |
| 5317 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5318 | // 75 0a jne <some near label> |
| 5319 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5320 | // |
| 5321 | // If call site patching is requested the stack will have the delta from the |
| 5322 | // return address to the cmp instruction just below the return address. This |
| 5323 | // also means that call site patching can only take place with arguments in |
| 5324 | // registers. TOS looks like this when call site patching is requested |
| 5325 | // |
| 5326 | // esp[0] : return address |
| 5327 | // esp[4] : delta from return address to cmp instruction |
| 5328 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5329 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5330 | // Call site inlining and patching implies arguments in registers. |
| 5331 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5332 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5333 | // Fixed register usage throughout the stub. |
| 5334 | Register object = eax; // Object (lhs). |
| 5335 | Register map = ebx; // Map of the object. |
| 5336 | Register function = edx; // Function (rhs). |
| 5337 | Register prototype = edi; // Prototype of the function. |
| 5338 | Register scratch = ecx; |
| 5339 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5340 | // Constants describing the call site code to patch. |
| 5341 | static const int kDeltaToCmpImmediate = 2; |
| 5342 | static const int kDeltaToMov = 8; |
| 5343 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5344 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5345 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5346 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5347 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5348 | ExternalReference roots_array_start = |
| 5349 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5350 | |
| 5351 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5352 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5353 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5354 | // Get the object and function - they are always both needed. |
| 5355 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5356 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5357 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5358 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5359 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5360 | |
| 5361 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5362 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5363 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5364 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5365 | // If there is a call site cache don't look in the global cache, but do the |
| 5366 | // real lookup and update the call site cache. |
| 5367 | if (!HasCallSiteInlineCheck()) { |
| 5368 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5369 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5370 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5371 | __ cmp(function, Operand::StaticArray(scratch, |
| 5372 | times_pointer_size, |
| 5373 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5374 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5375 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5376 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5377 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5378 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5379 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5380 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5381 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5382 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5383 | __ bind(&miss); |
| 5384 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5385 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5386 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5387 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5388 | |
| 5389 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5390 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5391 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5392 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5393 | // Update the global instanceof or call site inlined cache with the current |
| 5394 | // map and function. The cached answer will be set when it is known below. |
| 5395 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5396 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5397 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5398 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5399 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5400 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5401 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5402 | } else { |
| 5403 | // The constants for the code patching are based on no push instructions |
| 5404 | // at the call site. |
| 5405 | ASSERT(HasArgsInRegisters()); |
| 5406 | // Get return address and delta to inlined map check. |
| 5407 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5408 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5409 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5410 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5411 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5412 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5413 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5414 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5415 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5416 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5417 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5418 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5419 | // Loop through the prototype chain of the object looking for the function |
| 5420 | // prototype. |
| 5421 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5422 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5423 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5424 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5425 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5426 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5427 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5428 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5429 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5430 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5431 | __ jmp(&loop); |
| 5432 | |
| 5433 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5434 | if (!HasCallSiteInlineCheck()) { |
| 5435 | __ Set(eax, Immediate(0)); |
| 5436 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5437 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5438 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5439 | } else { |
| 5440 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5441 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5442 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5443 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5444 | if (FLAG_debug_code) { |
| 5445 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5446 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5447 | } |
| 5448 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5449 | if (!ReturnTrueFalseObject()) { |
| 5450 | __ Set(eax, Immediate(0)); |
| 5451 | } |
| 5452 | } |
| 5453 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5454 | |
| 5455 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5456 | if (!HasCallSiteInlineCheck()) { |
| 5457 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5458 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5459 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5460 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5461 | } else { |
| 5462 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5463 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5464 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5465 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5466 | if (FLAG_debug_code) { |
| 5467 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5468 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5469 | } |
| 5470 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5471 | if (!ReturnTrueFalseObject()) { |
| 5472 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5473 | } |
| 5474 | } |
| 5475 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5476 | |
| 5477 | Label object_not_null, object_not_null_or_smi; |
| 5478 | __ bind(¬_js_object); |
| 5479 | // Before null, smi and string value checks, check that the rhs is a function |
| 5480 | // 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] | 5481 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5482 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5483 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5484 | |
| 5485 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5486 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5487 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5488 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5489 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5490 | |
| 5491 | __ bind(&object_not_null); |
| 5492 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5493 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5494 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5495 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5496 | |
| 5497 | __ bind(&object_not_null_or_smi); |
| 5498 | // String values is not instance of anything. |
| 5499 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5500 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5501 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5502 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5503 | |
| 5504 | // Slow-case: Go through the JavaScript implementation. |
| 5505 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5506 | if (!ReturnTrueFalseObject()) { |
| 5507 | // Tail call the builtin which returns 0 or 1. |
| 5508 | if (HasArgsInRegisters()) { |
| 5509 | // Push arguments below return address. |
| 5510 | __ pop(scratch); |
| 5511 | __ push(object); |
| 5512 | __ push(function); |
| 5513 | __ push(scratch); |
| 5514 | } |
| 5515 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5516 | } else { |
| 5517 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5518 | { |
| 5519 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5520 | __ push(object); |
| 5521 | __ push(function); |
| 5522 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5523 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5524 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5525 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5526 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5527 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5528 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5529 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5530 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5531 | __ bind(&done); |
| 5532 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5533 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5537 | Register InstanceofStub::left() { return eax; } |
| 5538 | |
| 5539 | |
| 5540 | Register InstanceofStub::right() { return edx; } |
| 5541 | |
| 5542 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5543 | // ------------------------------------------------------------------------- |
| 5544 | // StringCharCodeAtGenerator |
| 5545 | |
| 5546 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | // If the receiver is a smi trigger the non-string case. |
| 5548 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5549 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5550 | |
| 5551 | // Fetch the instance type of the receiver into result register. |
| 5552 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5553 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5554 | // If the receiver is not a string trigger the non-string case. |
| 5555 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5556 | __ j(not_zero, receiver_not_string_); |
| 5557 | |
| 5558 | // If the index is non-smi trigger the non-smi case. |
| 5559 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5560 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5561 | __ bind(&got_smi_index_); |
| 5562 | |
| 5563 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5564 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5565 | __ j(above_equal, index_out_of_range_); |
| 5566 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5567 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5568 | |
| 5569 | Factory* factory = masm->isolate()->factory(); |
| 5570 | StringCharLoadGenerator::Generate( |
| 5571 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5572 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5573 | __ SmiTag(result_); |
| 5574 | __ bind(&exit_); |
| 5575 | } |
| 5576 | |
| 5577 | |
| 5578 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5579 | MacroAssembler* masm, |
| 5580 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5581 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5582 | |
| 5583 | // Index is not a smi. |
| 5584 | __ bind(&index_not_smi_); |
| 5585 | // 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] | 5586 | __ CheckMap(index_, |
| 5587 | masm->isolate()->factory()->heap_number_map(), |
| 5588 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5589 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5590 | call_helper.BeforeCall(masm); |
| 5591 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5592 | __ push(index_); // Consumed by runtime conversion function. |
| 5593 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5594 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5595 | } else { |
| 5596 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5597 | // NumberToSmi discards numbers that are not exact integers. |
| 5598 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5599 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5600 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5601 | // Save the conversion result before the pop instructions below |
| 5602 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5603 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5604 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | __ pop(object_); |
| 5606 | // Reload the instance type. |
| 5607 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5608 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5609 | call_helper.AfterCall(masm); |
| 5610 | // If index is still not a smi, it must be out of range. |
| 5611 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5612 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5613 | // Otherwise, return to the fast path. |
| 5614 | __ jmp(&got_smi_index_); |
| 5615 | |
| 5616 | // Call runtime. We get here when the receiver is a string and the |
| 5617 | // index is a number, but the code of getting the actual character |
| 5618 | // is too complex (e.g., when the string needs to be flattened). |
| 5619 | __ bind(&call_runtime_); |
| 5620 | call_helper.BeforeCall(masm); |
| 5621 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5622 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5623 | __ push(index_); |
| 5624 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5625 | if (!result_.is(eax)) { |
| 5626 | __ mov(result_, eax); |
| 5627 | } |
| 5628 | call_helper.AfterCall(masm); |
| 5629 | __ jmp(&exit_); |
| 5630 | |
| 5631 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5632 | } |
| 5633 | |
| 5634 | |
| 5635 | // ------------------------------------------------------------------------- |
| 5636 | // StringCharFromCodeGenerator |
| 5637 | |
| 5638 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5639 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5640 | STATIC_ASSERT(kSmiTag == 0); |
| 5641 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5642 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5643 | __ test(code_, |
| 5644 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5645 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5646 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5647 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5648 | Factory* factory = masm->isolate()->factory(); |
| 5649 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5650 | STATIC_ASSERT(kSmiTag == 0); |
| 5651 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5652 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5653 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5654 | __ mov(result_, FieldOperand(result_, |
| 5655 | code_, times_half_pointer_size, |
| 5656 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5657 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5658 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5659 | __ bind(&exit_); |
| 5660 | } |
| 5661 | |
| 5662 | |
| 5663 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5664 | MacroAssembler* masm, |
| 5665 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5666 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5667 | |
| 5668 | __ bind(&slow_case_); |
| 5669 | call_helper.BeforeCall(masm); |
| 5670 | __ push(code_); |
| 5671 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5672 | if (!result_.is(eax)) { |
| 5673 | __ mov(result_, eax); |
| 5674 | } |
| 5675 | call_helper.AfterCall(masm); |
| 5676 | __ jmp(&exit_); |
| 5677 | |
| 5678 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5679 | } |
| 5680 | |
| 5681 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5682 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5683 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5684 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5685 | |
| 5686 | // Load the two arguments. |
| 5687 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5688 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5689 | |
| 5690 | // 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] | 5691 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5692 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5693 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5694 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5695 | |
| 5696 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5697 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5698 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5699 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5700 | } else { |
| 5701 | // Here at least one of the arguments is definitely a string. |
| 5702 | // We convert the one that is not known to be a string. |
| 5703 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5704 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5705 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5706 | &call_builtin); |
| 5707 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5708 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5709 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5710 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5711 | &call_builtin); |
| 5712 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5713 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | // Both arguments are strings. |
| 5717 | // eax: first string |
| 5718 | // edx: second string |
| 5719 | // 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] | 5720 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5721 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5722 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5723 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5724 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5725 | // 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] | 5726 | Counters* counters = masm->isolate()->counters(); |
| 5727 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5728 | __ ret(2 * kPointerSize); |
| 5729 | __ bind(&second_not_zero_length); |
| 5730 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5731 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5732 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5733 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5734 | // First string is empty, result is second string which is in edx. |
| 5735 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5736 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5737 | __ ret(2 * kPointerSize); |
| 5738 | |
| 5739 | // Both strings are non-empty. |
| 5740 | // eax: first string |
| 5741 | // ebx: length of first string as a smi |
| 5742 | // ecx: length of second string as a smi |
| 5743 | // edx: second string |
| 5744 | // Look at the length of the result of adding the two strings. |
| 5745 | Label string_add_flat_result, longer_than_two; |
| 5746 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5747 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5748 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5749 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5750 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5751 | // Use the symbol table when adding two one character strings, as it |
| 5752 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5753 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5754 | __ j(not_equal, &longer_than_two); |
| 5755 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5756 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5757 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5758 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5759 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5760 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5761 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5762 | |
| 5763 | // Try to lookup two character string in symbol table. If it is not found |
| 5764 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5765 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5766 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5767 | masm, ebx, ecx, eax, edx, edi, |
| 5768 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5769 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5770 | __ ret(2 * kPointerSize); |
| 5771 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5772 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5773 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5774 | // Reload the arguments. |
| 5775 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5776 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5777 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5778 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5779 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5780 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5781 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5782 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5783 | // Pack both characters in ebx. |
| 5784 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5785 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5786 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5787 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5788 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5789 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5790 | |
| 5791 | __ bind(&longer_than_two); |
| 5792 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5793 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5794 | __ j(below, &string_add_flat_result); |
| 5795 | |
| 5796 | // 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] | 5797 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5798 | Label non_ascii, allocated, ascii_data; |
| 5799 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5800 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5801 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5802 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5803 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5804 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5805 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5806 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5807 | __ j(zero, &non_ascii); |
| 5808 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5809 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5810 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5811 | __ bind(&allocated); |
| 5812 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5813 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5814 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5815 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5816 | Immediate(String::kEmptyHashField)); |
| 5817 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5818 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5819 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5820 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5821 | __ ret(2 * kPointerSize); |
| 5822 | __ bind(&non_ascii); |
| 5823 | // 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] | 5824 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5825 | // ecx: first instance type AND second instance type. |
| 5826 | // edi: second instance type. |
| 5827 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5828 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5829 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5830 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5831 | __ xor_(edi, ecx); |
| 5832 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5833 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5834 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5835 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5837 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | __ jmp(&allocated); |
| 5839 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5840 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5841 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5842 | // Handle creating a flat result from either external or sequential strings. |
| 5843 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | // eax: first string |
| 5845 | // ebx: length of resulting flat string as a smi |
| 5846 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5847 | Label first_prepared, second_prepared; |
| 5848 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5849 | __ bind(&string_add_flat_result); |
| 5850 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5851 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5852 | // ecx: instance type of first string |
| 5853 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5854 | __ test_b(ecx, kStringRepresentationMask); |
| 5855 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5856 | // Rule out short external string and load string resource. |
| 5857 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5858 | __ test_b(ecx, kShortExternalStringMask); |
| 5859 | __ j(not_zero, &call_runtime); |
| 5860 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5861 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5862 | __ jmp(&first_prepared, Label::kNear); |
| 5863 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5864 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5865 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5866 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5867 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5868 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5869 | // Check whether both strings have same encoding. |
| 5870 | // edi: instance type of second string |
| 5871 | __ xor_(ecx, edi); |
| 5872 | __ test_b(ecx, kStringEncodingMask); |
| 5873 | __ j(not_zero, &call_runtime); |
| 5874 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5875 | __ test_b(edi, kStringRepresentationMask); |
| 5876 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5877 | // Rule out short external string and load string resource. |
| 5878 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5879 | __ test_b(edi, kShortExternalStringMask); |
| 5880 | __ j(not_zero, &call_runtime); |
| 5881 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5882 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5883 | __ jmp(&second_prepared, Label::kNear); |
| 5884 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5885 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5886 | __ bind(&second_prepared); |
| 5887 | |
| 5888 | // Push the addresses of both strings' first characters onto the stack. |
| 5889 | __ push(edx); |
| 5890 | __ push(eax); |
| 5891 | |
| 5892 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5893 | // edi: instance type of second string |
| 5894 | // First string and second string have the same encoding. |
| 5895 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5896 | __ test_b(edi, kStringEncodingMask); |
| 5897 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5898 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5899 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5900 | // ebx: length of resulting flat string as a smi |
| 5901 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5902 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5903 | // eax: result string |
| 5904 | __ mov(ecx, eax); |
| 5905 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5906 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5907 | // Load first argument's length and first character location. Account for |
| 5908 | // values currently on the stack when fetching arguments from it. |
| 5909 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5910 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5911 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5912 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | // eax: result string |
| 5914 | // ecx: first character of result |
| 5915 | // edx: first char of first argument |
| 5916 | // edi: length of first argument |
| 5917 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5918 | // Load second argument's length and first character location. Account for |
| 5919 | // values currently on the stack when fetching arguments from it. |
| 5920 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5921 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5922 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5923 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5924 | // eax: result string |
| 5925 | // ecx: next character of result |
| 5926 | // edx: first char of second argument |
| 5927 | // edi: length of second argument |
| 5928 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5929 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5930 | __ ret(2 * kPointerSize); |
| 5931 | |
| 5932 | // Handle creating a flat two byte result. |
| 5933 | // eax: first string - known to be two byte |
| 5934 | // ebx: length of resulting flat string as a smi |
| 5935 | // edx: second string |
| 5936 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5937 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5938 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5939 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5940 | // eax: result string |
| 5941 | __ mov(ecx, eax); |
| 5942 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5943 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5944 | // Load second argument's length and first character location. Account for |
| 5945 | // values currently on the stack when fetching arguments from it. |
| 5946 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5947 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5948 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5949 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5950 | // eax: result string |
| 5951 | // ecx: first character of result |
| 5952 | // edx: first char of first argument |
| 5953 | // edi: length of first argument |
| 5954 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5955 | // Load second argument's length and first character location. Account for |
| 5956 | // values currently on the stack when fetching arguments from it. |
| 5957 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5958 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5959 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5960 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5961 | // eax: result string |
| 5962 | // ecx: next character of result |
| 5963 | // edx: first char of second argument |
| 5964 | // edi: length of second argument |
| 5965 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5966 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5967 | __ ret(2 * kPointerSize); |
| 5968 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5969 | // Recover stack pointer before jumping to runtime. |
| 5970 | __ bind(&call_runtime_drop_two); |
| 5971 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5972 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5973 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5974 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5975 | |
| 5976 | if (call_builtin.is_linked()) { |
| 5977 | __ bind(&call_builtin); |
| 5978 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | |
| 5983 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5984 | int stack_offset, |
| 5985 | Register arg, |
| 5986 | Register scratch1, |
| 5987 | Register scratch2, |
| 5988 | Register scratch3, |
| 5989 | Label* slow) { |
| 5990 | // First check if the argument is already a string. |
| 5991 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5992 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5993 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5994 | __ j(below, &done); |
| 5995 | |
| 5996 | // Check the number to string cache. |
| 5997 | Label not_cached; |
| 5998 | __ bind(¬_string); |
| 5999 | // Puts the cached result into scratch1. |
| 6000 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6001 | arg, |
| 6002 | scratch1, |
| 6003 | scratch2, |
| 6004 | scratch3, |
| 6005 | false, |
| 6006 | ¬_cached); |
| 6007 | __ mov(arg, scratch1); |
| 6008 | __ mov(Operand(esp, stack_offset), arg); |
| 6009 | __ jmp(&done); |
| 6010 | |
| 6011 | // Check if the argument is a safe string wrapper. |
| 6012 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6013 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6014 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6015 | __ j(not_equal, slow); |
| 6016 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6017 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6018 | __ j(zero, slow); |
| 6019 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6020 | __ mov(Operand(esp, stack_offset), arg); |
| 6021 | |
| 6022 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6023 | } |
| 6024 | |
| 6025 | |
| 6026 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6027 | Register dest, |
| 6028 | Register src, |
| 6029 | Register count, |
| 6030 | Register scratch, |
| 6031 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6032 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6033 | __ bind(&loop); |
| 6034 | // This loop just copies one character at a time, as it is only used for very |
| 6035 | // short strings. |
| 6036 | if (ascii) { |
| 6037 | __ mov_b(scratch, Operand(src, 0)); |
| 6038 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6039 | __ add(src, Immediate(1)); |
| 6040 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6041 | } else { |
| 6042 | __ mov_w(scratch, Operand(src, 0)); |
| 6043 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6044 | __ add(src, Immediate(2)); |
| 6045 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6046 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6047 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6048 | __ j(not_zero, &loop); |
| 6049 | } |
| 6050 | |
| 6051 | |
| 6052 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6053 | Register dest, |
| 6054 | Register src, |
| 6055 | Register count, |
| 6056 | Register scratch, |
| 6057 | bool ascii) { |
| 6058 | // Copy characters using rep movs of doublewords. |
| 6059 | // The destination is aligned on a 4 byte boundary because we are |
| 6060 | // copying to the beginning of a newly allocated string. |
| 6061 | ASSERT(dest.is(edi)); // rep movs destination |
| 6062 | ASSERT(src.is(esi)); // rep movs source |
| 6063 | ASSERT(count.is(ecx)); // rep movs count |
| 6064 | ASSERT(!scratch.is(dest)); |
| 6065 | ASSERT(!scratch.is(src)); |
| 6066 | ASSERT(!scratch.is(count)); |
| 6067 | |
| 6068 | // Nothing to do for zero characters. |
| 6069 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6070 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6071 | __ j(zero, &done); |
| 6072 | |
| 6073 | // Make count the number of bytes to copy. |
| 6074 | if (!ascii) { |
| 6075 | __ shl(count, 1); |
| 6076 | } |
| 6077 | |
| 6078 | // 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] | 6079 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6080 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6081 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6082 | |
| 6083 | // Copy from edi to esi using rep movs instruction. |
| 6084 | __ mov(scratch, count); |
| 6085 | __ sar(count, 2); // Number of doublewords to copy. |
| 6086 | __ cld(); |
| 6087 | __ rep_movs(); |
| 6088 | |
| 6089 | // Find number of bytes left. |
| 6090 | __ mov(count, scratch); |
| 6091 | __ and_(count, 3); |
| 6092 | |
| 6093 | // Check if there are more bytes to copy. |
| 6094 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6095 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6096 | __ j(zero, &done); |
| 6097 | |
| 6098 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6099 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6100 | __ bind(&loop); |
| 6101 | __ mov_b(scratch, Operand(src, 0)); |
| 6102 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6103 | __ add(src, Immediate(1)); |
| 6104 | __ add(dest, Immediate(1)); |
| 6105 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6106 | __ j(not_zero, &loop); |
| 6107 | |
| 6108 | __ bind(&done); |
| 6109 | } |
| 6110 | |
| 6111 | |
| 6112 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 6113 | Register c1, |
| 6114 | Register c2, |
| 6115 | Register scratch1, |
| 6116 | Register scratch2, |
| 6117 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6118 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6119 | Label* not_found) { |
| 6120 | // Register scratch3 is the general scratch register in this function. |
| 6121 | Register scratch = scratch3; |
| 6122 | |
| 6123 | // Make sure that both characters are not digits as such strings has a |
| 6124 | // different hash algorithm. Don't try to look for these in the symbol table. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6125 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6126 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6127 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6128 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6129 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6130 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6131 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6132 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6133 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6134 | |
| 6135 | __ bind(¬_array_index); |
| 6136 | // Calculate the two character string hash. |
| 6137 | Register hash = scratch1; |
| 6138 | GenerateHashInit(masm, hash, c1, scratch); |
| 6139 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6140 | GenerateHashGetHash(masm, hash, scratch); |
| 6141 | |
| 6142 | // Collect the two characters in a register. |
| 6143 | Register chars = c1; |
| 6144 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6145 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6146 | |
| 6147 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6148 | // hash: hash of two character string. |
| 6149 | |
| 6150 | // Load the symbol table. |
| 6151 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6152 | ExternalReference roots_array_start = |
| 6153 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6154 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 6155 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6156 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6157 | |
| 6158 | // Calculate capacity mask from the symbol table capacity. |
| 6159 | Register mask = scratch2; |
| 6160 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 6161 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6162 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6163 | |
| 6164 | // Registers |
| 6165 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6166 | // hash: hash of two character string |
| 6167 | // symbol_table: symbol table |
| 6168 | // mask: capacity mask |
| 6169 | // scratch: - |
| 6170 | |
| 6171 | // Perform a number of probes in the symbol table. |
| 6172 | static const int kProbes = 4; |
| 6173 | Label found_in_symbol_table; |
| 6174 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6175 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6176 | for (int i = 0; i < kProbes; i++) { |
| 6177 | // Calculate entry in symbol table. |
| 6178 | __ mov(scratch, hash); |
| 6179 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6180 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6181 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6182 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6183 | |
| 6184 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6185 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6186 | __ mov(candidate, |
| 6187 | FieldOperand(symbol_table, |
| 6188 | scratch, |
| 6189 | times_pointer_size, |
| 6190 | SymbolTable::kElementsStartOffset)); |
| 6191 | |
| 6192 | // 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] | 6193 | Factory* factory = masm->isolate()->factory(); |
| 6194 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6195 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6196 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6197 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6198 | |
| 6199 | // If length is not 2 the string is not a candidate. |
| 6200 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6201 | Immediate(Smi::FromInt(2))); |
| 6202 | __ j(not_equal, &next_probe[i]); |
| 6203 | |
| 6204 | // As we are out of registers save the mask on the stack and use that |
| 6205 | // register as a temporary. |
| 6206 | __ push(mask); |
| 6207 | Register temp = mask; |
| 6208 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6209 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6210 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6211 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6212 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6213 | temp, temp, &next_probe_pop_mask[i]); |
| 6214 | |
| 6215 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6216 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6217 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6218 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6219 | __ j(equal, &found_in_symbol_table); |
| 6220 | __ bind(&next_probe_pop_mask[i]); |
| 6221 | __ pop(mask); |
| 6222 | __ bind(&next_probe[i]); |
| 6223 | } |
| 6224 | |
| 6225 | // No matching 2 character string found by probing. |
| 6226 | __ jmp(not_found); |
| 6227 | |
| 6228 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6229 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6230 | __ bind(&found_in_symbol_table); |
| 6231 | __ pop(mask); // Pop saved mask from the stack. |
| 6232 | if (!result.is(eax)) { |
| 6233 | __ mov(eax, result); |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | |
| 6238 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6239 | Register hash, |
| 6240 | Register character, |
| 6241 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6242 | // hash = (seed + character) + ((seed + character) << 10); |
| 6243 | if (Serializer::enabled()) { |
| 6244 | ExternalReference roots_array_start = |
| 6245 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6246 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6247 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6248 | times_pointer_size, |
| 6249 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6250 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6251 | __ add(scratch, character); |
| 6252 | __ mov(hash, scratch); |
| 6253 | __ shl(scratch, 10); |
| 6254 | __ add(hash, scratch); |
| 6255 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6256 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6257 | __ lea(scratch, Operand(character, seed)); |
| 6258 | __ shl(scratch, 10); |
| 6259 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6260 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6261 | // hash ^= hash >> 6; |
| 6262 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6263 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6264 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | |
| 6268 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6269 | Register hash, |
| 6270 | Register character, |
| 6271 | Register scratch) { |
| 6272 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6273 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | // hash += hash << 10; |
| 6275 | __ mov(scratch, hash); |
| 6276 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6277 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6278 | // hash ^= hash >> 6; |
| 6279 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6280 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6281 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | |
| 6285 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6286 | Register hash, |
| 6287 | Register scratch) { |
| 6288 | // hash += hash << 3; |
| 6289 | __ mov(scratch, hash); |
| 6290 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6291 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6292 | // hash ^= hash >> 11; |
| 6293 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6294 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6295 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6296 | // hash += hash << 15; |
| 6297 | __ mov(scratch, hash); |
| 6298 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6299 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6301 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6302 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6303 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6304 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6305 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6306 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6307 | __ bind(&hash_not_zero); |
| 6308 | } |
| 6309 | |
| 6310 | |
| 6311 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6312 | Label runtime; |
| 6313 | |
| 6314 | // Stack frame on entry. |
| 6315 | // esp[0]: return address |
| 6316 | // esp[4]: to |
| 6317 | // esp[8]: from |
| 6318 | // esp[12]: string |
| 6319 | |
| 6320 | // Make sure first argument is a string. |
| 6321 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6322 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6323 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6324 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6325 | __ j(NegateCondition(is_string), &runtime); |
| 6326 | |
| 6327 | // eax: string |
| 6328 | // ebx: instance type |
| 6329 | |
| 6330 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6331 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6332 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6333 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6334 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6335 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6336 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6337 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6338 | // Shorter than original string's length: an actual substring. |
| 6339 | __ j(below, ¬_original_string, Label::kNear); |
| 6340 | // Longer than original string's length or negative: unsafe arguments. |
| 6341 | __ j(above, &runtime); |
| 6342 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6343 | Counters* counters = masm->isolate()->counters(); |
| 6344 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6345 | __ ret(3 * kPointerSize); |
| 6346 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6347 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6348 | Label single_char; |
| 6349 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6350 | __ j(equal, &single_char); |
| 6351 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6352 | // eax: string |
| 6353 | // ebx: instance type |
| 6354 | // ecx: sub string length (smi) |
| 6355 | // edx: from index (smi) |
| 6356 | // Deal with different string types: update the index if necessary |
| 6357 | // and put the underlying string into edi. |
| 6358 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6359 | // If the string is not indirect, it can only be sequential or external. |
| 6360 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6361 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6362 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6363 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6364 | |
| 6365 | Factory* factory = masm->isolate()->factory(); |
| 6366 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6367 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6368 | // Cons string. Check whether it is flat, then fetch first part. |
| 6369 | // Flat cons strings have an empty second part. |
| 6370 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6371 | factory->empty_string()); |
| 6372 | __ j(not_equal, &runtime); |
| 6373 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6374 | // Update instance type. |
| 6375 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6376 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6377 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6378 | |
| 6379 | __ bind(&sliced_string); |
| 6380 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6381 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6382 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6383 | // Update instance type. |
| 6384 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6385 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6386 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6387 | |
| 6388 | __ bind(&seq_or_external_string); |
| 6389 | // Sequential or external string. Just move string to the expected register. |
| 6390 | __ mov(edi, eax); |
| 6391 | |
| 6392 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6393 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6394 | if (FLAG_string_slices) { |
| 6395 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6396 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6397 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6398 | // edx: adjusted start index (smi) |
| 6399 | // ecx: length (smi) |
| 6400 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6401 | // Short slice. Copy instead of slicing. |
| 6402 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6403 | // Allocate new sliced string. At this point we do not reload the instance |
| 6404 | // type including the string encoding because we simply rely on the info |
| 6405 | // provided by the original string. It does not matter if the original |
| 6406 | // string's encoding is wrong because we always have to recheck encoding of |
| 6407 | // the newly created string's parent anyways due to externalized strings. |
| 6408 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6409 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6410 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6411 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6412 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6413 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6414 | __ jmp(&set_slice_header, Label::kNear); |
| 6415 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6416 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6417 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6418 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6419 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6420 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6421 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6422 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6423 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6424 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6425 | |
| 6426 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6427 | } |
| 6428 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6429 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6430 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6431 | // edx: adjusted start index (smi) |
| 6432 | // ecx: length (smi) |
| 6433 | // The subject string can only be external or sequential string of either |
| 6434 | // encoding at this point. |
| 6435 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6436 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6437 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6438 | __ test_b(ebx, kExternalStringTag); |
| 6439 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6440 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6441 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6442 | // Rule out short external strings. |
| 6443 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6444 | __ test_b(ebx, kShortExternalStringMask); |
| 6445 | __ j(not_zero, &runtime); |
| 6446 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6447 | // 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] | 6448 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6449 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6450 | |
| 6451 | __ bind(&sequential_string); |
| 6452 | // Stash away (adjusted) index and (underlying) string. |
| 6453 | __ push(edx); |
| 6454 | __ push(edi); |
| 6455 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6456 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6457 | __ test_b(ebx, kStringEncodingMask); |
| 6458 | __ j(zero, &two_byte_sequential); |
| 6459 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6460 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6461 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6462 | |
| 6463 | // eax: result string |
| 6464 | // ecx: result string length |
| 6465 | __ mov(edx, esi); // esi used by following code. |
| 6466 | // Locate first character of result. |
| 6467 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6468 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6469 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6470 | __ pop(esi); |
| 6471 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6472 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6473 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6474 | |
| 6475 | // eax: result string |
| 6476 | // ecx: result length |
| 6477 | // edx: original value of esi |
| 6478 | // edi: first character of result |
| 6479 | // esi: character of sub string start |
| 6480 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6481 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6482 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6483 | __ ret(3 * kPointerSize); |
| 6484 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6485 | __ bind(&two_byte_sequential); |
| 6486 | // Sequential two-byte string. Allocate the result. |
| 6487 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6488 | |
| 6489 | // eax: result string |
| 6490 | // ecx: result string length |
| 6491 | __ mov(edx, esi); // esi used by following code. |
| 6492 | // Locate first character of result. |
| 6493 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6494 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6495 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6496 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6497 | __ pop(esi); |
| 6498 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6499 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6500 | // byte character. |
| 6501 | STATIC_ASSERT(kSmiTag == 0); |
| 6502 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6503 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6504 | |
| 6505 | // eax: result string |
| 6506 | // ecx: result length |
| 6507 | // edx: original value of esi |
| 6508 | // edi: first character of result |
| 6509 | // esi: character of sub string start |
| 6510 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6511 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6512 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6513 | __ ret(3 * kPointerSize); |
| 6514 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6515 | // Drop pushed values on the stack before tail call. |
| 6516 | __ bind(&runtime_drop_two); |
| 6517 | __ Drop(2); |
| 6518 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6519 | // Just jump to runtime to create the sub string. |
| 6520 | __ bind(&runtime); |
| 6521 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6522 | |
| 6523 | __ bind(&single_char); |
| 6524 | // eax: string |
| 6525 | // ebx: instance type |
| 6526 | // ecx: sub string length (smi) |
| 6527 | // edx: from index (smi) |
| 6528 | StringCharAtGenerator generator( |
| 6529 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6530 | generator.GenerateFast(masm); |
| 6531 | __ ret(3 * kPointerSize); |
| 6532 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6536 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6537 | Register left, |
| 6538 | Register right, |
| 6539 | Register scratch1, |
| 6540 | Register scratch2) { |
| 6541 | Register length = scratch1; |
| 6542 | |
| 6543 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6544 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6545 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6546 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6547 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6548 | __ bind(&strings_not_equal); |
| 6549 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6550 | __ ret(0); |
| 6551 | |
| 6552 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6553 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6554 | __ bind(&check_zero_length); |
| 6555 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6556 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6557 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6558 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6559 | __ ret(0); |
| 6560 | |
| 6561 | // Compare characters. |
| 6562 | __ bind(&compare_chars); |
| 6563 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6564 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6565 | |
| 6566 | // Characters are equal. |
| 6567 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6568 | __ ret(0); |
| 6569 | } |
| 6570 | |
| 6571 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6572 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6573 | Register left, |
| 6574 | Register right, |
| 6575 | Register scratch1, |
| 6576 | Register scratch2, |
| 6577 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6578 | Counters* counters = masm->isolate()->counters(); |
| 6579 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6580 | |
| 6581 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6582 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6583 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6584 | __ mov(scratch3, scratch1); |
| 6585 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6586 | |
| 6587 | Register length_delta = scratch3; |
| 6588 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6589 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6590 | // 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] | 6591 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6592 | __ bind(&left_shorter); |
| 6593 | |
| 6594 | Register min_length = scratch1; |
| 6595 | |
| 6596 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6597 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6598 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6599 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6600 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6601 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6602 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6603 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6604 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6605 | |
| 6606 | // Compare lengths - strings up to min-length are equal. |
| 6607 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6608 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6609 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6610 | __ j(not_zero, &result_not_equal, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6611 | #else |
| 6612 | Label length_not_equal; |
| 6613 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 6614 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6615 | |
| 6616 | // Result is EQUAL. |
| 6617 | STATIC_ASSERT(EQUAL == 0); |
| 6618 | STATIC_ASSERT(kSmiTag == 0); |
| 6619 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6620 | __ ret(0); |
| 6621 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6622 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6623 | #ifdef ENABLE_LATIN_1 |
| 6624 | Label result_less; |
| 6625 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6626 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6627 | __ jmp(&result_less, Label::kNear); |
| 6628 | #endif |
| 6629 | __ bind(&result_not_equal); |
| 6630 | #ifndef ENABLE_LATIN_1 |
| 6631 | __ j(greater, &result_greater, Label::kNear); |
| 6632 | #else |
| 6633 | __ j(above, &result_greater, Label::kNear); |
| 6634 | __ bind(&result_less); |
| 6635 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6636 | |
| 6637 | // Result is LESS. |
| 6638 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6639 | __ ret(0); |
| 6640 | |
| 6641 | // Result is GREATER. |
| 6642 | __ bind(&result_greater); |
| 6643 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6644 | __ ret(0); |
| 6645 | } |
| 6646 | |
| 6647 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6648 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6649 | MacroAssembler* masm, |
| 6650 | Register left, |
| 6651 | Register right, |
| 6652 | Register length, |
| 6653 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6654 | Label* chars_not_equal, |
| 6655 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6656 | // Change index to run from -length to -1 by adding length to string |
| 6657 | // start. This means that loop ends when index reaches zero, which |
| 6658 | // doesn't need an additional compare. |
| 6659 | __ SmiUntag(length); |
| 6660 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6661 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6662 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6663 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6664 | __ neg(length); |
| 6665 | Register index = length; // index = -length; |
| 6666 | |
| 6667 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6668 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6669 | __ bind(&loop); |
| 6670 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6671 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6672 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6673 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6674 | __ j(not_zero, &loop); |
| 6675 | } |
| 6676 | |
| 6677 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6678 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6679 | Label runtime; |
| 6680 | |
| 6681 | // Stack frame on entry. |
| 6682 | // esp[0]: return address |
| 6683 | // esp[4]: right string |
| 6684 | // esp[8]: left string |
| 6685 | |
| 6686 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6687 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6688 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6689 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6690 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6691 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6692 | STATIC_ASSERT(EQUAL == 0); |
| 6693 | STATIC_ASSERT(kSmiTag == 0); |
| 6694 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6695 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6696 | __ ret(2 * kPointerSize); |
| 6697 | |
| 6698 | __ bind(¬_same); |
| 6699 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6700 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6701 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6702 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6703 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6704 | // Drop arguments from the stack. |
| 6705 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6706 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6707 | __ push(ecx); |
| 6708 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6709 | |
| 6710 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6711 | // tagged as a small integer. |
| 6712 | __ bind(&runtime); |
| 6713 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6714 | } |
| 6715 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6716 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6717 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6718 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6719 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6720 | __ mov(ecx, edx); |
| 6721 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6722 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6723 | |
| 6724 | if (GetCondition() == equal) { |
| 6725 | // 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] | 6726 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6727 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6728 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6729 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6730 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6731 | // Correct sign of result in case of overflow. |
| 6732 | __ not_(edx); |
| 6733 | __ bind(&done); |
| 6734 | __ mov(eax, edx); |
| 6735 | } |
| 6736 | __ ret(0); |
| 6737 | |
| 6738 | __ bind(&miss); |
| 6739 | GenerateMiss(masm); |
| 6740 | } |
| 6741 | |
| 6742 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 6743 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6744 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6745 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6746 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6747 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6748 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6749 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6750 | if (left_ == CompareIC::SMI) { |
| 6751 | __ JumpIfNotSmi(edx, &miss); |
| 6752 | } |
| 6753 | if (right_ == CompareIC::SMI) { |
| 6754 | __ JumpIfNotSmi(eax, &miss); |
| 6755 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6756 | |
| 6757 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6758 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6759 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6760 | CpuFeatures::Scope scope1(SSE2); |
| 6761 | CpuFeatures::Scope scope2(CMOV); |
| 6762 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6763 | // Load left and right operand. |
| 6764 | Label done, left, left_smi, right_smi; |
| 6765 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6766 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6767 | masm->isolate()->factory()->heap_number_map()); |
| 6768 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6769 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6770 | __ jmp(&left, Label::kNear); |
| 6771 | __ bind(&right_smi); |
| 6772 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6773 | __ SmiUntag(ecx); |
| 6774 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6775 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6776 | __ bind(&left); |
| 6777 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6778 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6779 | masm->isolate()->factory()->heap_number_map()); |
| 6780 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6781 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6782 | __ jmp(&done); |
| 6783 | __ bind(&left_smi); |
| 6784 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6785 | __ SmiUntag(ecx); |
| 6786 | __ cvtsi2sd(xmm0, ecx); |
| 6787 | |
| 6788 | __ bind(&done); |
| 6789 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6790 | __ ucomisd(xmm0, xmm1); |
| 6791 | |
| 6792 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6793 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6794 | |
| 6795 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6796 | // Performing mov, because xor would destroy the flag register. |
| 6797 | __ mov(eax, 0); // equal |
| 6798 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6799 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6800 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6801 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6802 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6803 | } else { |
| 6804 | __ mov(ecx, edx); |
| 6805 | __ and_(ecx, eax); |
| 6806 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6807 | |
| 6808 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6809 | masm->isolate()->factory()->heap_number_map()); |
| 6810 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6811 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6812 | masm->isolate()->factory()->heap_number_map()); |
| 6813 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6814 | } |
| 6815 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6816 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6817 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6818 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6819 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 6820 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6821 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6822 | __ bind(&maybe_undefined1); |
| 6823 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6824 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6825 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6826 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6827 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6828 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6829 | __ jmp(&unordered); |
| 6830 | } |
| 6831 | |
| 6832 | __ bind(&maybe_undefined2); |
| 6833 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6834 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6835 | __ j(equal, &unordered); |
| 6836 | } |
| 6837 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6838 | __ bind(&miss); |
| 6839 | GenerateMiss(masm); |
| 6840 | } |
| 6841 | |
| 6842 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6843 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6844 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6845 | ASSERT(GetCondition() == equal); |
| 6846 | |
| 6847 | // Registers containing left and right operands respectively. |
| 6848 | Register left = edx; |
| 6849 | Register right = eax; |
| 6850 | Register tmp1 = ecx; |
| 6851 | Register tmp2 = ebx; |
| 6852 | |
| 6853 | // Check that both operands are heap objects. |
| 6854 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6855 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6856 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6857 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6858 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6859 | |
| 6860 | // Check that both operands are symbols. |
| 6861 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6862 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6863 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6864 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6865 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6866 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6867 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6868 | __ j(zero, &miss, Label::kNear); |
| 6869 | |
| 6870 | // Symbols are compared by identity. |
| 6871 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6872 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6873 | // Make sure eax is non-zero. At this point input operands are |
| 6874 | // guaranteed to be non-zero. |
| 6875 | ASSERT(right.is(eax)); |
| 6876 | __ j(not_equal, &done, Label::kNear); |
| 6877 | STATIC_ASSERT(EQUAL == 0); |
| 6878 | STATIC_ASSERT(kSmiTag == 0); |
| 6879 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6880 | __ bind(&done); |
| 6881 | __ ret(0); |
| 6882 | |
| 6883 | __ bind(&miss); |
| 6884 | GenerateMiss(masm); |
| 6885 | } |
| 6886 | |
| 6887 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6888 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6889 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6890 | Label miss; |
| 6891 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6892 | bool equality = Token::IsEqualityOp(op_); |
| 6893 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6894 | // Registers containing left and right operands respectively. |
| 6895 | Register left = edx; |
| 6896 | Register right = eax; |
| 6897 | Register tmp1 = ecx; |
| 6898 | Register tmp2 = ebx; |
| 6899 | Register tmp3 = edi; |
| 6900 | |
| 6901 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6902 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6903 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6904 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6905 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6906 | |
| 6907 | // Check that both operands are strings. This leaves the instance |
| 6908 | // types loaded in tmp1 and tmp2. |
| 6909 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6910 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6911 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6912 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6913 | __ mov(tmp3, tmp1); |
| 6914 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6915 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6916 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6917 | __ j(not_zero, &miss); |
| 6918 | |
| 6919 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6920 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6921 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6922 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6923 | STATIC_ASSERT(EQUAL == 0); |
| 6924 | STATIC_ASSERT(kSmiTag == 0); |
| 6925 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6926 | __ ret(0); |
| 6927 | |
| 6928 | // Handle not identical strings. |
| 6929 | __ bind(¬_same); |
| 6930 | |
| 6931 | // Check that both strings are symbols. If they are, we're done |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6932 | // because we already know they are not identical. But in the case of |
| 6933 | // non-equality compare, we still need to determine the order. |
| 6934 | if (equality) { |
| 6935 | Label do_compare; |
| 6936 | STATIC_ASSERT(kSymbolTag != 0); |
| 6937 | __ and_(tmp1, tmp2); |
| 6938 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6939 | __ j(zero, &do_compare, Label::kNear); |
| 6940 | // Make sure eax is non-zero. At this point input operands are |
| 6941 | // guaranteed to be non-zero. |
| 6942 | ASSERT(right.is(eax)); |
| 6943 | __ ret(0); |
| 6944 | __ bind(&do_compare); |
| 6945 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6946 | |
| 6947 | // Check that both strings are sequential ASCII. |
| 6948 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6949 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6950 | |
| 6951 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6952 | if (equality) { |
| 6953 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6954 | masm, left, right, tmp1, tmp2); |
| 6955 | } else { |
| 6956 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6957 | masm, left, right, tmp1, tmp2, tmp3); |
| 6958 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6959 | |
| 6960 | // Handle more complex cases in runtime. |
| 6961 | __ bind(&runtime); |
| 6962 | __ pop(tmp1); // Return address. |
| 6963 | __ push(left); |
| 6964 | __ push(right); |
| 6965 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6966 | if (equality) { |
| 6967 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6968 | } else { |
| 6969 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6970 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6971 | |
| 6972 | __ bind(&miss); |
| 6973 | GenerateMiss(masm); |
| 6974 | } |
| 6975 | |
| 6976 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6977 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6978 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6979 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6980 | __ mov(ecx, edx); |
| 6981 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6982 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6983 | |
| 6984 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6985 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6986 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6987 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6988 | |
| 6989 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6990 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6991 | __ ret(0); |
| 6992 | |
| 6993 | __ bind(&miss); |
| 6994 | GenerateMiss(masm); |
| 6995 | } |
| 6996 | |
| 6997 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6998 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6999 | Label miss; |
| 7000 | __ mov(ecx, edx); |
| 7001 | __ and_(ecx, eax); |
| 7002 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7003 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7004 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7005 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7006 | __ cmp(ecx, known_map_); |
| 7007 | __ j(not_equal, &miss, Label::kNear); |
| 7008 | __ cmp(ebx, known_map_); |
| 7009 | __ j(not_equal, &miss, Label::kNear); |
| 7010 | |
| 7011 | __ sub(eax, edx); |
| 7012 | __ ret(0); |
| 7013 | |
| 7014 | __ bind(&miss); |
| 7015 | GenerateMiss(masm); |
| 7016 | } |
| 7017 | |
| 7018 | |
| 7019 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7020 | { |
| 7021 | // Call the runtime system in a fresh internal frame. |
| 7022 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7023 | masm->isolate()); |
| 7024 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7025 | __ push(edx); // Preserve edx and eax. |
| 7026 | __ push(eax); |
| 7027 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7028 | __ push(eax); |
| 7029 | __ push(Immediate(Smi::FromInt(op_))); |
| 7030 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7031 | // Compute the entry point of the rewritten stub. |
| 7032 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7033 | __ pop(eax); |
| 7034 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7035 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7036 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7037 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7038 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7042 | // Helper function used to check that the dictionary doesn't contain |
| 7043 | // the property. This function may return false negatives, so miss_label |
| 7044 | // must always call a backup property check that is complete. |
| 7045 | // This function is safe to call if the receiver has fast properties. |
| 7046 | // Name must be a symbol and receiver must be a heap object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7047 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7048 | Label* miss, |
| 7049 | Label* done, |
| 7050 | Register properties, |
| 7051 | Handle<String> name, |
| 7052 | Register r0) { |
| 7053 | ASSERT(name->IsSymbol()); |
| 7054 | |
| 7055 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7056 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7057 | // undefined value), it guarantees the hash table doesn't contain the |
| 7058 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7059 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7060 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7061 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7062 | Register index = r0; |
| 7063 | // Capacity is smi 2^n. |
| 7064 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7065 | __ dec(index); |
| 7066 | __ and_(index, |
| 7067 | Immediate(Smi::FromInt(name->Hash() + |
| 7068 | StringDictionary::GetProbeOffset(i)))); |
| 7069 | |
| 7070 | // Scale the index by multiplying by the entry size. |
| 7071 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7072 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7073 | Register entity_name = r0; |
| 7074 | // Having undefined at this place means the name is not contained. |
| 7075 | ASSERT_EQ(kSmiTagSize, 1); |
| 7076 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7077 | kElementsStartOffset - kHeapObjectTag)); |
| 7078 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7079 | __ j(equal, done); |
| 7080 | |
| 7081 | // Stop if found the property. |
| 7082 | __ cmp(entity_name, Handle<String>(name)); |
| 7083 | __ j(equal, miss); |
| 7084 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7085 | Label the_hole; |
| 7086 | // Check for the hole and skip. |
| 7087 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 7088 | __ j(equal, &the_hole, Label::kNear); |
| 7089 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7090 | // Check if the entry name is not a symbol. |
| 7091 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7092 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7093 | kIsSymbolMask); |
| 7094 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7095 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | StringDictionaryLookupStub stub(properties, |
| 7099 | r0, |
| 7100 | r0, |
| 7101 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 7102 | __ push(Immediate(Handle<Object>(name))); |
| 7103 | __ push(Immediate(name->Hash())); |
| 7104 | __ CallStub(&stub); |
| 7105 | __ test(r0, r0); |
| 7106 | __ j(not_zero, miss); |
| 7107 | __ jmp(done); |
| 7108 | } |
| 7109 | |
| 7110 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7111 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7112 | // |done| label if a property with the given name is found leaving the |
| 7113 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7114 | // otherwise. |
| 7115 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7116 | Label* miss, |
| 7117 | Label* done, |
| 7118 | Register elements, |
| 7119 | Register name, |
| 7120 | Register r0, |
| 7121 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7122 | ASSERT(!elements.is(r0)); |
| 7123 | ASSERT(!elements.is(r1)); |
| 7124 | ASSERT(!name.is(r0)); |
| 7125 | ASSERT(!name.is(r1)); |
| 7126 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7127 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7128 | |
| 7129 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7130 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7131 | __ dec(r1); |
| 7132 | |
| 7133 | // Generate an unrolled loop that performs a few probes before |
| 7134 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7135 | // cover ~93% of loads from dictionaries. |
| 7136 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7137 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7138 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7139 | __ shr(r0, String::kHashShift); |
| 7140 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7141 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7142 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7143 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7144 | |
| 7145 | // Scale the index by multiplying by the entry size. |
| 7146 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7147 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7148 | |
| 7149 | // Check if the key is identical to the name. |
| 7150 | __ cmp(name, Operand(elements, |
| 7151 | r0, |
| 7152 | times_4, |
| 7153 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7154 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | StringDictionaryLookupStub stub(elements, |
| 7158 | r1, |
| 7159 | r0, |
| 7160 | POSITIVE_LOOKUP); |
| 7161 | __ push(name); |
| 7162 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7163 | __ shr(r0, String::kHashShift); |
| 7164 | __ push(r0); |
| 7165 | __ CallStub(&stub); |
| 7166 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7167 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7168 | __ j(zero, miss); |
| 7169 | __ jmp(done); |
| 7170 | } |
| 7171 | |
| 7172 | |
| 7173 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7174 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7175 | // 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] | 7176 | // Stack frame on entry: |
| 7177 | // esp[0 * kPointerSize]: return address. |
| 7178 | // esp[1 * kPointerSize]: key's hash. |
| 7179 | // esp[2 * kPointerSize]: key. |
| 7180 | // Registers: |
| 7181 | // dictionary_: StringDictionary to probe. |
| 7182 | // result_: used as scratch. |
| 7183 | // index_: will hold an index of entry if lookup is successful. |
| 7184 | // might alias with result_. |
| 7185 | // Returns: |
| 7186 | // result_ is zero if lookup failed, non zero otherwise. |
| 7187 | |
| 7188 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7189 | |
| 7190 | Register scratch = result_; |
| 7191 | |
| 7192 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7193 | __ dec(scratch); |
| 7194 | __ SmiUntag(scratch); |
| 7195 | __ push(scratch); |
| 7196 | |
| 7197 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7198 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7199 | // undefined value), it guarantees the hash table doesn't contain the |
| 7200 | // property. It's true even if some slots represent deleted properties |
| 7201 | // (their names are the null value). |
| 7202 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7203 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7204 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7205 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7206 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7207 | } |
| 7208 | __ and_(scratch, Operand(esp, 0)); |
| 7209 | |
| 7210 | // Scale the index by multiplying by the entry size. |
| 7211 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7212 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7213 | |
| 7214 | // Having undefined at this place means the name is not contained. |
| 7215 | ASSERT_EQ(kSmiTagSize, 1); |
| 7216 | __ mov(scratch, Operand(dictionary_, |
| 7217 | index_, |
| 7218 | times_pointer_size, |
| 7219 | kElementsStartOffset - kHeapObjectTag)); |
| 7220 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7221 | __ j(equal, ¬_in_dictionary); |
| 7222 | |
| 7223 | // Stop if found the property. |
| 7224 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7225 | __ j(equal, &in_dictionary); |
| 7226 | |
| 7227 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7228 | // If we hit a non symbol key during negative lookup |
| 7229 | // we have to bailout as this key might be equal to the |
| 7230 | // key we are looking for. |
| 7231 | |
| 7232 | // Check if the entry name is not a symbol. |
| 7233 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7234 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7235 | kIsSymbolMask); |
| 7236 | __ j(zero, &maybe_in_dictionary); |
| 7237 | } |
| 7238 | } |
| 7239 | |
| 7240 | __ bind(&maybe_in_dictionary); |
| 7241 | // If we are doing negative lookup then probing failure should be |
| 7242 | // treated as a lookup success. For positive lookup probing failure |
| 7243 | // should be treated as lookup failure. |
| 7244 | if (mode_ == POSITIVE_LOOKUP) { |
| 7245 | __ mov(result_, Immediate(0)); |
| 7246 | __ Drop(1); |
| 7247 | __ ret(2 * kPointerSize); |
| 7248 | } |
| 7249 | |
| 7250 | __ bind(&in_dictionary); |
| 7251 | __ mov(result_, Immediate(1)); |
| 7252 | __ Drop(1); |
| 7253 | __ ret(2 * kPointerSize); |
| 7254 | |
| 7255 | __ bind(¬_in_dictionary); |
| 7256 | __ mov(result_, Immediate(0)); |
| 7257 | __ Drop(1); |
| 7258 | __ ret(2 * kPointerSize); |
| 7259 | } |
| 7260 | |
| 7261 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7262 | struct AheadOfTimeWriteBarrierStubList { |
| 7263 | Register object, value, address; |
| 7264 | RememberedSetAction action; |
| 7265 | }; |
| 7266 | |
| 7267 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7268 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7269 | |
| 7270 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7271 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7272 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7273 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7274 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7275 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7276 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7277 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7278 | // Used in StoreStubCompiler::CompileStoreField and |
| 7279 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7280 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7281 | // GenerateStoreField calls the stub with two different permutations of |
| 7282 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7283 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7284 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7285 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7286 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7287 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7288 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7289 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7290 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7291 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7292 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7293 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7294 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7295 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7296 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7297 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7298 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7299 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7300 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7301 | // FastNewClosureStub |
| 7302 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7303 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7304 | { 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] | 7305 | }; |
| 7306 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7307 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7308 | |
| 7309 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7310 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7311 | !entry->object.is(no_reg); |
| 7312 | entry++) { |
| 7313 | if (object_.is(entry->object) && |
| 7314 | value_.is(entry->value) && |
| 7315 | address_.is(entry->address) && |
| 7316 | remembered_set_action_ == entry->action && |
| 7317 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7318 | return true; |
| 7319 | } |
| 7320 | } |
| 7321 | return false; |
| 7322 | } |
| 7323 | |
| 7324 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7325 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7326 | Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7327 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7328 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7329 | |
| 7330 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7331 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7332 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7333 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7334 | } |
| 7335 | } |
| 7336 | |
| 7337 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7338 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7339 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7340 | !entry->object.is(no_reg); |
| 7341 | entry++) { |
| 7342 | RecordWriteStub stub(entry->object, |
| 7343 | entry->value, |
| 7344 | entry->address, |
| 7345 | entry->action, |
| 7346 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7347 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7348 | } |
| 7349 | } |
| 7350 | |
| 7351 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7352 | bool CodeStub::CanUseFPRegisters() { |
| 7353 | return CpuFeatures::IsSupported(SSE2); |
| 7354 | } |
| 7355 | |
| 7356 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7357 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7358 | // the value has just been written into the object, now this stub makes sure |
| 7359 | // we keep the GC informed. The word in the object where the value has been |
| 7360 | // written is in the address register. |
| 7361 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7362 | Label skip_to_incremental_noncompacting; |
| 7363 | Label skip_to_incremental_compacting; |
| 7364 | |
| 7365 | // The first two instructions are generated with labels so as to get the |
| 7366 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7367 | // forth between a compare instructions (a nop in this position) and the |
| 7368 | // real branch when we start and stop incremental heap marking. |
| 7369 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7370 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7371 | |
| 7372 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7373 | __ RememberedSetHelper(object_, |
| 7374 | address_, |
| 7375 | value_, |
| 7376 | save_fp_regs_mode_, |
| 7377 | MacroAssembler::kReturnAtEnd); |
| 7378 | } else { |
| 7379 | __ ret(0); |
| 7380 | } |
| 7381 | |
| 7382 | __ bind(&skip_to_incremental_noncompacting); |
| 7383 | GenerateIncremental(masm, INCREMENTAL); |
| 7384 | |
| 7385 | __ bind(&skip_to_incremental_compacting); |
| 7386 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7387 | |
| 7388 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7389 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7390 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7391 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7392 | } |
| 7393 | |
| 7394 | |
| 7395 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7396 | regs_.Save(masm); |
| 7397 | |
| 7398 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7399 | Label dont_need_remembered_set; |
| 7400 | |
| 7401 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7402 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7403 | regs_.scratch0(), |
| 7404 | &dont_need_remembered_set); |
| 7405 | |
| 7406 | __ CheckPageFlag(regs_.object(), |
| 7407 | regs_.scratch0(), |
| 7408 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7409 | not_zero, |
| 7410 | &dont_need_remembered_set); |
| 7411 | |
| 7412 | // First notify the incremental marker if necessary, then update the |
| 7413 | // remembered set. |
| 7414 | CheckNeedsToInformIncrementalMarker( |
| 7415 | masm, |
| 7416 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7417 | mode); |
| 7418 | InformIncrementalMarker(masm, mode); |
| 7419 | regs_.Restore(masm); |
| 7420 | __ RememberedSetHelper(object_, |
| 7421 | address_, |
| 7422 | value_, |
| 7423 | save_fp_regs_mode_, |
| 7424 | MacroAssembler::kReturnAtEnd); |
| 7425 | |
| 7426 | __ bind(&dont_need_remembered_set); |
| 7427 | } |
| 7428 | |
| 7429 | CheckNeedsToInformIncrementalMarker( |
| 7430 | masm, |
| 7431 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7432 | mode); |
| 7433 | InformIncrementalMarker(masm, mode); |
| 7434 | regs_.Restore(masm); |
| 7435 | __ ret(0); |
| 7436 | } |
| 7437 | |
| 7438 | |
| 7439 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7440 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7441 | int argument_count = 3; |
| 7442 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7443 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7444 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7445 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7446 | Immediate(ExternalReference::isolate_address())); |
| 7447 | |
| 7448 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7449 | if (mode == INCREMENTAL_COMPACTION) { |
| 7450 | __ CallCFunction( |
| 7451 | ExternalReference::incremental_evacuation_record_write_function( |
| 7452 | masm->isolate()), |
| 7453 | argument_count); |
| 7454 | } else { |
| 7455 | ASSERT(mode == INCREMENTAL); |
| 7456 | __ CallCFunction( |
| 7457 | ExternalReference::incremental_marking_record_write_function( |
| 7458 | masm->isolate()), |
| 7459 | argument_count); |
| 7460 | } |
| 7461 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7462 | } |
| 7463 | |
| 7464 | |
| 7465 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7466 | MacroAssembler* masm, |
| 7467 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7468 | Mode mode) { |
| 7469 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7470 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7471 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7472 | __ and_(regs_.scratch0(), regs_.object()); |
| 7473 | __ mov(regs_.scratch1(), |
| 7474 | Operand(regs_.scratch0(), |
| 7475 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7476 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7477 | __ mov(Operand(regs_.scratch0(), |
| 7478 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7479 | regs_.scratch1()); |
| 7480 | __ j(negative, &need_incremental); |
| 7481 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7482 | // Let's look at the color of the object: If it is not black we don't have |
| 7483 | // to inform the incremental marker. |
| 7484 | __ JumpIfBlack(regs_.object(), |
| 7485 | regs_.scratch0(), |
| 7486 | regs_.scratch1(), |
| 7487 | &object_is_black, |
| 7488 | Label::kNear); |
| 7489 | |
| 7490 | regs_.Restore(masm); |
| 7491 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7492 | __ RememberedSetHelper(object_, |
| 7493 | address_, |
| 7494 | value_, |
| 7495 | save_fp_regs_mode_, |
| 7496 | MacroAssembler::kReturnAtEnd); |
| 7497 | } else { |
| 7498 | __ ret(0); |
| 7499 | } |
| 7500 | |
| 7501 | __ bind(&object_is_black); |
| 7502 | |
| 7503 | // Get the value from the slot. |
| 7504 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7505 | |
| 7506 | if (mode == INCREMENTAL_COMPACTION) { |
| 7507 | Label ensure_not_white; |
| 7508 | |
| 7509 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7510 | regs_.scratch1(), // Scratch. |
| 7511 | MemoryChunk::kEvacuationCandidateMask, |
| 7512 | zero, |
| 7513 | &ensure_not_white, |
| 7514 | Label::kNear); |
| 7515 | |
| 7516 | __ CheckPageFlag(regs_.object(), |
| 7517 | regs_.scratch1(), // Scratch. |
| 7518 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7519 | not_zero, |
| 7520 | &ensure_not_white, |
| 7521 | Label::kNear); |
| 7522 | |
| 7523 | __ jmp(&need_incremental); |
| 7524 | |
| 7525 | __ bind(&ensure_not_white); |
| 7526 | } |
| 7527 | |
| 7528 | // We need an extra register for this, so we push the object register |
| 7529 | // temporarily. |
| 7530 | __ push(regs_.object()); |
| 7531 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7532 | regs_.scratch1(), // Scratch. |
| 7533 | regs_.object(), // Scratch. |
| 7534 | &need_incremental_pop_object, |
| 7535 | Label::kNear); |
| 7536 | __ pop(regs_.object()); |
| 7537 | |
| 7538 | regs_.Restore(masm); |
| 7539 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7540 | __ RememberedSetHelper(object_, |
| 7541 | address_, |
| 7542 | value_, |
| 7543 | save_fp_regs_mode_, |
| 7544 | MacroAssembler::kReturnAtEnd); |
| 7545 | } else { |
| 7546 | __ ret(0); |
| 7547 | } |
| 7548 | |
| 7549 | __ bind(&need_incremental_pop_object); |
| 7550 | __ pop(regs_.object()); |
| 7551 | |
| 7552 | __ bind(&need_incremental); |
| 7553 | |
| 7554 | // Fall through when we need to inform the incremental marker. |
| 7555 | } |
| 7556 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7557 | |
| 7558 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7559 | // ----------- S t a t e ------------- |
| 7560 | // -- eax : element value to store |
| 7561 | // -- ebx : array literal |
| 7562 | // -- edi : map of array literal |
| 7563 | // -- ecx : element index as smi |
| 7564 | // -- edx : array literal index in function |
| 7565 | // -- esp[0] : return address |
| 7566 | // ----------------------------------- |
| 7567 | |
| 7568 | Label element_done; |
| 7569 | Label double_elements; |
| 7570 | Label smi_element; |
| 7571 | Label slow_elements; |
| 7572 | Label slow_elements_from_double; |
| 7573 | Label fast_elements; |
| 7574 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7575 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7576 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7577 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7578 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7579 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7580 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7581 | // Store into the array literal requires a elements transition. Call into |
| 7582 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7583 | |
| 7584 | __ bind(&slow_elements); |
| 7585 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7586 | // call. |
| 7587 | __ push(ebx); |
| 7588 | __ push(ecx); |
| 7589 | __ push(eax); |
| 7590 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7591 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7592 | __ push(edx); |
| 7593 | __ push(edi); // Return return address so that tail call returns to right |
| 7594 | // place. |
| 7595 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7596 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7597 | __ bind(&slow_elements_from_double); |
| 7598 | __ pop(edx); |
| 7599 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7600 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7601 | // 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] | 7602 | __ bind(&fast_elements); |
| 7603 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7604 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7605 | FixedArrayBase::kHeaderSize)); |
| 7606 | __ mov(Operand(ecx, 0), eax); |
| 7607 | // Update the write barrier for the array store. |
| 7608 | __ RecordWrite(ebx, ecx, eax, |
| 7609 | kDontSaveFPRegs, |
| 7610 | EMIT_REMEMBERED_SET, |
| 7611 | OMIT_SMI_CHECK); |
| 7612 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7613 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7614 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7615 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7616 | __ bind(&smi_element); |
| 7617 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7618 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7619 | FixedArrayBase::kHeaderSize), eax); |
| 7620 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7621 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7622 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7623 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7624 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7625 | __ push(edx); |
| 7626 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7627 | __ StoreNumberToDoubleElements(eax, |
| 7628 | edx, |
| 7629 | ecx, |
| 7630 | edi, |
| 7631 | xmm0, |
| 7632 | &slow_elements_from_double, |
| 7633 | false); |
| 7634 | __ pop(edx); |
| 7635 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7636 | } |
| 7637 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7638 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7639 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7640 | ASSERT(!Serializer::enabled()); |
| 7641 | bool save_fp_regs = CpuFeatures::IsSupported(SSE2); |
| 7642 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame^] | 7643 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7644 | int parameter_count_offset = |
| 7645 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7646 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7647 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7648 | __ pop(ecx); |
| 7649 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, |
| 7650 | extra_expression_stack_count_ * kPointerSize)); |
| 7651 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7652 | } |
| 7653 | |
| 7654 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7655 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7656 | if (entry_hook_ != NULL) { |
| 7657 | ProfileEntryHookStub stub; |
| 7658 | masm->CallStub(&stub); |
| 7659 | } |
| 7660 | } |
| 7661 | |
| 7662 | |
| 7663 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7664 | // Ecx is the only volatile register we must save. |
| 7665 | __ push(ecx); |
| 7666 | |
| 7667 | // Calculate and push the original stack pointer. |
| 7668 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7669 | __ push(eax); |
| 7670 | |
| 7671 | // Calculate and push the function address. |
| 7672 | __ mov(eax, Operand(eax, 0)); |
| 7673 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7674 | __ push(eax); |
| 7675 | |
| 7676 | // Call the entry hook. |
| 7677 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7678 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7679 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7680 | |
| 7681 | // Restore ecx. |
| 7682 | __ pop(ecx); |
| 7683 | __ ret(0); |
| 7684 | } |
| 7685 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7686 | #undef __ |
| 7687 | |
| 7688 | } } // namespace v8::internal |
| 7689 | |
| 7690 | #endif // V8_TARGET_ARCH_IA32 |