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 | |
| 45 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 46 | Isolate* isolate, |
| 47 | CodeStubInterfaceDescriptor* descriptor) { |
| 48 | static Register registers[] = { edx, ecx }; |
| 49 | descriptor->register_param_count_ = 2; |
| 50 | descriptor->register_params_ = registers; |
| 51 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 52 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 56 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 57 | Isolate* isolate, |
| 58 | CodeStubInterfaceDescriptor* descriptor) { |
| 59 | static Register registers[] = { eax, ebx }; |
| 60 | descriptor->register_param_count_ = 2; |
| 61 | descriptor->register_params_ = registers; |
| 62 | descriptor->deoptimization_handler_ = |
| 63 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 64 | } |
| 65 | |
| 66 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 67 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 68 | |
| 69 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 70 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 71 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 72 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 73 | __ ret(0); |
| 74 | |
| 75 | __ bind(&check_heap_number); |
| 76 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 77 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 78 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 79 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 80 | __ ret(0); |
| 81 | |
| 82 | __ bind(&call_builtin); |
| 83 | __ pop(ecx); // Pop return address. |
| 84 | __ push(eax); |
| 85 | __ push(ecx); // Push return address. |
| 86 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 87 | } |
| 88 | |
| 89 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 90 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 91 | // Create a new closure from the given function info in new |
| 92 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 93 | Counters* counters = masm->isolate()->counters(); |
| 94 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 95 | Label gc; |
| 96 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 97 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 98 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 99 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 100 | // Get the function info from the stack. |
| 101 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 102 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 103 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 104 | ? Context::FUNCTION_MAP_INDEX |
| 105 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 106 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 107 | // 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] | 108 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 109 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 110 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 111 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 112 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 113 | |
| 114 | // Initialize the rest of the function. We don't have to update the |
| 115 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 116 | Factory* factory = masm->isolate()->factory(); |
| 117 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 118 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 119 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 120 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 121 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 122 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 123 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 124 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 125 | |
| 126 | // Initialize the code pointer in the function to be the one |
| 127 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 128 | // But first check if there is an optimized version for our context. |
| 129 | Label check_optimized; |
| 130 | Label install_unoptimized; |
| 131 | if (FLAG_cache_optimized_code) { |
| 132 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 133 | __ test(ebx, ebx); |
| 134 | __ j(not_zero, &check_optimized, Label::kNear); |
| 135 | } |
| 136 | __ bind(&install_unoptimized); |
| 137 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 138 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 139 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 140 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 141 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 142 | |
| 143 | // Return and remove the on-stack parameter. |
| 144 | __ ret(1 * kPointerSize); |
| 145 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 146 | __ bind(&check_optimized); |
| 147 | |
| 148 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 149 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 150 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 151 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 152 | // Map must never be empty, so check the first elements. |
| 153 | Label install_optimized; |
| 154 | // Speculatively move code object into edx. |
| 155 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 156 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 157 | __ j(equal, &install_optimized); |
| 158 | |
| 159 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 160 | Label loop; |
| 161 | Label restore; |
| 162 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 163 | __ bind(&loop); |
| 164 | // Do not double check first entry. |
| 165 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 166 | __ j(equal, &restore); |
| 167 | __ sub(edx, Immediate(Smi::FromInt( |
| 168 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 169 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 170 | __ j(not_equal, &loop, Label::kNear); |
| 171 | // Hit: fetch the optimized code. |
| 172 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 173 | |
| 174 | __ bind(&install_optimized); |
| 175 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 176 | |
| 177 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 178 | // map and either unmangle them on marking or do nothing as the whole map is |
| 179 | // discarded on major GC anyway. |
| 180 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 181 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 182 | |
| 183 | // Now link a function into a list of optimized functions. |
| 184 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 185 | |
| 186 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 187 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 188 | |
| 189 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 190 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 191 | // it clobbers all the registers passed. |
| 192 | __ mov(edx, eax); |
| 193 | __ RecordWriteContextSlot( |
| 194 | ecx, |
| 195 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 196 | edx, |
| 197 | ebx, |
| 198 | kDontSaveFPRegs); |
| 199 | |
| 200 | // Return and remove the on-stack parameter. |
| 201 | __ ret(1 * kPointerSize); |
| 202 | |
| 203 | __ bind(&restore); |
| 204 | // Restore SharedFunctionInfo into edx. |
| 205 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 206 | __ jmp(&install_unoptimized); |
| 207 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 208 | // Create a new closure through the slower runtime call. |
| 209 | __ bind(&gc); |
| 210 | __ pop(ecx); // Temporarily remove return address. |
| 211 | __ pop(edx); |
| 212 | __ push(esi); |
| 213 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 214 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 215 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 216 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 221 | // Try to allocate the context in new space. |
| 222 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 223 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 224 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 225 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 226 | |
| 227 | // Get the function from the stack. |
| 228 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 229 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 230 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 231 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 232 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 233 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 234 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 235 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 236 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 237 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 238 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 239 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 240 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 241 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 242 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 243 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 244 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 245 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 246 | |
| 247 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 248 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 249 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 250 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 251 | } |
| 252 | |
| 253 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 254 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 255 | __ ret(1 * kPointerSize); |
| 256 | |
| 257 | // Need to collect. Call into runtime system. |
| 258 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 259 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 263 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 264 | // Stack layout on entry: |
| 265 | // |
| 266 | // [esp + (1 * kPointerSize)]: function |
| 267 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 268 | |
| 269 | // Try to allocate the context in new space. |
| 270 | Label gc; |
| 271 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 272 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 273 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 274 | |
| 275 | // Get the function or sentinel from the stack. |
| 276 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 277 | |
| 278 | // Get the serialized scope info from the stack. |
| 279 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 280 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 281 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 282 | Factory* factory = masm->isolate()->factory(); |
| 283 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 284 | factory->block_context_map()); |
| 285 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 286 | Immediate(Smi::FromInt(length))); |
| 287 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 288 | // 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] | 289 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 290 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 291 | // we still have to look up. |
| 292 | Label after_sentinel; |
| 293 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 294 | if (FLAG_debug_code) { |
| 295 | const char* message = "Expected 0 as a Smi sentinel"; |
| 296 | __ cmp(ecx, 0); |
| 297 | __ Assert(equal, message); |
| 298 | } |
| 299 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 300 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 301 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 302 | __ bind(&after_sentinel); |
| 303 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 304 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 305 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 306 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 307 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 308 | |
| 309 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 310 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 311 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 312 | |
| 313 | // Initialize the rest of the slots to the hole value. |
| 314 | if (slots_ == 1) { |
| 315 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 316 | factory->the_hole_value()); |
| 317 | } else { |
| 318 | __ mov(ebx, factory->the_hole_value()); |
| 319 | for (int i = 0; i < slots_; i++) { |
| 320 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // Return and remove the on-stack parameters. |
| 325 | __ mov(esi, eax); |
| 326 | __ ret(2 * kPointerSize); |
| 327 | |
| 328 | // Need to collect. Call into runtime system. |
| 329 | __ bind(&gc); |
| 330 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 331 | } |
| 332 | |
| 333 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 334 | static void GenerateFastCloneShallowArrayCommon( |
| 335 | MacroAssembler* masm, |
| 336 | int length, |
| 337 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 338 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 339 | Label* fail) { |
| 340 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 341 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 342 | // ecx: boilerplate literal array. |
| 343 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 344 | |
| 345 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 346 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 347 | if (length > 0) { |
| 348 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 349 | ? FixedDoubleArray::SizeFor(length) |
| 350 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 351 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 352 | int size = JSArray::kSize; |
| 353 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 354 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 355 | size += AllocationSiteInfo::kSize; |
| 356 | } |
| 357 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 358 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 359 | // Allocate both the JS array and the elements array in one big |
| 360 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 361 | AllocationFlags flags = TAG_OBJECT; |
| 362 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 363 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 364 | } |
| 365 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 366 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 367 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 368 | __ mov(FieldOperand(eax, allocation_info_start), |
| 369 | Immediate(Handle<Map>(masm->isolate()->heap()-> |
| 370 | allocation_site_info_map()))); |
| 371 | __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); |
| 372 | } |
| 373 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 374 | // Copy the JS array part. |
| 375 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 376 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 377 | __ mov(ebx, FieldOperand(ecx, i)); |
| 378 | __ mov(FieldOperand(eax, i), ebx); |
| 379 | } |
| 380 | } |
| 381 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 382 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 383 | // Get hold of the elements array of the boilerplate and setup the |
| 384 | // elements pointer in the resulting object. |
| 385 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 386 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 387 | __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 388 | } else { |
| 389 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 390 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 391 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 392 | |
| 393 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 394 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 395 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 396 | __ mov(ebx, FieldOperand(ecx, i)); |
| 397 | __ mov(FieldOperand(edx, i), ebx); |
| 398 | } |
| 399 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 400 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 401 | int i; |
| 402 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 403 | __ mov(ebx, FieldOperand(ecx, i)); |
| 404 | __ mov(FieldOperand(edx, i), ebx); |
| 405 | } |
| 406 | while (i < elements_size) { |
| 407 | __ fld_d(FieldOperand(ecx, i)); |
| 408 | __ fstp_d(FieldOperand(edx, i)); |
| 409 | i += kDoubleSize; |
| 410 | } |
| 411 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 414 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 415 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 416 | |
| 417 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 418 | // Stack layout on entry: |
| 419 | // |
| 420 | // [esp + kPointerSize]: constant elements. |
| 421 | // [esp + (2 * kPointerSize)]: literal index. |
| 422 | // [esp + (3 * kPointerSize)]: literals array. |
| 423 | |
| 424 | // Load boilerplate object into ecx and check if we need to create a |
| 425 | // boilerplate. |
| 426 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 427 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 428 | STATIC_ASSERT(kPointerSize == 4); |
| 429 | STATIC_ASSERT(kSmiTagSize == 1); |
| 430 | STATIC_ASSERT(kSmiTag == 0); |
| 431 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 432 | FixedArray::kHeaderSize)); |
| 433 | Factory* factory = masm->isolate()->factory(); |
| 434 | __ cmp(ecx, factory->undefined_value()); |
| 435 | Label slow_case; |
| 436 | __ j(equal, &slow_case); |
| 437 | |
| 438 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 439 | // ecx is boilerplate object. |
| 440 | if (mode == CLONE_ANY_ELEMENTS) { |
| 441 | Label double_elements, check_fast_elements; |
| 442 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 443 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 444 | &check_fast_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 445 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 446 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 447 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 448 | __ ret(3 * kPointerSize); |
| 449 | |
| 450 | __ bind(&check_fast_elements); |
| 451 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 452 | &double_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 453 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 454 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 455 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 456 | __ ret(3 * kPointerSize); |
| 457 | |
| 458 | __ bind(&double_elements); |
| 459 | mode = CLONE_DOUBLE_ELEMENTS; |
| 460 | // Fall through to generate the code to handle double elements. |
| 461 | } |
| 462 | |
| 463 | if (FLAG_debug_code) { |
| 464 | const char* message; |
| 465 | Handle<Map> expected_map; |
| 466 | if (mode == CLONE_ELEMENTS) { |
| 467 | message = "Expected (writable) fixed array"; |
| 468 | expected_map = factory->fixed_array_map(); |
| 469 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 470 | message = "Expected (writable) fixed double array"; |
| 471 | expected_map = factory->fixed_double_array_map(); |
| 472 | } else { |
| 473 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 474 | message = "Expected copy-on-write fixed array"; |
| 475 | expected_map = factory->fixed_cow_array_map(); |
| 476 | } |
| 477 | __ push(ecx); |
| 478 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 479 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 480 | __ Assert(equal, message); |
| 481 | __ pop(ecx); |
| 482 | } |
| 483 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 484 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 485 | allocation_site_mode_, |
| 486 | &slow_case); |
| 487 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 488 | // Return and remove the on-stack parameters. |
| 489 | __ ret(3 * kPointerSize); |
| 490 | |
| 491 | __ bind(&slow_case); |
| 492 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 493 | } |
| 494 | |
| 495 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 496 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 497 | // Stack layout on entry: |
| 498 | // |
| 499 | // [esp + kPointerSize]: object literal flags. |
| 500 | // [esp + (2 * kPointerSize)]: constant properties. |
| 501 | // [esp + (3 * kPointerSize)]: literal index. |
| 502 | // [esp + (4 * kPointerSize)]: literals array. |
| 503 | |
| 504 | // Load boilerplate object into ecx and check if we need to create a |
| 505 | // boilerplate. |
| 506 | Label slow_case; |
| 507 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 508 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 509 | STATIC_ASSERT(kPointerSize == 4); |
| 510 | STATIC_ASSERT(kSmiTagSize == 1); |
| 511 | STATIC_ASSERT(kSmiTag == 0); |
| 512 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 513 | FixedArray::kHeaderSize)); |
| 514 | Factory* factory = masm->isolate()->factory(); |
| 515 | __ cmp(ecx, factory->undefined_value()); |
| 516 | __ j(equal, &slow_case); |
| 517 | |
| 518 | // Check that the boilerplate contains only fast properties and we can |
| 519 | // statically determine the instance size. |
| 520 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 521 | __ mov(eax, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 522 | __ movzx_b(eax, FieldOperand(eax, Map::kInstanceSizeOffset)); |
| 523 | __ cmp(eax, Immediate(size >> kPointerSizeLog2)); |
| 524 | __ j(not_equal, &slow_case); |
| 525 | |
| 526 | // Allocate the JS object and copy header together with all in-object |
| 527 | // properties from the boilerplate. |
| 528 | __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); |
| 529 | for (int i = 0; i < size; i += kPointerSize) { |
| 530 | __ mov(ebx, FieldOperand(ecx, i)); |
| 531 | __ mov(FieldOperand(eax, i), ebx); |
| 532 | } |
| 533 | |
| 534 | // Return and remove the on-stack parameters. |
| 535 | __ ret(4 * kPointerSize); |
| 536 | |
| 537 | __ bind(&slow_case); |
| 538 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 539 | } |
| 540 | |
| 541 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 542 | // The stub expects its argument on the stack and returns its result in tos_: |
| 543 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 544 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 545 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 546 | // 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] | 547 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 548 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 549 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 550 | const Register map = edx; |
| 551 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 552 | if (!types_.IsEmpty()) { |
| 553 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 554 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 555 | |
| 556 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 557 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 558 | |
| 559 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 560 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 561 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 562 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 563 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 564 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 565 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 566 | if (types_.Contains(SMI)) { |
| 567 | // Smis: 0 -> false, all other -> true |
| 568 | Label not_smi; |
| 569 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 570 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 571 | if (!tos_.is(argument)) { |
| 572 | __ mov(tos_, argument); |
| 573 | } |
| 574 | __ ret(1 * kPointerSize); |
| 575 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 576 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 577 | // If we need a map later and have a Smi -> patch. |
| 578 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 579 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 580 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 581 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 582 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 583 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 584 | if (types_.CanBeUndetectable()) { |
| 585 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 586 | 1 << Map::kIsUndetectable); |
| 587 | // Undetectable -> false. |
| 588 | Label not_undetectable; |
| 589 | __ j(zero, ¬_undetectable, Label::kNear); |
| 590 | __ Set(tos_, Immediate(0)); |
| 591 | __ ret(1 * kPointerSize); |
| 592 | __ bind(¬_undetectable); |
| 593 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 594 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 595 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 596 | if (types_.Contains(SPEC_OBJECT)) { |
| 597 | // spec object -> true. |
| 598 | Label not_js_object; |
| 599 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 600 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 601 | // argument contains the correct return value already. |
| 602 | if (!tos_.is(argument)) { |
| 603 | __ Set(tos_, Immediate(1)); |
| 604 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 605 | __ ret(1 * kPointerSize); |
| 606 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 607 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 608 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 609 | if (types_.Contains(STRING)) { |
| 610 | // String value -> false iff empty. |
| 611 | Label not_string; |
| 612 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 613 | __ j(above_equal, ¬_string, Label::kNear); |
| 614 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 615 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 616 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (types_.Contains(HEAP_NUMBER)) { |
| 620 | // heap number -> false iff +0, -0, or NaN. |
| 621 | Label not_heap_number, false_result; |
| 622 | __ cmp(map, factory->heap_number_map()); |
| 623 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 624 | __ fldz(); |
| 625 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 626 | __ FCmp(); |
| 627 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 628 | // argument contains the correct return value already. |
| 629 | if (!tos_.is(argument)) { |
| 630 | __ Set(tos_, Immediate(1)); |
| 631 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 632 | __ ret(1 * kPointerSize); |
| 633 | __ bind(&false_result); |
| 634 | __ Set(tos_, Immediate(0)); |
| 635 | __ ret(1 * kPointerSize); |
| 636 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 637 | } |
| 638 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 639 | __ bind(&patch); |
| 640 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 644 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 645 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 646 | // store the registers in any particular way, but we do have to store and |
| 647 | // restore them. |
| 648 | __ pushad(); |
| 649 | if (save_doubles_ == kSaveFPRegs) { |
| 650 | CpuFeatures::Scope scope(SSE2); |
| 651 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 652 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 653 | XMMRegister reg = XMMRegister::from_code(i); |
| 654 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 655 | } |
| 656 | } |
| 657 | const int argument_count = 1; |
| 658 | |
| 659 | AllowExternalCallThatCantCauseGC scope(masm); |
| 660 | __ PrepareCallCFunction(argument_count, ecx); |
| 661 | __ mov(Operand(esp, 0 * kPointerSize), |
| 662 | Immediate(ExternalReference::isolate_address())); |
| 663 | __ CallCFunction( |
| 664 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 665 | argument_count); |
| 666 | if (save_doubles_ == kSaveFPRegs) { |
| 667 | CpuFeatures::Scope scope(SSE2); |
| 668 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 669 | XMMRegister reg = XMMRegister::from_code(i); |
| 670 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 671 | } |
| 672 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 673 | } |
| 674 | __ popad(); |
| 675 | __ ret(0); |
| 676 | } |
| 677 | |
| 678 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 679 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 680 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 681 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 682 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 683 | const Register argument = eax; |
| 684 | if (types_.Contains(type)) { |
| 685 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 686 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 687 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 688 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 689 | if (!result) { |
| 690 | // If we have to return zero, there is no way around clearing tos_. |
| 691 | __ Set(tos_, Immediate(0)); |
| 692 | } else if (!tos_.is(argument)) { |
| 693 | // If we have to return non-zero, we can re-use the argument if it is the |
| 694 | // same register as the result, because we never see Smi-zero here. |
| 695 | __ Set(tos_, Immediate(1)); |
| 696 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 697 | __ ret(1 * kPointerSize); |
| 698 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| 702 | |
| 703 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 704 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 705 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 706 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 707 | __ push(ecx); // Push return address. |
| 708 | // Patch the caller to an appropriate specialized stub and return the |
| 709 | // operation result to the caller of the stub. |
| 710 | __ TailCallExternalReference( |
| 711 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 712 | 3, |
| 713 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 717 | class FloatingPointHelper : public AllStatic { |
| 718 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 719 | enum ArgLocation { |
| 720 | ARGS_ON_STACK, |
| 721 | ARGS_IN_REGISTERS |
| 722 | }; |
| 723 | |
| 724 | // Code pattern for loading a floating point value. Input value must |
| 725 | // be either a smi or a heap number object (fp value). Requirements: |
| 726 | // operand in register number. Returns operand as floating point number |
| 727 | // on FPU stack. |
| 728 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 729 | |
| 730 | // Code pattern for loading floating point values. Input values must |
| 731 | // be either smi or heap number objects (fp values). Requirements: |
| 732 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 733 | // Returns operands as floating point numbers on FPU stack. |
| 734 | static void LoadFloatOperands(MacroAssembler* masm, |
| 735 | Register scratch, |
| 736 | ArgLocation arg_location = ARGS_ON_STACK); |
| 737 | |
| 738 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 739 | // Expects operands in edx, eax. |
| 740 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 741 | |
| 742 | // Test if operands are smi or number objects (fp). Requirements: |
| 743 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 744 | // operands, jumps to the non_float label otherwise. |
| 745 | static void CheckFloatOperands(MacroAssembler* masm, |
| 746 | Label* non_float, |
| 747 | Register scratch); |
| 748 | |
| 749 | // Takes the operands in edx and eax and loads them as integers in eax |
| 750 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 751 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 752 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 753 | BinaryOpIC::TypeInfo left_type, |
| 754 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 755 | Label* operand_conversion_failure); |
| 756 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 757 | // Assumes that operands are smis or heap numbers and loads them |
| 758 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 759 | // Leaves operands unchanged. |
| 760 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 761 | |
| 762 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 763 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 764 | // either operand is not a number. Operands are in edx and eax. |
| 765 | // Leaves operands unchanged. |
| 766 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 767 | |
| 768 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 769 | // Expects operands in edx, eax. |
| 770 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 771 | |
| 772 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 773 | // have int32 values. |
| 774 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 775 | Label* non_int32, |
| 776 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 777 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 778 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 779 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 780 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 781 | Label* non_int32, |
| 782 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 783 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 784 | Register scratch, |
| 785 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 786 | }; |
| 787 | |
| 788 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 789 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 790 | // is faster than using the built-in instructions on floating point registers. |
| 791 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 792 | // trashed registers. |
| 793 | static void IntegerConvert(MacroAssembler* masm, |
| 794 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 795 | bool use_sse3, |
| 796 | Label* conversion_failure) { |
| 797 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 798 | Label done, right_exponent, normal_exponent; |
| 799 | Register scratch = ebx; |
| 800 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 801 | // Get exponent word. |
| 802 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 803 | // Get exponent alone in scratch2. |
| 804 | __ mov(scratch2, scratch); |
| 805 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 806 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 807 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 808 | // Load ecx with zero. We use this either for the final shift or |
| 809 | // for the answer. |
| 810 | __ xor_(ecx, ecx); |
| 811 | // If the exponent is above 83, the number contains no significant |
| 812 | // bits in the range 0..2^31, so the result is zero. |
| 813 | static const uint32_t kResultIsZeroExponent = 83; |
| 814 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 815 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 816 | if (use_sse3) { |
| 817 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 818 | // 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] | 819 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 820 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 821 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 822 | // Load x87 register with heap number. |
| 823 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 824 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 825 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 826 | // Do conversion, which cannot fail because we checked the exponent. |
| 827 | __ fisttp_d(Operand(esp, 0)); |
| 828 | __ 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] | 829 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 830 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 831 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 832 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 833 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 834 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 835 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 836 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 837 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 838 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 839 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | // If the exponent is higher than that then go to slow case. This catches |
| 841 | // 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] | 842 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 843 | |
| 844 | { |
| 845 | // Handle a big exponent. The only reason we have this code is that the |
| 846 | // >>> 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] | 847 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 848 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 849 | __ j(not_equal, conversion_failure); |
| 850 | // We have the big exponent, typically from >>>. This means the number is |
| 851 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 852 | __ mov(scratch2, scratch); |
| 853 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 854 | // Put back the implicit 1. |
| 855 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 856 | // Shift up the mantissa bits to take up the space the exponent used to |
| 857 | // take. We just orred in the implicit bit so that took care of one and |
| 858 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 859 | // shift distance. |
| 860 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 861 | __ shl(scratch2, big_shift_distance); |
| 862 | // Get the second half of the double. |
| 863 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 864 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 865 | // mantissa word. |
| 866 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 867 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 868 | // 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] | 869 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 870 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 871 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 872 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 876 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 877 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 878 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 879 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 880 | |
| 881 | __ bind(&right_exponent); |
| 882 | // Here ecx is the shift, scratch is the exponent word. |
| 883 | // Get the top bits of the mantissa. |
| 884 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 885 | // Put back the implicit 1. |
| 886 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 887 | // Shift up the mantissa bits to take up the space the exponent used to |
| 888 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 889 | // word. Shift them to the top bits. |
| 890 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 891 | __ shl(scratch, shift_distance); |
| 892 | // Get the second half of the double. For some exponents we don't |
| 893 | // actually need this because the bits get shifted out again, but |
| 894 | // it's probably slower to test than just to do it. |
| 895 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 896 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 897 | // mantissa word. |
| 898 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 899 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 900 | // Move down according to the exponent. |
| 901 | __ shr_cl(scratch2); |
| 902 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 903 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 904 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 905 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 906 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 907 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 908 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 909 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 910 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 911 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 912 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 913 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 917 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 918 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 919 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 920 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 921 | Register source, |
| 922 | Label* conversion_failure) { |
| 923 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 924 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 925 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 926 | } |
| 927 | |
| 928 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 929 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 930 | const char* op_name = Token::Name(op_); |
| 931 | const char* overwrite_name = NULL; // Make g++ happy. |
| 932 | switch (mode_) { |
| 933 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 934 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 935 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 936 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 937 | op_name, |
| 938 | overwrite_name, |
| 939 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | |
| 943 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 944 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 945 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 946 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 947 | GenerateTypeTransition(masm); |
| 948 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 949 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 950 | GenerateSmiStub(masm); |
| 951 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 952 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 953 | GenerateHeapNumberStub(masm); |
| 954 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 955 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 956 | GenerateGenericStub(masm); |
| 957 | break; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 962 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 963 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 964 | |
| 965 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 966 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 967 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 968 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 969 | |
| 970 | __ push(ecx); // Push return address. |
| 971 | |
| 972 | // Patch the caller to an appropriate specialized stub and return the |
| 973 | // operation result to the caller of the stub. |
| 974 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 975 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
| 979 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 980 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 981 | switch (op_) { |
| 982 | case Token::SUB: |
| 983 | GenerateSmiStubSub(masm); |
| 984 | break; |
| 985 | case Token::BIT_NOT: |
| 986 | GenerateSmiStubBitNot(masm); |
| 987 | break; |
| 988 | default: |
| 989 | UNREACHABLE(); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 994 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 995 | Label non_smi, undo, slow; |
| 996 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 997 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 998 | __ bind(&undo); |
| 999 | GenerateSmiCodeUndo(masm); |
| 1000 | __ bind(&non_smi); |
| 1001 | __ bind(&slow); |
| 1002 | GenerateTypeTransition(masm); |
| 1003 | } |
| 1004 | |
| 1005 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1006 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1007 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1008 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1009 | __ bind(&non_smi); |
| 1010 | GenerateTypeTransition(masm); |
| 1011 | } |
| 1012 | |
| 1013 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1014 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 1015 | Label* non_smi, |
| 1016 | Label* undo, |
| 1017 | Label* slow, |
| 1018 | Label::Distance non_smi_near, |
| 1019 | Label::Distance undo_near, |
| 1020 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1021 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1022 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1023 | |
| 1024 | // 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] | 1025 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1026 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1027 | |
| 1028 | // 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] | 1029 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1030 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1031 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1032 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1033 | __ ret(0); |
| 1034 | } |
| 1035 | |
| 1036 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1037 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1038 | MacroAssembler* masm, |
| 1039 | Label* non_smi, |
| 1040 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1041 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1042 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1043 | |
| 1044 | // Flip bits and revert inverted smi-tag. |
| 1045 | __ not_(eax); |
| 1046 | __ and_(eax, ~kSmiTagMask); |
| 1047 | __ ret(0); |
| 1048 | } |
| 1049 | |
| 1050 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1051 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1052 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1057 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1058 | switch (op_) { |
| 1059 | case Token::SUB: |
| 1060 | GenerateHeapNumberStubSub(masm); |
| 1061 | break; |
| 1062 | case Token::BIT_NOT: |
| 1063 | GenerateHeapNumberStubBitNot(masm); |
| 1064 | break; |
| 1065 | default: |
| 1066 | UNREACHABLE(); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1071 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1072 | Label non_smi, undo, slow, call_builtin; |
| 1073 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1074 | __ bind(&non_smi); |
| 1075 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1076 | __ bind(&undo); |
| 1077 | GenerateSmiCodeUndo(masm); |
| 1078 | __ bind(&slow); |
| 1079 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1080 | __ bind(&call_builtin); |
| 1081 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1085 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1086 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1087 | Label non_smi, slow; |
| 1088 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1089 | __ bind(&non_smi); |
| 1090 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1091 | __ bind(&slow); |
| 1092 | GenerateTypeTransition(masm); |
| 1093 | } |
| 1094 | |
| 1095 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1096 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1097 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1098 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1099 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1100 | __ j(not_equal, slow); |
| 1101 | |
| 1102 | if (mode_ == UNARY_OVERWRITE) { |
| 1103 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1104 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1105 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1106 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1107 | // edx: operand |
| 1108 | |
| 1109 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1110 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1111 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1112 | |
| 1113 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1114 | { |
| 1115 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1116 | __ push(edx); |
| 1117 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1118 | __ pop(edx); |
| 1119 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1120 | |
| 1121 | __ bind(&heapnumber_allocated); |
| 1122 | // eax: allocated 'empty' number |
| 1123 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1124 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1125 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1126 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1127 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1128 | } |
| 1129 | __ ret(0); |
| 1130 | } |
| 1131 | |
| 1132 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1133 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1134 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1135 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1136 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1137 | __ j(not_equal, slow); |
| 1138 | |
| 1139 | // 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] | 1140 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1141 | |
| 1142 | // 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] | 1143 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1144 | __ not_(ecx); |
| 1145 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1146 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Tag the result as a smi and we're done. |
| 1149 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1150 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1151 | __ ret(0); |
| 1152 | |
| 1153 | // Try to store the result in a heap number. |
| 1154 | __ bind(&try_float); |
| 1155 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1156 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1157 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1158 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1159 | __ jmp(&heapnumber_allocated); |
| 1160 | |
| 1161 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1162 | { |
| 1163 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1164 | // Push the original HeapNumber on the stack. The integer value can't |
| 1165 | // be stored since it's untagged and not in the smi range (so we can't |
| 1166 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1167 | __ push(ebx); |
| 1168 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1169 | // New HeapNumber is in eax. |
| 1170 | __ pop(edx); |
| 1171 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1172 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1173 | // This conversion won't go slow-case. |
| 1174 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1175 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1176 | |
| 1177 | __ bind(&heapnumber_allocated); |
| 1178 | } |
| 1179 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1180 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1181 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1182 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1183 | } else { |
| 1184 | __ push(ecx); |
| 1185 | __ fild_s(Operand(esp, 0)); |
| 1186 | __ pop(ecx); |
| 1187 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1188 | } |
| 1189 | __ ret(0); |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1194 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1195 | switch (op_) { |
| 1196 | case Token::SUB: |
| 1197 | GenerateGenericStubSub(masm); |
| 1198 | break; |
| 1199 | case Token::BIT_NOT: |
| 1200 | GenerateGenericStubBitNot(masm); |
| 1201 | break; |
| 1202 | default: |
| 1203 | UNREACHABLE(); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1208 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1209 | Label non_smi, undo, slow; |
| 1210 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1211 | __ bind(&non_smi); |
| 1212 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1213 | __ bind(&undo); |
| 1214 | GenerateSmiCodeUndo(masm); |
| 1215 | __ bind(&slow); |
| 1216 | GenerateGenericCodeFallback(masm); |
| 1217 | } |
| 1218 | |
| 1219 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1220 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1221 | Label non_smi, slow; |
| 1222 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1223 | __ bind(&non_smi); |
| 1224 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1225 | __ bind(&slow); |
| 1226 | GenerateGenericCodeFallback(masm); |
| 1227 | } |
| 1228 | |
| 1229 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1230 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1231 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1232 | __ pop(ecx); // pop return address. |
| 1233 | __ push(eax); |
| 1234 | __ push(ecx); // push return address |
| 1235 | switch (op_) { |
| 1236 | case Token::SUB: |
| 1237 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1238 | break; |
| 1239 | case Token::BIT_NOT: |
| 1240 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1241 | break; |
| 1242 | default: |
| 1243 | UNREACHABLE(); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1248 | void BinaryOpStub::Initialize() { |
| 1249 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1250 | } |
| 1251 | |
| 1252 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1253 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1254 | __ pop(ecx); // Save return address. |
| 1255 | __ push(edx); |
| 1256 | __ push(eax); |
| 1257 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1258 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1259 | |
| 1260 | __ push(ecx); // Push return address. |
| 1261 | |
| 1262 | // Patch the caller to an appropriate specialized stub and return the |
| 1263 | // operation result to the caller of the stub. |
| 1264 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1265 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1266 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1267 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | 1); |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | // Prepare for a type transition runtime call when the args are already on |
| 1273 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1274 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1275 | __ pop(ecx); // Save return address. |
| 1276 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1277 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1278 | |
| 1279 | __ push(ecx); // Push return address. |
| 1280 | |
| 1281 | // Patch the caller to an appropriate specialized stub and return the |
| 1282 | // operation result to the caller of the stub. |
| 1283 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1284 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1285 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1286 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1287 | 1); |
| 1288 | } |
| 1289 | |
| 1290 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1291 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1292 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1294 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1295 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1296 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1297 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1298 | Comment load_comment(masm, "-- Load arguments"); |
| 1299 | Register left = edx; |
| 1300 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1301 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1302 | left = eax; |
| 1303 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1304 | __ mov(ebx, eax); |
| 1305 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | // 2. Prepare the smi check of both operands by oring them together. |
| 1310 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1311 | Label not_smis; |
| 1312 | Register combined = ecx; |
| 1313 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1314 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1315 | case Token::BIT_OR: |
| 1316 | // Perform the operation into eax and smi check the result. Preserve |
| 1317 | // eax in case the result is not a smi. |
| 1318 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1319 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1320 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1321 | combined = right; |
| 1322 | break; |
| 1323 | |
| 1324 | case Token::BIT_XOR: |
| 1325 | case Token::BIT_AND: |
| 1326 | case Token::ADD: |
| 1327 | case Token::SUB: |
| 1328 | case Token::MUL: |
| 1329 | case Token::DIV: |
| 1330 | case Token::MOD: |
| 1331 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1332 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1333 | break; |
| 1334 | |
| 1335 | case Token::SHL: |
| 1336 | case Token::SAR: |
| 1337 | case Token::SHR: |
| 1338 | // Move the right operand into ecx for the shift operation, use eax |
| 1339 | // for the smi check register. |
| 1340 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1341 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1342 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1343 | combined = right; |
| 1344 | break; |
| 1345 | |
| 1346 | default: |
| 1347 | break; |
| 1348 | } |
| 1349 | |
| 1350 | // 3. Perform the smi check of the operands. |
| 1351 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1352 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1353 | |
| 1354 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1355 | // eax and check the result if necessary. |
| 1356 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1357 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1358 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1359 | case Token::BIT_OR: |
| 1360 | // Nothing to do. |
| 1361 | break; |
| 1362 | |
| 1363 | case Token::BIT_XOR: |
| 1364 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1365 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | |
| 1368 | case Token::BIT_AND: |
| 1369 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1370 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | |
| 1373 | case Token::SHL: |
| 1374 | // Remove tags from operands (but keep sign). |
| 1375 | __ SmiUntag(left); |
| 1376 | __ SmiUntag(ecx); |
| 1377 | // Perform the operation. |
| 1378 | __ shl_cl(left); |
| 1379 | // Check that the *signed* result fits in a smi. |
| 1380 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1381 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1382 | // Tag the result and store it in register eax. |
| 1383 | __ SmiTag(left); |
| 1384 | __ mov(eax, left); |
| 1385 | break; |
| 1386 | |
| 1387 | case Token::SAR: |
| 1388 | // Remove tags from operands (but keep sign). |
| 1389 | __ SmiUntag(left); |
| 1390 | __ SmiUntag(ecx); |
| 1391 | // Perform the operation. |
| 1392 | __ sar_cl(left); |
| 1393 | // Tag the result and store it in register eax. |
| 1394 | __ SmiTag(left); |
| 1395 | __ mov(eax, left); |
| 1396 | break; |
| 1397 | |
| 1398 | case Token::SHR: |
| 1399 | // Remove tags from operands (but keep sign). |
| 1400 | __ SmiUntag(left); |
| 1401 | __ SmiUntag(ecx); |
| 1402 | // Perform the operation. |
| 1403 | __ shr_cl(left); |
| 1404 | // Check that the *unsigned* result fits in a smi. |
| 1405 | // Neither of the two high-order bits can be set: |
| 1406 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1407 | // - 0x40000000: this number would convert to negative when |
| 1408 | // Smi tagging these two cases can only happen with shifts |
| 1409 | // by 0 or 1 when handed a valid smi. |
| 1410 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1411 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1412 | // Tag the result and store it in register eax. |
| 1413 | __ SmiTag(left); |
| 1414 | __ mov(eax, left); |
| 1415 | break; |
| 1416 | |
| 1417 | case Token::ADD: |
| 1418 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1419 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1420 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1424 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1425 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1426 | __ mov(eax, left); |
| 1427 | break; |
| 1428 | |
| 1429 | case Token::MUL: |
| 1430 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1431 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1432 | // We can't revert the multiplication if the result is not a smi |
| 1433 | // so save the right operand. |
| 1434 | __ mov(ebx, right); |
| 1435 | // Remove tag from one of the operands (but keep sign). |
| 1436 | __ SmiUntag(right); |
| 1437 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1438 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1439 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1440 | // Check for negative zero result. Use combined = left | right. |
| 1441 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1442 | break; |
| 1443 | |
| 1444 | case Token::DIV: |
| 1445 | // We can't revert the division if the result is not a smi so |
| 1446 | // save the left operand. |
| 1447 | __ mov(edi, left); |
| 1448 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1449 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1450 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1451 | // Sign extend left into edx:eax. |
| 1452 | ASSERT(left.is(eax)); |
| 1453 | __ cdq(); |
| 1454 | // Divide edx:eax by right. |
| 1455 | __ idiv(right); |
| 1456 | // Check for the corner case of dividing the most negative smi by |
| 1457 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1458 | // instruction. |
| 1459 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1460 | __ cmp(eax, 0x40000000); |
| 1461 | __ j(equal, &use_fp_on_smis); |
| 1462 | // Check for negative zero result. Use combined = left | right. |
| 1463 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1464 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1465 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1466 | __ j(not_zero, &use_fp_on_smis); |
| 1467 | // Tag the result and store it in register eax. |
| 1468 | __ SmiTag(eax); |
| 1469 | break; |
| 1470 | |
| 1471 | case Token::MOD: |
| 1472 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1473 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1474 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | |
| 1476 | // Sign extend left into edx:eax. |
| 1477 | ASSERT(left.is(eax)); |
| 1478 | __ cdq(); |
| 1479 | // Divide edx:eax by right. |
| 1480 | __ idiv(right); |
| 1481 | // Check for negative zero result. Use combined = left | right. |
| 1482 | __ NegativeZeroTest(edx, combined, slow); |
| 1483 | // Move remainder to register eax. |
| 1484 | __ mov(eax, edx); |
| 1485 | break; |
| 1486 | |
| 1487 | default: |
| 1488 | UNREACHABLE(); |
| 1489 | } |
| 1490 | |
| 1491 | // 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] | 1492 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1493 | case Token::ADD: |
| 1494 | case Token::SUB: |
| 1495 | case Token::MUL: |
| 1496 | case Token::DIV: |
| 1497 | __ ret(0); |
| 1498 | break; |
| 1499 | case Token::MOD: |
| 1500 | case Token::BIT_OR: |
| 1501 | case Token::BIT_AND: |
| 1502 | case Token::BIT_XOR: |
| 1503 | case Token::SAR: |
| 1504 | case Token::SHL: |
| 1505 | case Token::SHR: |
| 1506 | __ ret(2 * kPointerSize); |
| 1507 | break; |
| 1508 | default: |
| 1509 | UNREACHABLE(); |
| 1510 | } |
| 1511 | |
| 1512 | // 6. For some operations emit inline code to perform floating point |
| 1513 | // operations on known smis (e.g., if the result of the operation |
| 1514 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1515 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1516 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1517 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1518 | // Undo the effects of some operations, and some register moves. |
| 1519 | case Token::SHL: |
| 1520 | // The arguments are saved on the stack, and only used from there. |
| 1521 | break; |
| 1522 | case Token::ADD: |
| 1523 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1524 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1525 | break; |
| 1526 | case Token::SUB: |
| 1527 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1528 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1529 | break; |
| 1530 | case Token::MUL: |
| 1531 | // Right was clobbered but a copy is in ebx. |
| 1532 | __ mov(right, ebx); |
| 1533 | break; |
| 1534 | case Token::DIV: |
| 1535 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1536 | // division. They should be in eax, ebx for jump to not_smi. |
| 1537 | __ mov(eax, edi); |
| 1538 | break; |
| 1539 | default: |
| 1540 | // No other operators jump to use_fp_on_smis. |
| 1541 | break; |
| 1542 | } |
| 1543 | __ jmp(¬_smis); |
| 1544 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1545 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1546 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1547 | case Token::SHL: |
| 1548 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1549 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1550 | __ bind(&use_fp_on_smis); |
| 1551 | // Result we want is in left == edx, so we can put the allocated heap |
| 1552 | // number in eax. |
| 1553 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1554 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1555 | // It's OK to overwrite the arguments on the stack because we |
| 1556 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1557 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1558 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1559 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1560 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1561 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1562 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1563 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1564 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1565 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1566 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1567 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1568 | } else { |
| 1569 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1570 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1571 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1572 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1573 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1574 | __ ret(2 * kPointerSize); |
| 1575 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | case Token::ADD: |
| 1579 | case Token::SUB: |
| 1580 | case Token::MUL: |
| 1581 | case Token::DIV: { |
| 1582 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1583 | __ bind(&use_fp_on_smis); |
| 1584 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1585 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1586 | case Token::ADD: |
| 1587 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1588 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1589 | break; |
| 1590 | case Token::SUB: |
| 1591 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1592 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1593 | break; |
| 1594 | case Token::MUL: |
| 1595 | // Right was clobbered but a copy is in ebx. |
| 1596 | __ mov(right, ebx); |
| 1597 | break; |
| 1598 | case Token::DIV: |
| 1599 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1600 | // division. |
| 1601 | __ mov(edx, edi); |
| 1602 | __ mov(eax, right); |
| 1603 | break; |
| 1604 | default: UNREACHABLE(); |
| 1605 | break; |
| 1606 | } |
| 1607 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1608 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1609 | CpuFeatures::Scope use_sse2(SSE2); |
| 1610 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1611 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1612 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1613 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1614 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1615 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1616 | default: UNREACHABLE(); |
| 1617 | } |
| 1618 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1619 | } else { // SSE2 not available, use FPU. |
| 1620 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1621 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1622 | case Token::ADD: __ faddp(1); break; |
| 1623 | case Token::SUB: __ fsubp(1); break; |
| 1624 | case Token::MUL: __ fmulp(1); break; |
| 1625 | case Token::DIV: __ fdivp(1); break; |
| 1626 | default: UNREACHABLE(); |
| 1627 | } |
| 1628 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1629 | } |
| 1630 | __ mov(eax, ecx); |
| 1631 | __ ret(0); |
| 1632 | break; |
| 1633 | } |
| 1634 | |
| 1635 | default: |
| 1636 | break; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1641 | // edx and eax. |
| 1642 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1643 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1644 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1645 | case Token::BIT_OR: |
| 1646 | case Token::SHL: |
| 1647 | case Token::SAR: |
| 1648 | case Token::SHR: |
| 1649 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1650 | // check. |
| 1651 | __ mov(eax, ecx); |
| 1652 | break; |
| 1653 | |
| 1654 | case Token::DIV: |
| 1655 | case Token::MOD: |
| 1656 | // Operands are in eax, ebx at this point. |
| 1657 | __ mov(edx, eax); |
| 1658 | __ mov(eax, ebx); |
| 1659 | break; |
| 1660 | |
| 1661 | default: |
| 1662 | break; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1667 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1668 | Label call_runtime; |
| 1669 | |
| 1670 | switch (op_) { |
| 1671 | case Token::ADD: |
| 1672 | case Token::SUB: |
| 1673 | case Token::MUL: |
| 1674 | case Token::DIV: |
| 1675 | break; |
| 1676 | case Token::MOD: |
| 1677 | case Token::BIT_OR: |
| 1678 | case Token::BIT_AND: |
| 1679 | case Token::BIT_XOR: |
| 1680 | case Token::SAR: |
| 1681 | case Token::SHL: |
| 1682 | case Token::SHR: |
| 1683 | GenerateRegisterArgsPush(masm); |
| 1684 | break; |
| 1685 | default: |
| 1686 | UNREACHABLE(); |
| 1687 | } |
| 1688 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1689 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1690 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1691 | BinaryOpStub_GenerateSmiCode( |
| 1692 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1693 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1694 | BinaryOpStub_GenerateSmiCode( |
| 1695 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1696 | } |
| 1697 | __ bind(&call_runtime); |
| 1698 | switch (op_) { |
| 1699 | case Token::ADD: |
| 1700 | case Token::SUB: |
| 1701 | case Token::MUL: |
| 1702 | case Token::DIV: |
| 1703 | GenerateTypeTransition(masm); |
| 1704 | break; |
| 1705 | case Token::MOD: |
| 1706 | case Token::BIT_OR: |
| 1707 | case Token::BIT_AND: |
| 1708 | case Token::BIT_XOR: |
| 1709 | case Token::SAR: |
| 1710 | case Token::SHL: |
| 1711 | case Token::SHR: |
| 1712 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1713 | break; |
| 1714 | default: |
| 1715 | UNREACHABLE(); |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1720 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1721 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1722 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1723 | ASSERT(op_ == Token::ADD); |
| 1724 | // If both arguments are strings, call the string add stub. |
| 1725 | // Otherwise, do a transition. |
| 1726 | |
| 1727 | // Registers containing left and right operands respectively. |
| 1728 | Register left = edx; |
| 1729 | Register right = eax; |
| 1730 | |
| 1731 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1732 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1733 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1734 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1735 | |
| 1736 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1737 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1738 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1739 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1740 | |
| 1741 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1742 | GenerateRegisterArgsPush(masm); |
| 1743 | __ TailCallStub(&string_add_stub); |
| 1744 | |
| 1745 | __ bind(&call_runtime); |
| 1746 | GenerateTypeTransition(masm); |
| 1747 | } |
| 1748 | |
| 1749 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1750 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1751 | Label* alloc_failure, |
| 1752 | OverwriteMode mode); |
| 1753 | |
| 1754 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1755 | // Input: |
| 1756 | // edx: left operand (tagged) |
| 1757 | // eax: right operand (tagged) |
| 1758 | // Output: |
| 1759 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1760 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1761 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1762 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | |
| 1764 | // Floating point case. |
| 1765 | switch (op_) { |
| 1766 | case Token::ADD: |
| 1767 | case Token::SUB: |
| 1768 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1769 | case Token::DIV: |
| 1770 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1771 | Label not_floats; |
| 1772 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1773 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1774 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1775 | // It could be that only SMIs have been seen at either the left |
| 1776 | // or the right operand. For precise type feedback, patch the IC |
| 1777 | // again if this changes. |
| 1778 | // In theory, we would need the same check in the non-SSE2 case, |
| 1779 | // but since we don't support Crankshaft on such hardware we can |
| 1780 | // afford not to care about precise type feedback. |
| 1781 | if (left_type_ == BinaryOpIC::SMI) { |
| 1782 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1783 | } |
| 1784 | if (right_type_ == BinaryOpIC::SMI) { |
| 1785 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1786 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1787 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1788 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1789 | if (op_ == Token::MOD) { |
| 1790 | GenerateRegisterArgsPush(masm); |
| 1791 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1792 | } else { |
| 1793 | switch (op_) { |
| 1794 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1795 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1796 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1797 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1798 | default: UNREACHABLE(); |
| 1799 | } |
| 1800 | // Check result type if it is currently Int32. |
| 1801 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1802 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1803 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1804 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1805 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1806 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1807 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1808 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | } else { // SSE2 not available, use FPU. |
| 1810 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1811 | FloatingPointHelper::LoadFloatOperands( |
| 1812 | masm, |
| 1813 | ecx, |
| 1814 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1815 | if (op_ == Token::MOD) { |
| 1816 | // The operands are now on the FPU stack, but we don't need them. |
| 1817 | __ fstp(0); |
| 1818 | __ fstp(0); |
| 1819 | GenerateRegisterArgsPush(masm); |
| 1820 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1821 | } else { |
| 1822 | switch (op_) { |
| 1823 | case Token::ADD: __ faddp(1); break; |
| 1824 | case Token::SUB: __ fsubp(1); break; |
| 1825 | case Token::MUL: __ fmulp(1); break; |
| 1826 | case Token::DIV: __ fdivp(1); break; |
| 1827 | default: UNREACHABLE(); |
| 1828 | } |
| 1829 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1830 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1831 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1832 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1833 | __ ret(0); |
| 1834 | __ bind(&after_alloc_failure); |
| 1835 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1836 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1837 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | __ bind(¬_floats); |
| 1841 | __ bind(¬_int32); |
| 1842 | GenerateTypeTransition(masm); |
| 1843 | break; |
| 1844 | } |
| 1845 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1846 | case Token::BIT_OR: |
| 1847 | case Token::BIT_AND: |
| 1848 | case Token::BIT_XOR: |
| 1849 | case Token::SAR: |
| 1850 | case Token::SHL: |
| 1851 | case Token::SHR: { |
| 1852 | GenerateRegisterArgsPush(masm); |
| 1853 | Label not_floats; |
| 1854 | Label not_int32; |
| 1855 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1856 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1857 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1858 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1859 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1860 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1861 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1862 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1863 | case Token::SAR: __ sar_cl(eax); break; |
| 1864 | case Token::SHL: __ shl_cl(eax); break; |
| 1865 | case Token::SHR: __ shr_cl(eax); break; |
| 1866 | default: UNREACHABLE(); |
| 1867 | } |
| 1868 | if (op_ == Token::SHR) { |
| 1869 | // Check if result is non-negative and fits in a smi. |
| 1870 | __ test(eax, Immediate(0xc0000000)); |
| 1871 | __ j(not_zero, &call_runtime); |
| 1872 | } else { |
| 1873 | // Check if result fits in a smi. |
| 1874 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1875 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1876 | } |
| 1877 | // Tag smi result and return. |
| 1878 | __ SmiTag(eax); |
| 1879 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1880 | |
| 1881 | // All ops except SHR return a signed int32 that we load in |
| 1882 | // a HeapNumber. |
| 1883 | if (op_ != Token::SHR) { |
| 1884 | __ bind(&non_smi_result); |
| 1885 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1886 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1887 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1888 | switch (mode_) { |
| 1889 | case OVERWRITE_LEFT: |
| 1890 | case OVERWRITE_RIGHT: |
| 1891 | // If the operand was an object, we skip the |
| 1892 | // allocation of a heap number. |
| 1893 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1894 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1895 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1896 | // Fall through! |
| 1897 | case NO_OVERWRITE: |
| 1898 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1899 | __ bind(&skip_allocation); |
| 1900 | break; |
| 1901 | default: UNREACHABLE(); |
| 1902 | } |
| 1903 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1904 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1905 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1906 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1907 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1908 | } else { |
| 1909 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1910 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1911 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1912 | } |
| 1913 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1914 | } |
| 1915 | |
| 1916 | __ bind(¬_floats); |
| 1917 | __ bind(¬_int32); |
| 1918 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1919 | break; |
| 1920 | } |
| 1921 | default: UNREACHABLE(); break; |
| 1922 | } |
| 1923 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1924 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1925 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1926 | __ bind(&call_runtime); |
| 1927 | |
| 1928 | switch (op_) { |
| 1929 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1930 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1931 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1932 | case Token::DIV: |
| 1933 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1936 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1938 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | default: |
| 1945 | UNREACHABLE(); |
| 1946 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1947 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1951 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1952 | if (op_ == Token::ADD) { |
| 1953 | // Handle string addition here, because it is the only operation |
| 1954 | // that does not do a ToNumber conversion on the operands. |
| 1955 | GenerateAddStrings(masm); |
| 1956 | } |
| 1957 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1958 | Factory* factory = masm->isolate()->factory(); |
| 1959 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1960 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1961 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1962 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1963 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1964 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1965 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1966 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1967 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1968 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1969 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1970 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1971 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1972 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1973 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1974 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1975 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1976 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1977 | } |
| 1978 | __ bind(&done); |
| 1979 | |
| 1980 | GenerateHeapNumberStub(masm); |
| 1981 | } |
| 1982 | |
| 1983 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1984 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1985 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1986 | |
| 1987 | // Floating point case. |
| 1988 | switch (op_) { |
| 1989 | case Token::ADD: |
| 1990 | case Token::SUB: |
| 1991 | case Token::MUL: |
| 1992 | case Token::DIV: { |
| 1993 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1994 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1995 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1996 | |
| 1997 | // It could be that only SMIs have been seen at either the left |
| 1998 | // or the right operand. For precise type feedback, patch the IC |
| 1999 | // again if this changes. |
| 2000 | // In theory, we would need the same check in the non-SSE2 case, |
| 2001 | // but since we don't support Crankshaft on such hardware we can |
| 2002 | // afford not to care about precise type feedback. |
| 2003 | if (left_type_ == BinaryOpIC::SMI) { |
| 2004 | __ JumpIfNotSmi(edx, ¬_floats); |
| 2005 | } |
| 2006 | if (right_type_ == BinaryOpIC::SMI) { |
| 2007 | __ JumpIfNotSmi(eax, ¬_floats); |
| 2008 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2009 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2010 | if (left_type_ == BinaryOpIC::INT32) { |
| 2011 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2012 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2013 | } |
| 2014 | if (right_type_ == BinaryOpIC::INT32) { |
| 2015 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2016 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2017 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2018 | |
| 2019 | switch (op_) { |
| 2020 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2021 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2022 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2023 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2024 | default: UNREACHABLE(); |
| 2025 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2026 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2027 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2028 | __ ret(0); |
| 2029 | } else { // SSE2 not available, use FPU. |
| 2030 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2031 | FloatingPointHelper::LoadFloatOperands( |
| 2032 | masm, |
| 2033 | ecx, |
| 2034 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2035 | switch (op_) { |
| 2036 | case Token::ADD: __ faddp(1); break; |
| 2037 | case Token::SUB: __ fsubp(1); break; |
| 2038 | case Token::MUL: __ fmulp(1); break; |
| 2039 | case Token::DIV: __ fdivp(1); break; |
| 2040 | default: UNREACHABLE(); |
| 2041 | } |
| 2042 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2043 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2044 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2045 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2046 | __ ret(0); |
| 2047 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2048 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2049 | __ jmp(&call_runtime); |
| 2050 | } |
| 2051 | |
| 2052 | __ bind(¬_floats); |
| 2053 | GenerateTypeTransition(masm); |
| 2054 | break; |
| 2055 | } |
| 2056 | |
| 2057 | case Token::MOD: { |
| 2058 | // For MOD we go directly to runtime in the non-smi case. |
| 2059 | break; |
| 2060 | } |
| 2061 | case Token::BIT_OR: |
| 2062 | case Token::BIT_AND: |
| 2063 | case Token::BIT_XOR: |
| 2064 | case Token::SAR: |
| 2065 | case Token::SHL: |
| 2066 | case Token::SHR: { |
| 2067 | GenerateRegisterArgsPush(masm); |
| 2068 | Label not_floats; |
| 2069 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2070 | // We do not check the input arguments here, as any value is |
| 2071 | // unconditionally truncated to an int32 anyway. To get the |
| 2072 | // right optimized code, int32 type feedback is just right. |
| 2073 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2074 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2075 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2076 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2077 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2078 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2079 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2080 | case Token::SAR: __ sar_cl(eax); break; |
| 2081 | case Token::SHL: __ shl_cl(eax); break; |
| 2082 | case Token::SHR: __ shr_cl(eax); break; |
| 2083 | default: UNREACHABLE(); |
| 2084 | } |
| 2085 | if (op_ == Token::SHR) { |
| 2086 | // Check if result is non-negative and fits in a smi. |
| 2087 | __ test(eax, Immediate(0xc0000000)); |
| 2088 | __ j(not_zero, &call_runtime); |
| 2089 | } else { |
| 2090 | // Check if result fits in a smi. |
| 2091 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2092 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2093 | } |
| 2094 | // Tag smi result and return. |
| 2095 | __ SmiTag(eax); |
| 2096 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2097 | |
| 2098 | // All ops except SHR return a signed int32 that we load in |
| 2099 | // a HeapNumber. |
| 2100 | if (op_ != Token::SHR) { |
| 2101 | __ bind(&non_smi_result); |
| 2102 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2103 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2104 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | switch (mode_) { |
| 2106 | case OVERWRITE_LEFT: |
| 2107 | case OVERWRITE_RIGHT: |
| 2108 | // If the operand was an object, we skip the |
| 2109 | // allocation of a heap number. |
| 2110 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2111 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2112 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | // Fall through! |
| 2114 | case NO_OVERWRITE: |
| 2115 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2116 | __ bind(&skip_allocation); |
| 2117 | break; |
| 2118 | default: UNREACHABLE(); |
| 2119 | } |
| 2120 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2121 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2122 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2123 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2124 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2125 | } else { |
| 2126 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2127 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2128 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2129 | } |
| 2130 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2131 | } |
| 2132 | |
| 2133 | __ bind(¬_floats); |
| 2134 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2135 | break; |
| 2136 | } |
| 2137 | default: UNREACHABLE(); break; |
| 2138 | } |
| 2139 | |
| 2140 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2141 | // use the runtime system to get the correct result. |
| 2142 | __ bind(&call_runtime); |
| 2143 | |
| 2144 | switch (op_) { |
| 2145 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2146 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2147 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2148 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2149 | case Token::MOD: |
| 2150 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2154 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2155 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2156 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2157 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | default: |
| 2160 | UNREACHABLE(); |
| 2161 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2162 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2166 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2167 | Label call_runtime; |
| 2168 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2169 | Counters* counters = masm->isolate()->counters(); |
| 2170 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2171 | |
| 2172 | switch (op_) { |
| 2173 | case Token::ADD: |
| 2174 | case Token::SUB: |
| 2175 | case Token::MUL: |
| 2176 | case Token::DIV: |
| 2177 | break; |
| 2178 | case Token::MOD: |
| 2179 | case Token::BIT_OR: |
| 2180 | case Token::BIT_AND: |
| 2181 | case Token::BIT_XOR: |
| 2182 | case Token::SAR: |
| 2183 | case Token::SHL: |
| 2184 | case Token::SHR: |
| 2185 | GenerateRegisterArgsPush(masm); |
| 2186 | break; |
| 2187 | default: |
| 2188 | UNREACHABLE(); |
| 2189 | } |
| 2190 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2191 | BinaryOpStub_GenerateSmiCode( |
| 2192 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2193 | |
| 2194 | // Floating point case. |
| 2195 | switch (op_) { |
| 2196 | case Token::ADD: |
| 2197 | case Token::SUB: |
| 2198 | case Token::MUL: |
| 2199 | case Token::DIV: { |
| 2200 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2201 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | CpuFeatures::Scope use_sse2(SSE2); |
| 2203 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2204 | |
| 2205 | switch (op_) { |
| 2206 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2207 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2208 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2209 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2210 | default: UNREACHABLE(); |
| 2211 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2212 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2213 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2214 | __ ret(0); |
| 2215 | } else { // SSE2 not available, use FPU. |
| 2216 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2217 | FloatingPointHelper::LoadFloatOperands( |
| 2218 | masm, |
| 2219 | ecx, |
| 2220 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2221 | switch (op_) { |
| 2222 | case Token::ADD: __ faddp(1); break; |
| 2223 | case Token::SUB: __ fsubp(1); break; |
| 2224 | case Token::MUL: __ fmulp(1); break; |
| 2225 | case Token::DIV: __ fdivp(1); break; |
| 2226 | default: UNREACHABLE(); |
| 2227 | } |
| 2228 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2229 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2230 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2231 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2232 | __ ret(0); |
| 2233 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2234 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2235 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2236 | } |
| 2237 | __ bind(¬_floats); |
| 2238 | break; |
| 2239 | } |
| 2240 | case Token::MOD: { |
| 2241 | // For MOD we go directly to runtime in the non-smi case. |
| 2242 | break; |
| 2243 | } |
| 2244 | case Token::BIT_OR: |
| 2245 | case Token::BIT_AND: |
| 2246 | case Token::BIT_XOR: |
| 2247 | case Token::SAR: |
| 2248 | case Token::SHL: |
| 2249 | case Token::SHR: { |
| 2250 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2251 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2252 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2253 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2254 | BinaryOpIC::GENERIC, |
| 2255 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2256 | &call_runtime); |
| 2257 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2258 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2259 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2260 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2261 | case Token::SAR: __ sar_cl(eax); break; |
| 2262 | case Token::SHL: __ shl_cl(eax); break; |
| 2263 | case Token::SHR: __ shr_cl(eax); break; |
| 2264 | default: UNREACHABLE(); |
| 2265 | } |
| 2266 | if (op_ == Token::SHR) { |
| 2267 | // Check if result is non-negative and fits in a smi. |
| 2268 | __ test(eax, Immediate(0xc0000000)); |
| 2269 | __ j(not_zero, &call_runtime); |
| 2270 | } else { |
| 2271 | // Check if result fits in a smi. |
| 2272 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2273 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2274 | } |
| 2275 | // Tag smi result and return. |
| 2276 | __ SmiTag(eax); |
| 2277 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2278 | |
| 2279 | // All ops except SHR return a signed int32 that we load in |
| 2280 | // a HeapNumber. |
| 2281 | if (op_ != Token::SHR) { |
| 2282 | __ bind(&non_smi_result); |
| 2283 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2284 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2285 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2286 | switch (mode_) { |
| 2287 | case OVERWRITE_LEFT: |
| 2288 | case OVERWRITE_RIGHT: |
| 2289 | // If the operand was an object, we skip the |
| 2290 | // allocation of a heap number. |
| 2291 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2292 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2293 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2294 | // Fall through! |
| 2295 | case NO_OVERWRITE: |
| 2296 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2297 | __ bind(&skip_allocation); |
| 2298 | break; |
| 2299 | default: UNREACHABLE(); |
| 2300 | } |
| 2301 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2302 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2304 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2305 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2306 | } else { |
| 2307 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2308 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2309 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2310 | } |
| 2311 | __ ret(2 * kPointerSize); |
| 2312 | } |
| 2313 | break; |
| 2314 | } |
| 2315 | default: UNREACHABLE(); break; |
| 2316 | } |
| 2317 | |
| 2318 | // If all else fails, use the runtime system to get the correct |
| 2319 | // result. |
| 2320 | __ bind(&call_runtime); |
| 2321 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2322 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2323 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2324 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2325 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2326 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2327 | case Token::DIV: |
| 2328 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2331 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2333 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2334 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2336 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2337 | break; |
| 2338 | default: |
| 2339 | UNREACHABLE(); |
| 2340 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2341 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2345 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2346 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2347 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2348 | |
| 2349 | // Registers containing left and right operands respectively. |
| 2350 | Register left = edx; |
| 2351 | Register right = eax; |
| 2352 | |
| 2353 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2354 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2355 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2356 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2357 | |
| 2358 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2359 | GenerateRegisterArgsPush(masm); |
| 2360 | __ TailCallStub(&string_add_left_stub); |
| 2361 | |
| 2362 | // Left operand is not a string, test right. |
| 2363 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2364 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2365 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2366 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2367 | |
| 2368 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2369 | GenerateRegisterArgsPush(masm); |
| 2370 | __ TailCallStub(&string_add_right_stub); |
| 2371 | |
| 2372 | // Neither argument is a string. |
| 2373 | __ bind(&call_runtime); |
| 2374 | } |
| 2375 | |
| 2376 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2377 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2378 | Label* alloc_failure, |
| 2379 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2380 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2381 | switch (mode) { |
| 2382 | case OVERWRITE_LEFT: { |
| 2383 | // If the argument in edx is already an object, we skip the |
| 2384 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2385 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2386 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2387 | // for the possible runtime call. |
| 2388 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2389 | // Now edx can be overwritten losing one of the arguments as we are |
| 2390 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2391 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2392 | __ bind(&skip_allocation); |
| 2393 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2394 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | } |
| 2397 | case OVERWRITE_RIGHT: |
| 2398 | // If the argument in eax is already an object, we skip the |
| 2399 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2400 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2401 | // Fall through! |
| 2402 | case NO_OVERWRITE: |
| 2403 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2404 | // for the possible runtime call. |
| 2405 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2406 | // Now eax can be overwritten losing one of the arguments as we are |
| 2407 | // now done and will not need it any more. |
| 2408 | __ mov(eax, ebx); |
| 2409 | __ bind(&skip_allocation); |
| 2410 | break; |
| 2411 | default: UNREACHABLE(); |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2416 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2417 | __ pop(ecx); |
| 2418 | __ push(edx); |
| 2419 | __ push(eax); |
| 2420 | __ push(ecx); |
| 2421 | } |
| 2422 | |
| 2423 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2424 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2425 | // TAGGED case: |
| 2426 | // Input: |
| 2427 | // esp[4]: tagged number input argument (should be number). |
| 2428 | // esp[0]: return address. |
| 2429 | // Output: |
| 2430 | // eax: tagged double result. |
| 2431 | // UNTAGGED case: |
| 2432 | // Input:: |
| 2433 | // esp[0]: return address. |
| 2434 | // xmm1: untagged double input argument |
| 2435 | // Output: |
| 2436 | // xmm1: untagged double result. |
| 2437 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2438 | Label runtime_call; |
| 2439 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2440 | Label skip_cache; |
| 2441 | const bool tagged = (argument_type_ == TAGGED); |
| 2442 | if (tagged) { |
| 2443 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2444 | Label input_not_smi; |
| 2445 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2446 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2447 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2448 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2449 | // Then load the low and high words of the double into ebx, edx. |
| 2450 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2451 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2452 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2453 | __ mov(Operand(esp, 0), eax); |
| 2454 | __ fild_s(Operand(esp, 0)); |
| 2455 | __ fst_d(Operand(esp, 0)); |
| 2456 | __ pop(edx); |
| 2457 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2458 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2459 | __ bind(&input_not_smi); |
| 2460 | // Check if input is a HeapNumber. |
| 2461 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2462 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2463 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2464 | __ j(not_equal, &runtime_call); |
| 2465 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2466 | // low and high words into ebx, edx. |
| 2467 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2468 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2469 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2470 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2471 | __ bind(&loaded); |
| 2472 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2473 | CpuFeatures::Scope scope(SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2474 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2475 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2476 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2477 | } else { |
| 2478 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2479 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2480 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2481 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2485 | // ebx = low 32 bits of double value |
| 2486 | // edx = high 32 bits of double value |
| 2487 | // Compute hash (the shifts are arithmetic): |
| 2488 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2489 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2490 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2491 | __ mov(eax, ecx); |
| 2492 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2493 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2494 | __ mov(eax, ecx); |
| 2495 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2497 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2498 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2499 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2500 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2501 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2502 | // ebx = low 32 bits of double value. |
| 2503 | // edx = high 32 bits of double value. |
| 2504 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2505 | ExternalReference cache_array = |
| 2506 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2507 | __ mov(eax, Immediate(cache_array)); |
| 2508 | int cache_array_index = |
| 2509 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2510 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2511 | // Eax points to the cache for the type type_. |
| 2512 | // 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] | 2513 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2514 | __ j(zero, &runtime_call_clear_stack); |
| 2515 | #ifdef DEBUG |
| 2516 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2517 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2518 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2519 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2520 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2521 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2522 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2523 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2524 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2525 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2526 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2527 | } |
| 2528 | #endif |
| 2529 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2530 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2531 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2532 | // 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] | 2533 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2534 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2535 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2536 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2537 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2538 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2539 | Counters* counters = masm->isolate()->counters(); |
| 2540 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2541 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2542 | if (tagged) { |
| 2543 | __ fstp(0); |
| 2544 | __ ret(kPointerSize); |
| 2545 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2546 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2547 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2548 | __ Ret(); |
| 2549 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2550 | |
| 2551 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2552 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2553 | // Update cache with new value. |
| 2554 | // We are short on registers, so use no_reg as scratch. |
| 2555 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2556 | if (tagged) { |
| 2557 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2558 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2559 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2560 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2561 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2562 | __ movdbl(Operand(esp, 0), xmm1); |
| 2563 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2564 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2565 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2566 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2567 | __ mov(Operand(ecx, 0), ebx); |
| 2568 | __ mov(Operand(ecx, kIntSize), edx); |
| 2569 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2570 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2571 | if (tagged) { |
| 2572 | __ ret(kPointerSize); |
| 2573 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2574 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2575 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2576 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2577 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2578 | // Skip cache and return answer directly, only in untagged case. |
| 2579 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2580 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2581 | __ movdbl(Operand(esp, 0), xmm1); |
| 2582 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2583 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2584 | __ fstp_d(Operand(esp, 0)); |
| 2585 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2586 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2587 | // We return the value in xmm1 without adding it to the cache, but |
| 2588 | // 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] | 2589 | { |
| 2590 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2591 | // Allocate an unused object bigger than a HeapNumber. |
| 2592 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2593 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2594 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2595 | __ Ret(); |
| 2596 | } |
| 2597 | |
| 2598 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2599 | if (tagged) { |
| 2600 | __ bind(&runtime_call_clear_stack); |
| 2601 | __ fstp(0); |
| 2602 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2603 | ExternalReference runtime = |
| 2604 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2605 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2606 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2607 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2608 | __ bind(&runtime_call_clear_stack); |
| 2609 | __ bind(&runtime_call); |
| 2610 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2611 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2612 | { |
| 2613 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2614 | __ push(eax); |
| 2615 | __ CallRuntime(RuntimeFunction(), 1); |
| 2616 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2617 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2618 | __ Ret(); |
| 2619 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | |
| 2623 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2624 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2625 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2626 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2627 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2628 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2629 | default: |
| 2630 | UNIMPLEMENTED(); |
| 2631 | return Runtime::kAbort; |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2636 | void TranscendentalCacheStub::GenerateOperation( |
| 2637 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2638 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2639 | // Input value is on FP stack, and also in ebx/edx. |
| 2640 | // Input value is possibly in xmm1. |
| 2641 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2642 | if (type == TranscendentalCache::SIN || |
| 2643 | type == TranscendentalCache::COS || |
| 2644 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2645 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2646 | // return NaN for infinities and NaN. They can share all code except |
| 2647 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2648 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2649 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2650 | // work. We must reduce it to the appropriate range. |
| 2651 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2652 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2653 | int supported_exponent_limit = |
| 2654 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2655 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2656 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2657 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2658 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2659 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2660 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2661 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2662 | __ fstp(0); |
| 2663 | // NaN is represented by 0x7ff8000000000000. |
| 2664 | __ push(Immediate(0x7ff80000)); |
| 2665 | __ push(Immediate(0)); |
| 2666 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2667 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2668 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2669 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2670 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2671 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2672 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2673 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2674 | __ fldpi(); |
| 2675 | __ fadd(0); |
| 2676 | __ fld(1); |
| 2677 | // FPU Stack: input, 2*pi, input. |
| 2678 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2679 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2680 | __ fwait(); |
| 2681 | __ fnstsw_ax(); |
| 2682 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2683 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2684 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2685 | __ fnclex(); |
| 2686 | __ bind(&no_exceptions); |
| 2687 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2688 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2689 | // Compute st(0) % st(1) |
| 2690 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2691 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2692 | __ bind(&partial_remainder_loop); |
| 2693 | __ fprem1(); |
| 2694 | __ fwait(); |
| 2695 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2696 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2697 | // If C2 is set, computation only has partial result. Loop to |
| 2698 | // continue computation. |
| 2699 | __ j(not_zero, &partial_remainder_loop); |
| 2700 | } |
| 2701 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2702 | __ fstp(2); |
| 2703 | __ fstp(0); |
| 2704 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2705 | |
| 2706 | // FPU Stack: input % 2*pi |
| 2707 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2708 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2709 | case TranscendentalCache::SIN: |
| 2710 | __ fsin(); |
| 2711 | break; |
| 2712 | case TranscendentalCache::COS: |
| 2713 | __ fcos(); |
| 2714 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2715 | case TranscendentalCache::TAN: |
| 2716 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2717 | // FP register stack. |
| 2718 | __ fptan(); |
| 2719 | __ fstp(0); // Pop FP register stack. |
| 2720 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2721 | default: |
| 2722 | UNREACHABLE(); |
| 2723 | } |
| 2724 | __ bind(&done); |
| 2725 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2726 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2727 | __ fldln2(); |
| 2728 | __ fxch(); |
| 2729 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2730 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2734 | // Input: edx, eax are the left and right objects of a bit op. |
| 2735 | // 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] | 2736 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2737 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2738 | MacroAssembler* masm, |
| 2739 | bool use_sse3, |
| 2740 | BinaryOpIC::TypeInfo left_type, |
| 2741 | BinaryOpIC::TypeInfo right_type, |
| 2742 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2743 | // Check float operands. |
| 2744 | Label arg1_is_object, check_undefined_arg1; |
| 2745 | Label arg2_is_object, check_undefined_arg2; |
| 2746 | Label load_arg2, done; |
| 2747 | |
| 2748 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2749 | if (left_type == BinaryOpIC::SMI) { |
| 2750 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2751 | } else { |
| 2752 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2753 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2754 | |
| 2755 | __ SmiUntag(edx); |
| 2756 | __ jmp(&load_arg2); |
| 2757 | |
| 2758 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2759 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2760 | Factory* factory = masm->isolate()->factory(); |
| 2761 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2762 | __ j(not_equal, conversion_failure); |
| 2763 | __ mov(edx, Immediate(0)); |
| 2764 | __ jmp(&load_arg2); |
| 2765 | |
| 2766 | __ bind(&arg1_is_object); |
| 2767 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2768 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2769 | __ j(not_equal, &check_undefined_arg1); |
| 2770 | |
| 2771 | // 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] | 2772 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2773 | CpuFeatures::Scope use_sse2(SSE2); |
| 2774 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2775 | } else { |
| 2776 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2777 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2778 | __ mov(edx, ecx); |
| 2779 | |
| 2780 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2781 | __ bind(&load_arg2); |
| 2782 | |
| 2783 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2784 | if (right_type == BinaryOpIC::SMI) { |
| 2785 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2786 | } else { |
| 2787 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2788 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2789 | |
| 2790 | __ SmiUntag(eax); |
| 2791 | __ mov(ecx, eax); |
| 2792 | __ jmp(&done); |
| 2793 | |
| 2794 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2795 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2796 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2797 | __ j(not_equal, conversion_failure); |
| 2798 | __ mov(ecx, Immediate(0)); |
| 2799 | __ jmp(&done); |
| 2800 | |
| 2801 | __ bind(&arg2_is_object); |
| 2802 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2803 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2804 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2805 | // 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] | 2806 | |
| 2807 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
| 2808 | CpuFeatures::Scope use_sse2(SSE2); |
| 2809 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2810 | } else { |
| 2811 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2812 | } |
| 2813 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2814 | __ bind(&done); |
| 2815 | __ mov(eax, edx); |
| 2816 | } |
| 2817 | |
| 2818 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2819 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2820 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2821 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2822 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2823 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2825 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | |
| 2827 | __ bind(&load_smi); |
| 2828 | __ SmiUntag(number); |
| 2829 | __ push(number); |
| 2830 | __ fild_s(Operand(esp, 0)); |
| 2831 | __ pop(number); |
| 2832 | |
| 2833 | __ bind(&done); |
| 2834 | } |
| 2835 | |
| 2836 | |
| 2837 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2838 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2839 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2840 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2841 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2842 | |
| 2843 | __ bind(&load_eax); |
| 2844 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2845 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2847 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2848 | |
| 2849 | __ bind(&load_smi_edx); |
| 2850 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2851 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2852 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2853 | __ jmp(&load_eax); |
| 2854 | |
| 2855 | __ bind(&load_smi_eax); |
| 2856 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2857 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2859 | |
| 2860 | __ bind(&done); |
| 2861 | } |
| 2862 | |
| 2863 | |
| 2864 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2865 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2866 | 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] | 2867 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2868 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2869 | Factory* factory = masm->isolate()->factory(); |
| 2870 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2871 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2872 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2873 | __ bind(&load_eax); |
| 2874 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2875 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2876 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2877 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2878 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2879 | __ bind(&load_smi_edx); |
| 2880 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2881 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2882 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2883 | __ jmp(&load_eax); |
| 2884 | __ bind(&load_smi_eax); |
| 2885 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2886 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2887 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2888 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2889 | __ bind(&load_float_eax); |
| 2890 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2891 | __ bind(&done); |
| 2892 | } |
| 2893 | |
| 2894 | |
| 2895 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2896 | Register scratch) { |
| 2897 | const Register left = edx; |
| 2898 | const Register right = eax; |
| 2899 | __ mov(scratch, left); |
| 2900 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2901 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2902 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2903 | |
| 2904 | __ mov(scratch, right); |
| 2905 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2906 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2910 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2911 | Label* non_int32, |
| 2912 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2913 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2914 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2919 | Label* non_int32, |
| 2920 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2921 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2922 | Register scratch, |
| 2923 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2924 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2925 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2926 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2927 | __ movmskps(scratch, xmm_scratch); |
| 2928 | // Two least significant bits should be both set. |
| 2929 | __ not_(scratch); |
| 2930 | __ test(scratch, Immediate(3)); |
| 2931 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2935 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2936 | Register scratch, |
| 2937 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2938 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2939 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2940 | __ mov(scratch, edx); |
| 2941 | } else { |
| 2942 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2943 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2944 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2945 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2946 | __ bind(&done_load_1); |
| 2947 | |
| 2948 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2949 | __ mov(scratch, eax); |
| 2950 | } else { |
| 2951 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2952 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2953 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2954 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2955 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2956 | |
| 2957 | __ bind(&load_smi_1); |
| 2958 | __ SmiUntag(scratch); |
| 2959 | __ push(scratch); |
| 2960 | __ fild_s(Operand(esp, 0)); |
| 2961 | __ pop(scratch); |
| 2962 | __ jmp(&done_load_1); |
| 2963 | |
| 2964 | __ bind(&load_smi_2); |
| 2965 | __ SmiUntag(scratch); |
| 2966 | __ push(scratch); |
| 2967 | __ fild_s(Operand(esp, 0)); |
| 2968 | __ pop(scratch); |
| 2969 | |
| 2970 | __ bind(&done); |
| 2971 | } |
| 2972 | |
| 2973 | |
| 2974 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2975 | Register scratch) { |
| 2976 | const Register left = edx; |
| 2977 | const Register right = eax; |
| 2978 | __ mov(scratch, left); |
| 2979 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2980 | __ SmiUntag(scratch); |
| 2981 | __ push(scratch); |
| 2982 | __ fild_s(Operand(esp, 0)); |
| 2983 | |
| 2984 | __ mov(scratch, right); |
| 2985 | __ SmiUntag(scratch); |
| 2986 | __ mov(Operand(esp, 0), scratch); |
| 2987 | __ fild_s(Operand(esp, 0)); |
| 2988 | __ pop(scratch); |
| 2989 | } |
| 2990 | |
| 2991 | |
| 2992 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2993 | Label* non_float, |
| 2994 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2995 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2996 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2997 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2998 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2999 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3000 | Factory* factory = masm->isolate()->factory(); |
| 3001 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3002 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 3003 | |
| 3004 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3005 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3006 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3007 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3008 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 3009 | |
| 3010 | // Fall-through: Both operands are numbers. |
| 3011 | __ bind(&done); |
| 3012 | } |
| 3013 | |
| 3014 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3015 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3016 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3017 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3018 | const Register exponent = eax; |
| 3019 | const Register base = edx; |
| 3020 | const Register scratch = ecx; |
| 3021 | const XMMRegister double_result = xmm3; |
| 3022 | const XMMRegister double_base = xmm2; |
| 3023 | const XMMRegister double_exponent = xmm1; |
| 3024 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3025 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3026 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3027 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3028 | // Save 1 in double_result - we need this several times later on. |
| 3029 | __ mov(scratch, Immediate(1)); |
| 3030 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3031 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3032 | if (exponent_type_ == ON_STACK) { |
| 3033 | Label base_is_smi, unpack_exponent; |
| 3034 | // The exponent and base are supplied as arguments on the stack. |
| 3035 | // This can only happen if the stub is called from non-optimized code. |
| 3036 | // Load input parameters from stack. |
| 3037 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3038 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3039 | |
| 3040 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3041 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3042 | factory->heap_number_map()); |
| 3043 | __ j(not_equal, &call_runtime); |
| 3044 | |
| 3045 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3046 | __ jmp(&unpack_exponent, Label::kNear); |
| 3047 | |
| 3048 | __ bind(&base_is_smi); |
| 3049 | __ SmiUntag(base); |
| 3050 | __ cvtsi2sd(double_base, base); |
| 3051 | |
| 3052 | __ bind(&unpack_exponent); |
| 3053 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3054 | __ SmiUntag(exponent); |
| 3055 | __ jmp(&int_exponent); |
| 3056 | |
| 3057 | __ bind(&exponent_not_smi); |
| 3058 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3059 | factory->heap_number_map()); |
| 3060 | __ j(not_equal, &call_runtime); |
| 3061 | __ movdbl(double_exponent, |
| 3062 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3063 | } else if (exponent_type_ == TAGGED) { |
| 3064 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3065 | __ SmiUntag(exponent); |
| 3066 | __ jmp(&int_exponent); |
| 3067 | |
| 3068 | __ bind(&exponent_not_smi); |
| 3069 | __ movdbl(double_exponent, |
| 3070 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3071 | } |
| 3072 | |
| 3073 | if (exponent_type_ != INTEGER) { |
| 3074 | Label fast_power; |
| 3075 | // Detect integer exponents stored as double. |
| 3076 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3077 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3078 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3079 | __ j(equal, &call_runtime); |
| 3080 | __ cvtsi2sd(double_scratch, exponent); |
| 3081 | // Already ruled out NaNs for exponent. |
| 3082 | __ ucomisd(double_exponent, double_scratch); |
| 3083 | __ j(equal, &int_exponent); |
| 3084 | |
| 3085 | if (exponent_type_ == ON_STACK) { |
| 3086 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3087 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3088 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3089 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3090 | // Test for 0.5. |
| 3091 | // Load double_scratch with 0.5. |
| 3092 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3093 | __ movd(double_scratch, scratch); |
| 3094 | __ cvtss2sd(double_scratch, double_scratch); |
| 3095 | // Already ruled out NaNs for exponent. |
| 3096 | __ ucomisd(double_scratch, double_exponent); |
| 3097 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3098 | |
| 3099 | // Calculates square root of base. Check for the special case of |
| 3100 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3101 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3102 | // 9 bits set and the lowest 23 bits cleared. |
| 3103 | __ mov(scratch, 0xFF800000u); |
| 3104 | __ movd(double_scratch, scratch); |
| 3105 | __ cvtss2sd(double_scratch, double_scratch); |
| 3106 | __ ucomisd(double_base, double_scratch); |
| 3107 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3108 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3109 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3110 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3111 | |
| 3112 | // Set result to Infinity in the special case. |
| 3113 | __ xorps(double_result, double_result); |
| 3114 | __ subsd(double_result, double_scratch); |
| 3115 | __ jmp(&done); |
| 3116 | |
| 3117 | __ bind(&continue_sqrt); |
| 3118 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3119 | __ xorps(double_scratch, double_scratch); |
| 3120 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3121 | __ sqrtsd(double_result, double_scratch); |
| 3122 | __ jmp(&done); |
| 3123 | |
| 3124 | // Test for -0.5. |
| 3125 | __ bind(¬_plus_half); |
| 3126 | // Load double_exponent with -0.5 by substracting 1. |
| 3127 | __ subsd(double_scratch, double_result); |
| 3128 | // Already ruled out NaNs for exponent. |
| 3129 | __ ucomisd(double_scratch, double_exponent); |
| 3130 | __ j(not_equal, &fast_power, Label::kNear); |
| 3131 | |
| 3132 | // Calculates reciprocal of square root of base. Check for the special |
| 3133 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3134 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3135 | // 9 bits set and the lowest 23 bits cleared. |
| 3136 | __ mov(scratch, 0xFF800000u); |
| 3137 | __ movd(double_scratch, scratch); |
| 3138 | __ cvtss2sd(double_scratch, double_scratch); |
| 3139 | __ ucomisd(double_base, double_scratch); |
| 3140 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3141 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3142 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3143 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3144 | |
| 3145 | // Set result to 0 in the special case. |
| 3146 | __ xorps(double_result, double_result); |
| 3147 | __ jmp(&done); |
| 3148 | |
| 3149 | __ bind(&continue_rsqrt); |
| 3150 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3151 | __ xorps(double_exponent, double_exponent); |
| 3152 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3153 | __ sqrtsd(double_exponent, double_exponent); |
| 3154 | __ divsd(double_result, double_exponent); |
| 3155 | __ jmp(&done); |
| 3156 | } |
| 3157 | |
| 3158 | // Using FPU instructions to calculate power. |
| 3159 | Label fast_power_failed; |
| 3160 | __ bind(&fast_power); |
| 3161 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3162 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3163 | __ sub(esp, Immediate(kDoubleSize)); |
| 3164 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3165 | __ fld_d(Operand(esp, 0)); // E |
| 3166 | __ movdbl(Operand(esp, 0), double_base); |
| 3167 | __ fld_d(Operand(esp, 0)); // B, E |
| 3168 | |
| 3169 | // Exponent is in st(1) and base is in st(0) |
| 3170 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3171 | // FYL2X calculates st(1) * log2(st(0)) |
| 3172 | __ fyl2x(); // X |
| 3173 | __ fld(0); // X, X |
| 3174 | __ frndint(); // rnd(X), X |
| 3175 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3176 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3177 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3178 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3179 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3180 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3181 | // FSCALE calculates st(0) * 2^st(1) |
| 3182 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3183 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3184 | // Bail out to runtime in case of exceptions in the status word. |
| 3185 | __ fnstsw_ax(); |
| 3186 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3187 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3188 | __ fstp_d(Operand(esp, 0)); |
| 3189 | __ movdbl(double_result, Operand(esp, 0)); |
| 3190 | __ add(esp, Immediate(kDoubleSize)); |
| 3191 | __ jmp(&done); |
| 3192 | |
| 3193 | __ bind(&fast_power_failed); |
| 3194 | __ fninit(); |
| 3195 | __ add(esp, Immediate(kDoubleSize)); |
| 3196 | __ jmp(&call_runtime); |
| 3197 | } |
| 3198 | |
| 3199 | // Calculate power with integer exponent. |
| 3200 | __ bind(&int_exponent); |
| 3201 | const XMMRegister double_scratch2 = double_exponent; |
| 3202 | __ mov(scratch, exponent); // Back up exponent. |
| 3203 | __ movsd(double_scratch, double_base); // Back up base. |
| 3204 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3205 | |
| 3206 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3207 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3208 | __ test(scratch, scratch); |
| 3209 | __ j(positive, &no_neg, Label::kNear); |
| 3210 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3211 | __ bind(&no_neg); |
| 3212 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3213 | __ j(zero, &while_false, Label::kNear); |
| 3214 | __ shr(scratch, 1); |
| 3215 | // Above condition means CF==0 && ZF==0. This means that the |
| 3216 | // bit that has been shifted out is 0 and the result is not 0. |
| 3217 | __ j(above, &while_true, Label::kNear); |
| 3218 | __ movsd(double_result, double_scratch); |
| 3219 | __ j(zero, &while_false, Label::kNear); |
| 3220 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3221 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3222 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3223 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3224 | __ j(above, &while_true, Label::kNear); |
| 3225 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3226 | __ j(not_zero, &while_true); |
| 3227 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3228 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3229 | // scratch has the original value of the exponent - if the exponent is |
| 3230 | // negative, return 1/result. |
| 3231 | __ test(exponent, exponent); |
| 3232 | __ j(positive, &done); |
| 3233 | __ divsd(double_scratch2, double_result); |
| 3234 | __ movsd(double_result, double_scratch2); |
| 3235 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3236 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3237 | __ xorps(double_scratch2, double_scratch2); |
| 3238 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3239 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3240 | // and may not have contained the exponent value in the first place when the |
| 3241 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3242 | __ j(not_equal, &done); |
| 3243 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3244 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3245 | // Returning or bailing out. |
| 3246 | Counters* counters = masm->isolate()->counters(); |
| 3247 | if (exponent_type_ == ON_STACK) { |
| 3248 | // The arguments are still on the stack. |
| 3249 | __ bind(&call_runtime); |
| 3250 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3251 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3252 | // The stub is called from non-optimized code, which expects the result |
| 3253 | // as heap number in exponent. |
| 3254 | __ bind(&done); |
| 3255 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3256 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3257 | __ IncrementCounter(counters->math_pow(), 1); |
| 3258 | __ ret(2 * kPointerSize); |
| 3259 | } else { |
| 3260 | __ bind(&call_runtime); |
| 3261 | { |
| 3262 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3263 | __ PrepareCallCFunction(4, scratch); |
| 3264 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3265 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3266 | __ CallCFunction( |
| 3267 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3268 | } |
| 3269 | // Return value is in st(0) on ia32. |
| 3270 | // Store it into the (fixed) result register. |
| 3271 | __ sub(esp, Immediate(kDoubleSize)); |
| 3272 | __ fstp_d(Operand(esp, 0)); |
| 3273 | __ movdbl(double_result, Operand(esp, 0)); |
| 3274 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3275 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3276 | __ bind(&done); |
| 3277 | __ IncrementCounter(counters->math_pow(), 1); |
| 3278 | __ ret(0); |
| 3279 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3283 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3284 | // ----------- S t a t e ------------- |
| 3285 | // -- ecx : name |
| 3286 | // -- edx : receiver |
| 3287 | // -- esp[0] : return address |
| 3288 | // ----------------------------------- |
| 3289 | Label miss; |
| 3290 | |
| 3291 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3292 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3293 | __ j(not_equal, &miss); |
| 3294 | } |
| 3295 | |
| 3296 | StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss); |
| 3297 | __ bind(&miss); |
| 3298 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3299 | } |
| 3300 | |
| 3301 | |
| 3302 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3303 | // ----------- S t a t e ------------- |
| 3304 | // -- ecx : name |
| 3305 | // -- edx : receiver |
| 3306 | // -- esp[0] : return address |
| 3307 | // ----------------------------------- |
| 3308 | Label miss; |
| 3309 | |
| 3310 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3311 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_symbol())); |
| 3312 | __ j(not_equal, &miss); |
| 3313 | } |
| 3314 | |
| 3315 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3316 | __ bind(&miss); |
| 3317 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3318 | } |
| 3319 | |
| 3320 | |
| 3321 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3322 | // ----------- S t a t e ------------- |
| 3323 | // -- ecx : name |
| 3324 | // -- edx : receiver |
| 3325 | // -- esp[0] : return address |
| 3326 | // ----------------------------------- |
| 3327 | Label miss; |
| 3328 | |
| 3329 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3330 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3331 | __ j(not_equal, &miss); |
| 3332 | } |
| 3333 | |
| 3334 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3335 | support_wrapper_); |
| 3336 | __ bind(&miss); |
| 3337 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3338 | } |
| 3339 | |
| 3340 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3341 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3342 | // ----------- S t a t e ------------- |
| 3343 | // -- eax : value |
| 3344 | // -- ecx : name |
| 3345 | // -- edx : receiver |
| 3346 | // -- esp[0] : return address |
| 3347 | // ----------------------------------- |
| 3348 | // |
| 3349 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3350 | // (currently anything except for external arrays which means anything with |
| 3351 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3352 | // accepted as the most common case. |
| 3353 | |
| 3354 | Label miss; |
| 3355 | |
| 3356 | Register receiver = edx; |
| 3357 | Register value = eax; |
| 3358 | Register scratch = ebx; |
| 3359 | |
| 3360 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3361 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3362 | __ j(not_equal, &miss); |
| 3363 | } |
| 3364 | |
| 3365 | // Check that the receiver isn't a smi. |
| 3366 | __ JumpIfSmi(receiver, &miss); |
| 3367 | |
| 3368 | // Check that the object is a JS array. |
| 3369 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3370 | __ j(not_equal, &miss); |
| 3371 | |
| 3372 | // Check that elements are FixedArray. |
| 3373 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3374 | // fast elements (including COW). |
| 3375 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3376 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3377 | __ j(not_equal, &miss); |
| 3378 | |
| 3379 | // Check that the array has fast properties, otherwise the length |
| 3380 | // property might have been redefined. |
| 3381 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3382 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3383 | Heap::kHashTableMapRootIndex); |
| 3384 | __ j(equal, &miss); |
| 3385 | |
| 3386 | // Check that value is a smi. |
| 3387 | __ JumpIfNotSmi(value, &miss); |
| 3388 | |
| 3389 | // Prepare tail call to StoreIC_ArrayLength. |
| 3390 | __ pop(scratch); |
| 3391 | __ push(receiver); |
| 3392 | __ push(value); |
| 3393 | __ push(scratch); // return address |
| 3394 | |
| 3395 | ExternalReference ref = |
| 3396 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3397 | __ TailCallExternalReference(ref, 2, 1); |
| 3398 | |
| 3399 | __ bind(&miss); |
| 3400 | |
| 3401 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 3402 | } |
| 3403 | |
| 3404 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3405 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3406 | // The key is in edx and the parameter count is in eax. |
| 3407 | |
| 3408 | // The displacement is used for skipping the frame pointer on the |
| 3409 | // stack. It is the offset of the last parameter (if any) relative |
| 3410 | // to the frame pointer. |
| 3411 | static const int kDisplacement = 1 * kPointerSize; |
| 3412 | |
| 3413 | // Check that the key is a smi. |
| 3414 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3415 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3416 | |
| 3417 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3418 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3419 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3420 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3421 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3422 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | |
| 3424 | // Check index against formal parameters count limit passed in |
| 3425 | // through register eax. Use unsigned comparison to get negative |
| 3426 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3427 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3428 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3429 | |
| 3430 | // Read the argument from the stack and return it. |
| 3431 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3432 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3433 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3434 | __ neg(edx); |
| 3435 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3436 | __ ret(0); |
| 3437 | |
| 3438 | // Arguments adaptor case: Check index against actual arguments |
| 3439 | // limit found in the arguments adaptor frame. Use unsigned |
| 3440 | // comparison to get negative check for free. |
| 3441 | __ bind(&adaptor); |
| 3442 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3443 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3444 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3445 | |
| 3446 | // Read the argument from the stack and return it. |
| 3447 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3448 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3449 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3450 | __ neg(edx); |
| 3451 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3452 | __ ret(0); |
| 3453 | |
| 3454 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3455 | // by calling the runtime system. |
| 3456 | __ bind(&slow); |
| 3457 | __ pop(ebx); // Return address. |
| 3458 | __ push(edx); |
| 3459 | __ push(ebx); |
| 3460 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3461 | } |
| 3462 | |
| 3463 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3464 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3465 | // esp[0] : return address |
| 3466 | // esp[4] : number of parameters |
| 3467 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3468 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3469 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3470 | // Check if the calling frame is an arguments adaptor frame. |
| 3471 | Label runtime; |
| 3472 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3473 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3474 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3475 | __ j(not_equal, &runtime, Label::kNear); |
| 3476 | |
| 3477 | // Patch the arguments.length and the parameters pointer. |
| 3478 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3479 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3480 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3481 | StandardFrameConstants::kCallerSPOffset)); |
| 3482 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3483 | |
| 3484 | __ bind(&runtime); |
| 3485 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3486 | } |
| 3487 | |
| 3488 | |
| 3489 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3490 | // esp[0] : return address |
| 3491 | // esp[4] : number of parameters (tagged) |
| 3492 | // esp[8] : receiver displacement |
| 3493 | // esp[12] : function |
| 3494 | |
| 3495 | // ebx = parameter count (tagged) |
| 3496 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3497 | |
| 3498 | // Check if the calling frame is an arguments adaptor frame. |
| 3499 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3500 | // Generate* functions. |
| 3501 | Label runtime; |
| 3502 | Label adaptor_frame, try_allocate; |
| 3503 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3504 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3505 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3506 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3507 | |
| 3508 | // No adaptor, parameter count = argument count. |
| 3509 | __ mov(ecx, ebx); |
| 3510 | __ jmp(&try_allocate, Label::kNear); |
| 3511 | |
| 3512 | // We have an adaptor frame. Patch the parameters pointer. |
| 3513 | __ bind(&adaptor_frame); |
| 3514 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3515 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3516 | StandardFrameConstants::kCallerSPOffset)); |
| 3517 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3518 | |
| 3519 | // ebx = parameter count (tagged) |
| 3520 | // ecx = argument count (tagged) |
| 3521 | // esp[4] = parameter count (tagged) |
| 3522 | // esp[8] = address of receiver argument |
| 3523 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3524 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3525 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3526 | __ mov(ebx, ecx); |
| 3527 | |
| 3528 | __ bind(&try_allocate); |
| 3529 | |
| 3530 | // Save mapped parameter count. |
| 3531 | __ push(ebx); |
| 3532 | |
| 3533 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3534 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3535 | const int kParameterMapHeaderSize = |
| 3536 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3537 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3538 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3539 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3540 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3541 | __ bind(&no_parameter_map); |
| 3542 | |
| 3543 | // 2. Backing store. |
| 3544 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3545 | |
| 3546 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3547 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3548 | |
| 3549 | // Do the allocation of all three objects in one go. |
| 3550 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3551 | |
| 3552 | // eax = address of new object(s) (tagged) |
| 3553 | // ecx = argument count (tagged) |
| 3554 | // esp[0] = mapped parameter count (tagged) |
| 3555 | // esp[8] = parameter count (tagged) |
| 3556 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3557 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3558 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3559 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3560 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3561 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3562 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3563 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3564 | __ mov(edi, Operand(edi, |
| 3565 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3566 | __ jmp(©, Label::kNear); |
| 3567 | |
| 3568 | __ bind(&has_mapped_parameters); |
| 3569 | __ mov(edi, Operand(edi, |
| 3570 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3571 | __ bind(©); |
| 3572 | |
| 3573 | // eax = address of new object (tagged) |
| 3574 | // ebx = mapped parameter count (tagged) |
| 3575 | // ecx = argument count (tagged) |
| 3576 | // edi = address of boilerplate object (tagged) |
| 3577 | // esp[0] = mapped parameter count (tagged) |
| 3578 | // esp[8] = parameter count (tagged) |
| 3579 | // esp[12] = address of receiver argument |
| 3580 | // Copy the JS object part. |
| 3581 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3582 | __ mov(edx, FieldOperand(edi, i)); |
| 3583 | __ mov(FieldOperand(eax, i), edx); |
| 3584 | } |
| 3585 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3586 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3587 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3588 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3589 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3590 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3591 | edx); |
| 3592 | |
| 3593 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3594 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3595 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3596 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3597 | ecx); |
| 3598 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3599 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3600 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3601 | // backing store. |
| 3602 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3603 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3604 | |
| 3605 | // eax = address of new object (tagged) |
| 3606 | // ebx = mapped parameter count (tagged) |
| 3607 | // ecx = argument count (tagged) |
| 3608 | // edi = address of parameter map or backing store (tagged) |
| 3609 | // esp[0] = mapped parameter count (tagged) |
| 3610 | // esp[8] = parameter count (tagged) |
| 3611 | // esp[12] = address of receiver argument |
| 3612 | // Free a register. |
| 3613 | __ push(eax); |
| 3614 | |
| 3615 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3616 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3617 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3618 | __ j(zero, &skip_parameter_map); |
| 3619 | |
| 3620 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3621 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3622 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3623 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3624 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3625 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3626 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3627 | |
| 3628 | // Copy the parameter slots and the holes in the arguments. |
| 3629 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3630 | // where parameters are stored in reverse order, at |
| 3631 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3632 | // The mapped parameter thus need to get indices |
| 3633 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3634 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3635 | // We loop from right to left. |
| 3636 | Label parameters_loop, parameters_test; |
| 3637 | __ push(ecx); |
| 3638 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3639 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3640 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3641 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3642 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3643 | __ mov(edx, edi); |
| 3644 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3645 | // eax = loop variable (tagged) |
| 3646 | // ebx = mapping index (tagged) |
| 3647 | // ecx = the hole value |
| 3648 | // edx = address of parameter map (tagged) |
| 3649 | // edi = address of backing store (tagged) |
| 3650 | // esp[0] = argument count (tagged) |
| 3651 | // esp[4] = address of new object (tagged) |
| 3652 | // esp[8] = mapped parameter count (tagged) |
| 3653 | // esp[16] = parameter count (tagged) |
| 3654 | // esp[20] = address of receiver argument |
| 3655 | __ jmp(¶meters_test, Label::kNear); |
| 3656 | |
| 3657 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3658 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3659 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3660 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3661 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3662 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3663 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3664 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3665 | __ pop(ecx); |
| 3666 | |
| 3667 | __ bind(&skip_parameter_map); |
| 3668 | |
| 3669 | // ecx = argument count (tagged) |
| 3670 | // edi = address of backing store (tagged) |
| 3671 | // esp[0] = address of new object (tagged) |
| 3672 | // esp[4] = mapped parameter count (tagged) |
| 3673 | // esp[12] = parameter count (tagged) |
| 3674 | // esp[16] = address of receiver argument |
| 3675 | // Copy arguments header and remaining slots (if there are any). |
| 3676 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3677 | Immediate(FACTORY->fixed_array_map())); |
| 3678 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3679 | |
| 3680 | Label arguments_loop, arguments_test; |
| 3681 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3682 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3683 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3684 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3685 | __ jmp(&arguments_test, Label::kNear); |
| 3686 | |
| 3687 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3688 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3689 | __ mov(eax, Operand(edx, 0)); |
| 3690 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3691 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3692 | |
| 3693 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3694 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3695 | __ j(less, &arguments_loop, Label::kNear); |
| 3696 | |
| 3697 | // Restore. |
| 3698 | __ pop(eax); // Address of arguments object. |
| 3699 | __ pop(ebx); // Parameter count. |
| 3700 | |
| 3701 | // Return and remove the on-stack parameters. |
| 3702 | __ ret(3 * kPointerSize); |
| 3703 | |
| 3704 | // Do the runtime call to allocate the arguments object. |
| 3705 | __ bind(&runtime); |
| 3706 | __ pop(eax); // Remove saved parameter count. |
| 3707 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3708 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | |
| 3712 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3713 | // esp[0] : return address |
| 3714 | // esp[4] : number of parameters |
| 3715 | // esp[8] : receiver displacement |
| 3716 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3717 | |
| 3718 | // Check if the calling frame is an arguments adaptor frame. |
| 3719 | Label adaptor_frame, try_allocate, runtime; |
| 3720 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3721 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3722 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3723 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3724 | |
| 3725 | // Get the length from the frame. |
| 3726 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3727 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3728 | |
| 3729 | // Patch the arguments.length and the parameters pointer. |
| 3730 | __ bind(&adaptor_frame); |
| 3731 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3732 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3733 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3734 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3735 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3736 | |
| 3737 | // Try the new space allocation. Start out with computing the size of |
| 3738 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3739 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3740 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3741 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3742 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3743 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3744 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3745 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3746 | |
| 3747 | // Do the allocation of both objects in one go. |
| 3748 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3749 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3750 | // Get the arguments boilerplate from the current native context. |
| 3751 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3752 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3753 | const int offset = |
| 3754 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3755 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3756 | |
| 3757 | // Copy the JS object part. |
| 3758 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3759 | __ mov(ebx, FieldOperand(edi, i)); |
| 3760 | __ mov(FieldOperand(eax, i), ebx); |
| 3761 | } |
| 3762 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3763 | // 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] | 3764 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3765 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3766 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3767 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3768 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3769 | |
| 3770 | // If there are no actual arguments, we're done. |
| 3771 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3772 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3773 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3774 | |
| 3775 | // Get the parameters pointer from the stack. |
| 3776 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3777 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3778 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3779 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3780 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3781 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3782 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3783 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3784 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3785 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3786 | // Untag the length for the loop below. |
| 3787 | __ SmiUntag(ecx); |
| 3788 | |
| 3789 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3790 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | __ bind(&loop); |
| 3792 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3793 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3794 | __ add(edi, Immediate(kPointerSize)); |
| 3795 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3796 | __ dec(ecx); |
| 3797 | __ j(not_zero, &loop); |
| 3798 | |
| 3799 | // Return and remove the on-stack parameters. |
| 3800 | __ bind(&done); |
| 3801 | __ ret(3 * kPointerSize); |
| 3802 | |
| 3803 | // Do the runtime call to allocate the arguments object. |
| 3804 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3805 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | |
| 3809 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3810 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3811 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3812 | // at compilation. |
| 3813 | #ifdef V8_INTERPRETED_REGEXP |
| 3814 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3815 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3816 | |
| 3817 | // Stack frame on entry. |
| 3818 | // esp[0]: return address |
| 3819 | // esp[4]: last_match_info (expected JSArray) |
| 3820 | // esp[8]: previous index |
| 3821 | // esp[12]: subject string |
| 3822 | // esp[16]: JSRegExp object |
| 3823 | |
| 3824 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3825 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3826 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3827 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3828 | |
| 3829 | Label runtime, invoke_regexp; |
| 3830 | |
| 3831 | // Ensure that a RegExp stack is allocated. |
| 3832 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3833 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3834 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3835 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3836 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3837 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3838 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3839 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3840 | |
| 3841 | // Check that the first argument is a JSRegExp object. |
| 3842 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3843 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3844 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3845 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3846 | __ j(not_equal, &runtime); |
| 3847 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3848 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3849 | if (FLAG_debug_code) { |
| 3850 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3851 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3852 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3853 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3854 | } |
| 3855 | |
| 3856 | // ecx: RegExp data (FixedArray) |
| 3857 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3858 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3859 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3860 | __ j(not_equal, &runtime); |
| 3861 | |
| 3862 | // ecx: RegExp data (FixedArray) |
| 3863 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3864 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3865 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3866 | // uses the asumption that smis are 2 * their untagged value. |
| 3867 | STATIC_ASSERT(kSmiTag == 0); |
| 3868 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3869 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3870 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3871 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3872 | __ j(above, &runtime); |
| 3873 | |
| 3874 | // ecx: RegExp data (FixedArray) |
| 3875 | // edx: Number of capture registers |
| 3876 | // Check that the second argument is a string. |
| 3877 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3878 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3879 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3880 | __ j(NegateCondition(is_string), &runtime); |
| 3881 | // Get the length of the string to ebx. |
| 3882 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3883 | |
| 3884 | // ebx: Length of subject string as a smi |
| 3885 | // ecx: RegExp data (FixedArray) |
| 3886 | // edx: Number of capture registers |
| 3887 | // Check that the third argument is a positive smi less than the subject |
| 3888 | // string length. A negative value will be greater (unsigned comparison). |
| 3889 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3890 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3891 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | __ j(above_equal, &runtime); |
| 3893 | |
| 3894 | // ecx: RegExp data (FixedArray) |
| 3895 | // edx: Number of capture registers |
| 3896 | // Check that the fourth object is a JSArray object. |
| 3897 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3898 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3899 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3900 | __ j(not_equal, &runtime); |
| 3901 | // Check that the JSArray is in fast case. |
| 3902 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3903 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3904 | Factory* factory = masm->isolate()->factory(); |
| 3905 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3906 | __ j(not_equal, &runtime); |
| 3907 | // Check that the last match info has space for the capture registers and the |
| 3908 | // additional information. |
| 3909 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3910 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3911 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3912 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3913 | __ j(greater, &runtime); |
| 3914 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3915 | // Reset offset for possibly sliced string. |
| 3916 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3917 | // ecx: RegExp data (FixedArray) |
| 3918 | // Check the representation and encoding of the subject string. |
| 3919 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3920 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3921 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3922 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3923 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3924 | __ and_(ebx, kIsNotStringMask | |
| 3925 | kStringRepresentationMask | |
| 3926 | kStringEncodingMask | |
| 3927 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3928 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3929 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3930 | // Any other flat string must be a flat ASCII string. None of the following |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3931 | // string type tests will succeed if subject is not a string or a short |
| 3932 | // external string. |
| 3933 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3934 | kStringRepresentationMask | |
| 3935 | kShortExternalStringMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3936 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3937 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3938 | // ebx: whether subject is a string and if yes, its string representation |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3939 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3940 | // A flat cons string is a cons string where the second part is the empty |
| 3941 | // string. In that case the subject string is just the first part of the cons |
| 3942 | // string. Also in this case the first part of the cons string is known to be |
| 3943 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3944 | // In the case of a sliced string its offset has to be taken into account. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3945 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3946 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3947 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3948 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3949 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3950 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3951 | __ j(less, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3952 | __ j(equal, &external_string); |
| 3953 | |
| 3954 | // Catch non-string subject or short external string. |
| 3955 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3956 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3957 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3958 | |
| 3959 | // String is sliced. |
| 3960 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3961 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3962 | // edi: offset of sliced string, smi-tagged. |
| 3963 | // eax: parent string. |
| 3964 | __ jmp(&check_encoding, Label::kNear); |
| 3965 | // String is a cons string, check whether it is flat. |
| 3966 | __ bind(&cons_string); |
| 3967 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3968 | __ j(not_equal, &runtime); |
| 3969 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3970 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3972 | // eax: first part of cons string or parent of sliced string. |
| 3973 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3974 | // Is first part of cons or parent of slice a flat two byte string? |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3975 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3976 | kStringRepresentationMask | kStringEncodingMask); |
| 3977 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3978 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3979 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3980 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3981 | kStringRepresentationMask); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3982 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3983 | |
| 3984 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3985 | // eax: subject string (flat ASCII) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | // ecx: RegExp data (FixedArray) |
| 3987 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3988 | __ Set(ecx, Immediate(1)); // Type is ASCII. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3989 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3990 | |
| 3991 | __ bind(&seq_two_byte_string); |
| 3992 | // eax: subject string (flat two byte) |
| 3993 | // ecx: RegExp data (FixedArray) |
| 3994 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3995 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3996 | |
| 3997 | __ bind(&check_code); |
| 3998 | // Check that the irregexp code has been generated for the actual string |
| 3999 | // 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] | 4000 | // a smi (code flushing support). |
| 4001 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4002 | |
| 4003 | // eax: subject string |
| 4004 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4005 | // 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] | 4006 | // Load used arguments before starting to push arguments for call to native |
| 4007 | // RegExp code to avoid handling changing stack height. |
| 4008 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4009 | __ SmiUntag(ebx); // Previous index from smi. |
| 4010 | |
| 4011 | // eax: subject string |
| 4012 | // ebx: previous index |
| 4013 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4014 | // 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] | 4015 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4016 | Counters* counters = masm->isolate()->counters(); |
| 4017 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4018 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4019 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4020 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4021 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4022 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4023 | // Argument 9: Pass current isolate address. |
| 4024 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4025 | Immediate(ExternalReference::isolate_address())); |
| 4026 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4027 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 4028 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4029 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4030 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4031 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 4032 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4033 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 4034 | |
| 4035 | // Argument 6: Set the number of capture registers to zero to force global |
| 4036 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 4037 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4038 | |
| 4039 | // Argument 5: static offsets vector buffer. |
| 4040 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4041 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 4042 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4043 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4044 | // Argument 2: Previous index. |
| 4045 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 4046 | |
| 4047 | // Argument 1: Original subject string. |
| 4048 | // The original subject is in the previous stack frame. Therefore we have to |
| 4049 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 4050 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 4051 | // and thereby moves up esp by one kPointerSize.) |
| 4052 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 4053 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 4054 | |
| 4055 | // esi: original subject string |
| 4056 | // eax: underlying subject string |
| 4057 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4058 | // 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] | 4059 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4060 | // Argument 4: End of string data |
| 4061 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4062 | // Prepare start and end index of the input. |
| 4063 | // Load the length from the original sliced string if that is the case. |
| 4064 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4065 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4066 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4067 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4068 | |
| 4069 | // ebx: start index of the input string |
| 4070 | // esi: end index of the input string |
| 4071 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4072 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4073 | __ j(zero, &setup_two_byte, Label::kNear); |
| 4074 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4075 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4076 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4077 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4078 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4079 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4080 | |
| 4081 | __ bind(&setup_two_byte); |
| 4082 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4083 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 4084 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4085 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 4086 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 4087 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 4088 | |
| 4089 | __ bind(&setup_rest); |
| 4090 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4091 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4092 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 4093 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4094 | |
| 4095 | // Drop arguments and come back to JS mode. |
| 4096 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4097 | |
| 4098 | // Check the result. |
| 4099 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4100 | __ cmp(eax, 1); |
| 4101 | // We expect exactly one result since we force the called regexp to behave |
| 4102 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4103 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4104 | Label failure; |
| 4105 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4106 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4107 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 4108 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4109 | __ j(not_equal, &runtime); |
| 4110 | // Result must now be exception. If there is no pending exception already a |
| 4111 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4112 | // haven't created the exception yet. Handle that in the runtime system. |
| 4113 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4114 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4115 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4116 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4117 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4118 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4119 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4120 | // For exception, throw the exception again. |
| 4121 | |
| 4122 | // Clear the pending exception variable. |
| 4123 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4124 | |
| 4125 | // Special handling of termination exceptions which are uncatchable |
| 4126 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4127 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4128 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4129 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4130 | |
| 4131 | // Handle normal exception by following handler chain. |
| 4132 | __ Throw(eax); |
| 4133 | |
| 4134 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4135 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4136 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4137 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4138 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4139 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4140 | __ ret(4 * kPointerSize); |
| 4141 | |
| 4142 | // Load RegExp data. |
| 4143 | __ bind(&success); |
| 4144 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4145 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4146 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4147 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4148 | STATIC_ASSERT(kSmiTag == 0); |
| 4149 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4150 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4151 | |
| 4152 | // edx: Number of capture registers |
| 4153 | // Load last_match_info which is still known to be a fast case JSArray. |
| 4154 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4155 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 4156 | |
| 4157 | // ebx: last_match_info backing store (FixedArray) |
| 4158 | // edx: number of capture registers |
| 4159 | // Store the capture count. |
| 4160 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4161 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4162 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4163 | // Store last subject and last input. |
| 4164 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4165 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4166 | __ RecordWriteField(ebx, |
| 4167 | RegExpImpl::kLastSubjectOffset, |
| 4168 | eax, |
| 4169 | edi, |
| 4170 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4172 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4173 | __ RecordWriteField(ebx, |
| 4174 | RegExpImpl::kLastInputOffset, |
| 4175 | eax, |
| 4176 | edi, |
| 4177 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4178 | |
| 4179 | // Get the static offsets vector filled by the native regexp code. |
| 4180 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4181 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4182 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4183 | |
| 4184 | // ebx: last_match_info backing store (FixedArray) |
| 4185 | // ecx: offsets vector |
| 4186 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4187 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4188 | // Capture register counter starts from number of capture registers and |
| 4189 | // counts down until wraping after zero. |
| 4190 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4191 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4192 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4193 | // Read the value from the static offsets vector buffer. |
| 4194 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4195 | __ SmiTag(edi); |
| 4196 | // Store the smi value in the last match info. |
| 4197 | __ mov(FieldOperand(ebx, |
| 4198 | edx, |
| 4199 | times_pointer_size, |
| 4200 | RegExpImpl::kFirstCaptureOffset), |
| 4201 | edi); |
| 4202 | __ jmp(&next_capture); |
| 4203 | __ bind(&done); |
| 4204 | |
| 4205 | // Return last match info. |
| 4206 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4207 | __ ret(4 * kPointerSize); |
| 4208 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4209 | // External string. Short external strings have already been ruled out. |
| 4210 | // eax: subject string (expected to be external) |
| 4211 | // ebx: scratch |
| 4212 | __ bind(&external_string); |
| 4213 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4214 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4215 | if (FLAG_debug_code) { |
| 4216 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4217 | // Sequential strings have already been ruled out. |
| 4218 | __ test_b(ebx, kIsIndirectStringMask); |
| 4219 | __ Assert(zero, "external string expected, but not found"); |
| 4220 | } |
| 4221 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4222 | // 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] | 4223 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4224 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4225 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4226 | __ test_b(ebx, kStringEncodingMask); |
| 4227 | __ j(not_zero, &seq_ascii_string); |
| 4228 | __ jmp(&seq_two_byte_string); |
| 4229 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4230 | // Do the runtime call to execute the regexp. |
| 4231 | __ bind(&runtime); |
| 4232 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4233 | #endif // V8_INTERPRETED_REGEXP |
| 4234 | } |
| 4235 | |
| 4236 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4237 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4238 | const int kMaxInlineLength = 100; |
| 4239 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4240 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4241 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4242 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4243 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4244 | __ j(above, &slowcase); |
| 4245 | // Smi-tagging is equivalent to multiplying by 2. |
| 4246 | STATIC_ASSERT(kSmiTag == 0); |
| 4247 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4248 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4249 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4250 | // Elements: [Map][Length][..elements..] |
| 4251 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4252 | times_pointer_size, |
| 4253 | ebx, // In: Number of elements as a smi |
| 4254 | REGISTER_VALUE_IS_SMI, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4255 | eax, // Out: Start of allocation (tagged). |
| 4256 | ecx, // Out: End of allocation. |
| 4257 | edx, // Scratch register |
| 4258 | &slowcase, |
| 4259 | TAG_OBJECT); |
| 4260 | // eax: Start of allocated area, object-tagged. |
| 4261 | |
| 4262 | // Set JSArray map to global.regexp_result_map(). |
| 4263 | // Set empty properties FixedArray. |
| 4264 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4265 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4266 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4267 | Factory* factory = masm->isolate()->factory(); |
| 4268 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4269 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4270 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4271 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4272 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4273 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4274 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4275 | |
| 4276 | // Set input, index and length fields from arguments. |
| 4277 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4278 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4279 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4280 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4281 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4282 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4283 | |
| 4284 | // Fill out the elements FixedArray. |
| 4285 | // eax: JSArray. |
| 4286 | // ebx: FixedArray. |
| 4287 | // ecx: Number of elements in array, as smi. |
| 4288 | |
| 4289 | // Set map. |
| 4290 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4291 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4292 | // Set length. |
| 4293 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4294 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4295 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4296 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4297 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4298 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4299 | // eax: JSArray. |
| 4300 | // ecx: Number of elements to fill. |
| 4301 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4302 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4303 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4304 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4305 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4306 | __ 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] | 4307 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4308 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4309 | __ jmp(&loop); |
| 4310 | |
| 4311 | __ bind(&done); |
| 4312 | __ ret(3 * kPointerSize); |
| 4313 | |
| 4314 | __ bind(&slowcase); |
| 4315 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4316 | } |
| 4317 | |
| 4318 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4319 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4320 | Register object, |
| 4321 | Register result, |
| 4322 | Register scratch1, |
| 4323 | Register scratch2, |
| 4324 | bool object_is_smi, |
| 4325 | Label* not_found) { |
| 4326 | // Use of registers. Register result is used as a temporary. |
| 4327 | Register number_string_cache = result; |
| 4328 | Register mask = scratch1; |
| 4329 | Register scratch = scratch2; |
| 4330 | |
| 4331 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4332 | ExternalReference roots_array_start = |
| 4333 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4334 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4335 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4336 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4337 | // Make the hash mask from the length of the number string cache. It |
| 4338 | // contains two elements (number and string) for each cache entry. |
| 4339 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4340 | __ 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] | 4341 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4342 | |
| 4343 | // Calculate the entry in the number string cache. The hash value in the |
| 4344 | // number string cache for smis is just the smi value, and the hash for |
| 4345 | // doubles is the xor of the upper and lower words. See |
| 4346 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4347 | Label smi_hash_calculated; |
| 4348 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4349 | if (object_is_smi) { |
| 4350 | __ mov(scratch, object); |
| 4351 | __ SmiUntag(scratch); |
| 4352 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4353 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4354 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4355 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4356 | __ mov(scratch, object); |
| 4357 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4358 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4359 | __ bind(¬_smi); |
| 4360 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4361 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4362 | __ j(not_equal, not_found); |
| 4363 | STATIC_ASSERT(8 == kDoubleSize); |
| 4364 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4365 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4366 | // 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] | 4367 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4368 | Register index = scratch; |
| 4369 | Register probe = mask; |
| 4370 | __ mov(probe, |
| 4371 | FieldOperand(number_string_cache, |
| 4372 | index, |
| 4373 | times_twice_pointer_size, |
| 4374 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4375 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4376 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4377 | CpuFeatures::Scope fscope(SSE2); |
| 4378 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4379 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4380 | __ ucomisd(xmm0, xmm1); |
| 4381 | } else { |
| 4382 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4383 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4384 | __ FCmp(); |
| 4385 | } |
| 4386 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4387 | __ 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] | 4388 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | __ bind(&smi_hash_calculated); |
| 4392 | // 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] | 4393 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4394 | Register index = scratch; |
| 4395 | // Check if the entry is the smi we are looking for. |
| 4396 | __ cmp(object, |
| 4397 | FieldOperand(number_string_cache, |
| 4398 | index, |
| 4399 | times_twice_pointer_size, |
| 4400 | FixedArray::kHeaderSize)); |
| 4401 | __ j(not_equal, not_found); |
| 4402 | |
| 4403 | // Get the result from the cache. |
| 4404 | __ bind(&load_result_from_cache); |
| 4405 | __ mov(result, |
| 4406 | FieldOperand(number_string_cache, |
| 4407 | index, |
| 4408 | times_twice_pointer_size, |
| 4409 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4410 | Counters* counters = masm->isolate()->counters(); |
| 4411 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | |
| 4415 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4416 | Label runtime; |
| 4417 | |
| 4418 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4419 | |
| 4420 | // Generate code to lookup number in the number string cache. |
| 4421 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4422 | __ ret(1 * kPointerSize); |
| 4423 | |
| 4424 | __ bind(&runtime); |
| 4425 | // Handle number to string in the runtime system if not found in the cache. |
| 4426 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4427 | } |
| 4428 | |
| 4429 | |
| 4430 | static int NegativeComparisonResult(Condition cc) { |
| 4431 | ASSERT(cc != equal); |
| 4432 | ASSERT((cc == less) || (cc == less_equal) |
| 4433 | || (cc == greater) || (cc == greater_equal)); |
| 4434 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4435 | } |
| 4436 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4437 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4438 | static void CheckInputType(MacroAssembler* masm, |
| 4439 | Register input, |
| 4440 | CompareIC::State expected, |
| 4441 | Label* fail) { |
| 4442 | Label ok; |
| 4443 | if (expected == CompareIC::SMI) { |
| 4444 | __ JumpIfNotSmi(input, fail); |
| 4445 | } else if (expected == CompareIC::HEAP_NUMBER) { |
| 4446 | __ JumpIfSmi(input, &ok); |
| 4447 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4448 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4449 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4450 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4451 | // We could be strict about symbol/string here, but as long as |
| 4452 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4453 | __ bind(&ok); |
| 4454 | } |
| 4455 | |
| 4456 | |
| 4457 | static void BranchIfNonSymbol(MacroAssembler* masm, |
| 4458 | Label* label, |
| 4459 | Register object, |
| 4460 | Register scratch) { |
| 4461 | __ JumpIfSmi(object, label); |
| 4462 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4463 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4464 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4465 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4466 | __ j(not_equal, label); |
| 4467 | } |
| 4468 | |
| 4469 | |
| 4470 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4471 | Label check_unequal_objects; |
| 4472 | Condition cc = GetCondition(); |
| 4473 | |
| 4474 | Label miss; |
| 4475 | CheckInputType(masm, edx, left_, &miss); |
| 4476 | CheckInputType(masm, eax, right_, &miss); |
| 4477 | |
| 4478 | // Compare two smis. |
| 4479 | Label non_smi, smi_done; |
| 4480 | __ mov(ecx, edx); |
| 4481 | __ or_(ecx, eax); |
| 4482 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4483 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4484 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4485 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4486 | __ bind(&smi_done); |
| 4487 | __ mov(eax, edx); |
| 4488 | __ ret(0); |
| 4489 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4490 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4491 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4492 | // it is certain that at least one operand isn't a smi. |
| 4493 | |
| 4494 | // Identical objects can be compared fast, but there are some tricky cases |
| 4495 | // for NaN and undefined. |
| 4496 | { |
| 4497 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4498 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4499 | __ j(not_equal, ¬_identical); |
| 4500 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4501 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4502 | // Check for undefined. undefined OP undefined is false even though |
| 4503 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4504 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4505 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4506 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4507 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4508 | __ ret(0); |
| 4509 | __ bind(&check_for_nan); |
| 4510 | } |
| 4511 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4512 | // 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] | 4513 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4514 | Label heap_number; |
| 4515 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4516 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4517 | __ j(equal, &heap_number, Label::kNear); |
| 4518 | if (cc != equal) { |
| 4519 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4520 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4521 | __ j(above_equal, ¬_identical); |
| 4522 | } |
| 4523 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4524 | __ ret(0); |
| 4525 | |
| 4526 | __ bind(&heap_number); |
| 4527 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4528 | // it's not NaN. |
| 4529 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4530 | // and not all mantissa bits (0..51) clear. |
| 4531 | // We only accept QNaNs, which have bit 51 set. |
| 4532 | // Read top bits of double representation (second word of value). |
| 4533 | |
| 4534 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4535 | // all bits in the mask are set. We only need to check the word |
| 4536 | // that contains the exponent and high bit of the mantissa. |
| 4537 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4538 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 4539 | __ Set(eax, Immediate(0)); |
| 4540 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4541 | // bits. |
| 4542 | __ add(edx, edx); |
| 4543 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4544 | if (cc == equal) { |
| 4545 | STATIC_ASSERT(EQUAL != 1); |
| 4546 | __ setcc(above_equal, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4547 | __ ret(0); |
| 4548 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4549 | Label nan; |
| 4550 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4551 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4552 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4553 | __ bind(&nan); |
| 4554 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 4555 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | __ bind(¬_identical); |
| 4559 | } |
| 4560 | |
| 4561 | // Strict equality can quickly decide whether objects are equal. |
| 4562 | // 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] | 4563 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4564 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4565 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4566 | // If we're doing a strict equality comparison, we don't have to do |
| 4567 | // type conversion, so we generate code to do fast comparison for objects |
| 4568 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4569 | // slow-case code. |
| 4570 | // If either is a Smi (we know that not both are), then they can only |
| 4571 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4572 | STATIC_ASSERT(kSmiTag == 0); |
| 4573 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4574 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4575 | __ and_(ecx, eax); |
| 4576 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4577 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4578 | // One operand is a smi. |
| 4579 | |
| 4580 | // Check whether the non-smi is a heap number. |
| 4581 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4582 | // 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] | 4583 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4584 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4585 | __ xor_(ebx, eax); |
| 4586 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4587 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4588 | // if eax was smi, ebx is now edx, else eax. |
| 4589 | |
| 4590 | // Check if the non-smi operand is a heap number. |
| 4591 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4592 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4593 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4594 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4595 | // Return non-equal (ebx is not zero) |
| 4596 | __ mov(eax, ebx); |
| 4597 | __ ret(0); |
| 4598 | |
| 4599 | __ bind(¬_smis); |
| 4600 | // If either operand is a JSObject or an oddball value, then they are not |
| 4601 | // equal since their pointers are different |
| 4602 | // There is no test for undetectability in strict equality. |
| 4603 | |
| 4604 | // Get the type of the first operand. |
| 4605 | // 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] | 4606 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4607 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4608 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4609 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4610 | |
| 4611 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4612 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4613 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4614 | __ bind(&return_not_equal); |
| 4615 | __ ret(0); |
| 4616 | |
| 4617 | __ bind(&first_non_object); |
| 4618 | // Check for oddballs: true, false, null, undefined. |
| 4619 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4620 | __ j(equal, &return_not_equal); |
| 4621 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4622 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4623 | __ j(above_equal, &return_not_equal); |
| 4624 | |
| 4625 | // Check for oddballs: true, false, null, undefined. |
| 4626 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4627 | __ j(equal, &return_not_equal); |
| 4628 | |
| 4629 | // Fall through to the general case. |
| 4630 | __ bind(&slow); |
| 4631 | } |
| 4632 | |
| 4633 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4634 | Label non_number_comparison; |
| 4635 | Label unordered; |
| 4636 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4637 | CpuFeatures::Scope use_sse2(SSE2); |
| 4638 | CpuFeatures::Scope use_cmov(CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4639 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4640 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4641 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4642 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4643 | // Don't base result on EFLAGS when a NaN is involved. |
| 4644 | __ j(parity_even, &unordered, Label::kNear); |
| 4645 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4646 | __ mov(eax, 0); // equal |
| 4647 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4648 | __ cmov(above, eax, ecx); |
| 4649 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4650 | __ cmov(below, eax, ecx); |
| 4651 | __ ret(0); |
| 4652 | } else { |
| 4653 | FloatingPointHelper::CheckFloatOperands( |
| 4654 | masm, &non_number_comparison, ebx); |
| 4655 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4656 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4657 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4658 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4659 | // Don't base result on EFLAGS when a NaN is involved. |
| 4660 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4661 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4662 | Label below_label, above_label; |
| 4663 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4664 | __ j(below, &below_label, Label::kNear); |
| 4665 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4666 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4667 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4668 | __ ret(0); |
| 4669 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4670 | __ bind(&below_label); |
| 4671 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4672 | __ ret(0); |
| 4673 | |
| 4674 | __ bind(&above_label); |
| 4675 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4676 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4679 | // If one of the numbers was NaN, then the result is always false. |
| 4680 | // The cc is never not-equal. |
| 4681 | __ bind(&unordered); |
| 4682 | ASSERT(cc != not_equal); |
| 4683 | if (cc == less || cc == less_equal) { |
| 4684 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4685 | } else { |
| 4686 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4687 | } |
| 4688 | __ ret(0); |
| 4689 | |
| 4690 | // The number comparison code did not provide a valid result. |
| 4691 | __ bind(&non_number_comparison); |
| 4692 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4693 | // Fast negative check for symbol-to-symbol equality. |
| 4694 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4695 | if (cc == equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4696 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4697 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4698 | |
| 4699 | // We've already checked for object identity, so if both operands |
| 4700 | // are symbols they aren't equal. Register eax already holds a |
| 4701 | // non-zero value, which indicates not equal, so just return. |
| 4702 | __ ret(0); |
| 4703 | } |
| 4704 | |
| 4705 | __ bind(&check_for_strings); |
| 4706 | |
| 4707 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4708 | &check_unequal_objects); |
| 4709 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4710 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4711 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4712 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4713 | edx, |
| 4714 | eax, |
| 4715 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4716 | ebx); |
| 4717 | } else { |
| 4718 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4719 | edx, |
| 4720 | eax, |
| 4721 | ecx, |
| 4722 | ebx, |
| 4723 | edi); |
| 4724 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4725 | #ifdef DEBUG |
| 4726 | __ Abort("Unexpected fall-through from string comparison"); |
| 4727 | #endif |
| 4728 | |
| 4729 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4730 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4731 | // Non-strict equality. Objects are unequal if |
| 4732 | // they are both JSObjects and not undetectable, |
| 4733 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4734 | Label not_both_objects; |
| 4735 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4736 | // At most one is a smi, so we can test for smi by adding the two. |
| 4737 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4738 | // a heap object has the low bit clear. |
| 4739 | STATIC_ASSERT(kSmiTag == 0); |
| 4740 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4741 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4742 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4743 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4744 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4745 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4746 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4747 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4748 | // We do not bail out after this point. Both are JSObjects, and |
| 4749 | // they are equal if and only if both are undetectable. |
| 4750 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4751 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4752 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4753 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4754 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4755 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4756 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4757 | // The objects are both undetectable, so they both compare as the value |
| 4758 | // undefined, and are equal. |
| 4759 | __ Set(eax, Immediate(EQUAL)); |
| 4760 | __ bind(&return_unequal); |
| 4761 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4762 | // or return equal if we fell through to here. |
| 4763 | __ ret(0); // rax, rdx were pushed |
| 4764 | __ bind(¬_both_objects); |
| 4765 | } |
| 4766 | |
| 4767 | // Push arguments below the return address. |
| 4768 | __ pop(ecx); |
| 4769 | __ push(edx); |
| 4770 | __ push(eax); |
| 4771 | |
| 4772 | // Figure out which native to call and setup the arguments. |
| 4773 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4774 | if (cc == equal) { |
| 4775 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4776 | } else { |
| 4777 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4778 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | // Restore return address on the stack. |
| 4782 | __ push(ecx); |
| 4783 | |
| 4784 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4785 | // tagged as a small integer. |
| 4786 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4787 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4788 | __ bind(&miss); |
| 4789 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | |
| 4793 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4794 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4798 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4799 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4800 | } |
| 4801 | |
| 4802 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4803 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4804 | // Cache the called function in a global property cell. Cache states |
| 4805 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4806 | // megamorphic. |
| 4807 | // ebx : cache cell for call target |
| 4808 | // edi : the function to call |
| 4809 | Isolate* isolate = masm->isolate(); |
| 4810 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4811 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4812 | // Load the cache state into ecx. |
| 4813 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4814 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4815 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4816 | // function without changing the state. |
| 4817 | __ cmp(ecx, edi); |
| 4818 | __ j(equal, &done, Label::kNear); |
| 4819 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4820 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4821 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4822 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4823 | // megamorphic. |
| 4824 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4825 | __ j(equal, &initialize, Label::kNear); |
| 4826 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4827 | // write-barrier is needed. |
| 4828 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4829 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4830 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4831 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4832 | // An uninitialized cache is patched with the function. |
| 4833 | __ bind(&initialize); |
| 4834 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4835 | // No need for a write barrier here - cells are rescanned. |
| 4836 | |
| 4837 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4841 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4842 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4843 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4844 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4845 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4846 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4847 | // The receiver might implicitly be the global object. This is |
| 4848 | // indicated by passing the hole as the receiver to the call |
| 4849 | // function stub. |
| 4850 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4851 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4852 | // Get the receiver from the stack. |
| 4853 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4854 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4855 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4856 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4857 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4858 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4859 | __ mov(ecx, GlobalObjectOperand()); |
| 4860 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4861 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4862 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4865 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4866 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4867 | // Goto slow case if we do not have a function. |
| 4868 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4869 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4870 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4871 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4872 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4875 | // Fast-case: Just invoke the function. |
| 4876 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4877 | |
| 4878 | if (ReceiverMightBeImplicit()) { |
| 4879 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4880 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4881 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4882 | __ InvokeFunction(edi, |
| 4883 | actual, |
| 4884 | JUMP_FUNCTION, |
| 4885 | NullCallWrapper(), |
| 4886 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4887 | __ bind(&call_as_function); |
| 4888 | } |
| 4889 | __ InvokeFunction(edi, |
| 4890 | actual, |
| 4891 | JUMP_FUNCTION, |
| 4892 | NullCallWrapper(), |
| 4893 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4894 | |
| 4895 | // Slow-case: Non-function called. |
| 4896 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4897 | if (RecordCallTarget()) { |
| 4898 | // 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] | 4899 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4900 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4901 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4902 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4903 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4904 | // Check for function proxy. |
| 4905 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4906 | __ j(not_equal, &non_function); |
| 4907 | __ pop(ecx); |
| 4908 | __ push(edi); // put proxy as additional argument under return address |
| 4909 | __ push(ecx); |
| 4910 | __ Set(eax, Immediate(argc_ + 1)); |
| 4911 | __ Set(ebx, Immediate(0)); |
| 4912 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4913 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4914 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4915 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4916 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4917 | } |
| 4918 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4919 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4920 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4921 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4922 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4923 | __ Set(eax, Immediate(argc_)); |
| 4924 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4925 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4926 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4927 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4928 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4929 | } |
| 4930 | |
| 4931 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4932 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4933 | // eax : number of arguments |
| 4934 | // ebx : cache cell for call target |
| 4935 | // edi : constructor function |
| 4936 | Label slow, non_function_call; |
| 4937 | |
| 4938 | // Check that function is not a smi. |
| 4939 | __ JumpIfSmi(edi, &non_function_call); |
| 4940 | // Check that function is a JSFunction. |
| 4941 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4942 | __ j(not_equal, &slow); |
| 4943 | |
| 4944 | if (RecordCallTarget()) { |
| 4945 | GenerateRecordCallTarget(masm); |
| 4946 | } |
| 4947 | |
| 4948 | // Jump to the function-specific construct stub. |
| 4949 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4950 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4951 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4952 | __ jmp(ebx); |
| 4953 | |
| 4954 | // edi: called object |
| 4955 | // eax: number of arguments |
| 4956 | // ecx: object map |
| 4957 | Label do_call; |
| 4958 | __ bind(&slow); |
| 4959 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4960 | __ j(not_equal, &non_function_call); |
| 4961 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4962 | __ jmp(&do_call); |
| 4963 | |
| 4964 | __ bind(&non_function_call); |
| 4965 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4966 | __ bind(&do_call); |
| 4967 | // Set expected number of arguments to zero (not changing eax). |
| 4968 | __ Set(ebx, Immediate(0)); |
| 4969 | Handle<Code> arguments_adaptor = |
| 4970 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4971 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4972 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4973 | } |
| 4974 | |
| 4975 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4976 | bool CEntryStub::NeedsImmovableCode() { |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
| 4980 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4981 | bool CEntryStub::IsPregenerated() { |
| 4982 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4983 | result_size_ == 1; |
| 4984 | } |
| 4985 | |
| 4986 | |
| 4987 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4988 | CEntryStub::GenerateAheadOfTime(); |
| 4989 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4990 | // It is important that the store buffer overflow stubs are generated first. |
| 4991 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4992 | } |
| 4993 | |
| 4994 | |
| 4995 | void CodeStub::GenerateFPStubs() { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4996 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4997 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4998 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4999 | // which would lead to code stub initialization state being messed up. |
| 5000 | Code* save_doubles_code; |
| 5001 | if (!save_doubles.FindCodeInCache(&save_doubles_code, ISOLATE)) { |
| 5002 | save_doubles_code = *(save_doubles.GetCode()); |
| 5003 | } |
| 5004 | save_doubles_code->set_is_pregenerated(true); |
| 5005 | save_doubles_code->GetIsolate()->set_fp_stubs_generated(true); |
| 5006 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | |
| 5010 | void CEntryStub::GenerateAheadOfTime() { |
| 5011 | CEntryStub stub(1, kDontSaveFPRegs); |
| 5012 | Handle<Code> code = stub.GetCode(); |
| 5013 | code->set_is_pregenerated(true); |
| 5014 | } |
| 5015 | |
| 5016 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5017 | static void JumpIfOOM(MacroAssembler* masm, |
| 5018 | Register value, |
| 5019 | Register scratch, |
| 5020 | Label* oom_label) { |
| 5021 | __ mov(scratch, value); |
| 5022 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 5023 | STATIC_ASSERT(kFailureTag == 3); |
| 5024 | __ and_(scratch, 0xf); |
| 5025 | __ cmp(scratch, 0xf); |
| 5026 | __ j(equal, oom_label); |
| 5027 | } |
| 5028 | |
| 5029 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5030 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5031 | Label* throw_normal_exception, |
| 5032 | Label* throw_termination_exception, |
| 5033 | Label* throw_out_of_memory_exception, |
| 5034 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5035 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5036 | // eax: result parameter for PerformGC, if any |
| 5037 | // ebx: pointer to C function (C callee-saved) |
| 5038 | // ebp: frame pointer (restored after C call) |
| 5039 | // esp: stack pointer (restored after C call) |
| 5040 | // edi: number of arguments including receiver (C callee-saved) |
| 5041 | // esi: pointer to the first argument (C callee-saved) |
| 5042 | |
| 5043 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5044 | |
| 5045 | // Check stack alignment. |
| 5046 | if (FLAG_debug_code) { |
| 5047 | __ CheckStackAlignment(); |
| 5048 | } |
| 5049 | |
| 5050 | if (do_gc) { |
| 5051 | // Pass failure code returned from last attempt as first argument to |
| 5052 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5053 | // stack alignment is known to be correct. This function takes one argument |
| 5054 | // which is passed on the stack, and we know that the stack has been |
| 5055 | // prepared to pass at least one argument. |
| 5056 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5057 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5058 | } |
| 5059 | |
| 5060 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5061 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5062 | if (always_allocate_scope) { |
| 5063 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5064 | } |
| 5065 | |
| 5066 | // Call C function. |
| 5067 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5068 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5069 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5070 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5071 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5072 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5073 | |
| 5074 | if (always_allocate_scope) { |
| 5075 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5076 | } |
| 5077 | |
| 5078 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5079 | // call as this may lead to crashes in the IC code later. |
| 5080 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5081 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5082 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5083 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5084 | __ int3(); |
| 5085 | __ bind(&okay); |
| 5086 | } |
| 5087 | |
| 5088 | // Check for failure result. |
| 5089 | Label failure_returned; |
| 5090 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5091 | __ lea(ecx, Operand(eax, 1)); |
| 5092 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5093 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5094 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5095 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5096 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5097 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5098 | |
| 5099 | // Check that there is no pending exception, otherwise we |
| 5100 | // should have returned some failure value. |
| 5101 | if (FLAG_debug_code) { |
| 5102 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5103 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5104 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5105 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5106 | // 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] | 5107 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5108 | __ int3(); |
| 5109 | __ bind(&okay); |
| 5110 | __ pop(edx); |
| 5111 | } |
| 5112 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5113 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5114 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5115 | __ ret(0); |
| 5116 | |
| 5117 | // Handling of failure. |
| 5118 | __ bind(&failure_returned); |
| 5119 | |
| 5120 | Label retry; |
| 5121 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5122 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5123 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5124 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5125 | |
| 5126 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5127 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5128 | |
| 5129 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5130 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5131 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5132 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5133 | |
| 5134 | // Special handling of termination exceptions which are uncatchable |
| 5135 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5136 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5137 | __ j(equal, throw_termination_exception); |
| 5138 | |
| 5139 | // Handle normal exception. |
| 5140 | __ jmp(throw_normal_exception); |
| 5141 | |
| 5142 | // Retry. |
| 5143 | __ bind(&retry); |
| 5144 | } |
| 5145 | |
| 5146 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5147 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5148 | // eax: number of arguments including receiver |
| 5149 | // ebx: pointer to C function (C callee-saved) |
| 5150 | // ebp: frame pointer (restored after C call) |
| 5151 | // esp: stack pointer (restored after C call) |
| 5152 | // esi: current context (C callee-saved) |
| 5153 | // edi: JS function of the caller (C callee-saved) |
| 5154 | |
| 5155 | // NOTE: Invocations of builtins may return failure objects instead |
| 5156 | // of a proper result. The builtin entry handles this by performing |
| 5157 | // a garbage collection and retrying the builtin (twice). |
| 5158 | |
| 5159 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5160 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5161 | |
| 5162 | // eax: result parameter for PerformGC, if any (setup below) |
| 5163 | // ebx: pointer to builtin function (C callee-saved) |
| 5164 | // ebp: frame pointer (restored after C call) |
| 5165 | // esp: stack pointer (restored after C call) |
| 5166 | // edi: number of arguments including receiver (C callee-saved) |
| 5167 | // esi: argv pointer (C callee-saved) |
| 5168 | |
| 5169 | Label throw_normal_exception; |
| 5170 | Label throw_termination_exception; |
| 5171 | Label throw_out_of_memory_exception; |
| 5172 | |
| 5173 | // Call into the runtime system. |
| 5174 | GenerateCore(masm, |
| 5175 | &throw_normal_exception, |
| 5176 | &throw_termination_exception, |
| 5177 | &throw_out_of_memory_exception, |
| 5178 | false, |
| 5179 | false); |
| 5180 | |
| 5181 | // Do space-specific GC and retry runtime call. |
| 5182 | GenerateCore(masm, |
| 5183 | &throw_normal_exception, |
| 5184 | &throw_termination_exception, |
| 5185 | &throw_out_of_memory_exception, |
| 5186 | true, |
| 5187 | false); |
| 5188 | |
| 5189 | // Do full GC and retry runtime call one final time. |
| 5190 | Failure* failure = Failure::InternalError(); |
| 5191 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5192 | GenerateCore(masm, |
| 5193 | &throw_normal_exception, |
| 5194 | &throw_termination_exception, |
| 5195 | &throw_out_of_memory_exception, |
| 5196 | true, |
| 5197 | true); |
| 5198 | |
| 5199 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5200 | // Set external caught exception to false. |
| 5201 | Isolate* isolate = masm->isolate(); |
| 5202 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5203 | isolate); |
| 5204 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5205 | |
| 5206 | // Set pending exception and eax to out of memory exception. |
| 5207 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5208 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5209 | Label already_have_failure; |
| 5210 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5211 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5212 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5213 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5214 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5215 | |
| 5216 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5217 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5218 | |
| 5219 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5220 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | } |
| 5222 | |
| 5223 | |
| 5224 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5225 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5226 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5227 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5228 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5230 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5231 | |
| 5232 | // Push marker in two places. |
| 5233 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5234 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5235 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5236 | // Save callee-saved registers (C calling conventions). |
| 5237 | __ push(edi); |
| 5238 | __ push(esi); |
| 5239 | __ push(ebx); |
| 5240 | |
| 5241 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5242 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5243 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5244 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5245 | // 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] | 5246 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5247 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5248 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5249 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5250 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5251 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5252 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5253 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5254 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5255 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5256 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5257 | // block that sets the pending exception. |
| 5258 | __ jmp(&invoke); |
| 5259 | __ bind(&handler_entry); |
| 5260 | handler_offset_ = handler_entry.pos(); |
| 5261 | // Caught exception: Store result (exception) in the pending exception |
| 5262 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5263 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5264 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5265 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5266 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5267 | __ jmp(&exit); |
| 5268 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5269 | // Invoke: Link this frame into the handler chain. There's only one |
| 5270 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5271 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5272 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5273 | |
| 5274 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5275 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5276 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5277 | |
| 5278 | // Fake a receiver (NULL). |
| 5279 | __ push(Immediate(0)); // receiver |
| 5280 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5281 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5282 | // pop the faked function when we return. Notice that we cannot store a |
| 5283 | // reference to the trampoline code directly in this stub, because the |
| 5284 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5285 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5286 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5287 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5288 | __ mov(edx, Immediate(construct_entry)); |
| 5289 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5290 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5291 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5292 | __ mov(edx, Immediate(entry)); |
| 5293 | } |
| 5294 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5295 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5296 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | |
| 5298 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5299 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5301 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5302 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5303 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5304 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5305 | __ j(not_equal, ¬_outermost_js_2); |
| 5306 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5307 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5308 | |
| 5309 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5310 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5311 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5312 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5313 | |
| 5314 | // Restore callee-saved registers (C calling conventions). |
| 5315 | __ pop(ebx); |
| 5316 | __ pop(esi); |
| 5317 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5318 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5319 | |
| 5320 | // Restore frame pointer and return. |
| 5321 | __ pop(ebp); |
| 5322 | __ ret(0); |
| 5323 | } |
| 5324 | |
| 5325 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5326 | // Generate stub code for instanceof. |
| 5327 | // This code can patch a call site inlined cache of the instance of check, |
| 5328 | // which looks like this. |
| 5329 | // |
| 5330 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5331 | // 75 0a jne <some near label> |
| 5332 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5333 | // |
| 5334 | // If call site patching is requested the stack will have the delta from the |
| 5335 | // return address to the cmp instruction just below the return address. This |
| 5336 | // also means that call site patching can only take place with arguments in |
| 5337 | // registers. TOS looks like this when call site patching is requested |
| 5338 | // |
| 5339 | // esp[0] : return address |
| 5340 | // esp[4] : delta from return address to cmp instruction |
| 5341 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5342 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5343 | // Call site inlining and patching implies arguments in registers. |
| 5344 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5345 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5346 | // Fixed register usage throughout the stub. |
| 5347 | Register object = eax; // Object (lhs). |
| 5348 | Register map = ebx; // Map of the object. |
| 5349 | Register function = edx; // Function (rhs). |
| 5350 | Register prototype = edi; // Prototype of the function. |
| 5351 | Register scratch = ecx; |
| 5352 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5353 | // Constants describing the call site code to patch. |
| 5354 | static const int kDeltaToCmpImmediate = 2; |
| 5355 | static const int kDeltaToMov = 8; |
| 5356 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5357 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5358 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5359 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5360 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5361 | ExternalReference roots_array_start = |
| 5362 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5363 | |
| 5364 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5365 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5366 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5367 | // Get the object and function - they are always both needed. |
| 5368 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5369 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5370 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5371 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5372 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5373 | |
| 5374 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5375 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5376 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5378 | // If there is a call site cache don't look in the global cache, but do the |
| 5379 | // real lookup and update the call site cache. |
| 5380 | if (!HasCallSiteInlineCheck()) { |
| 5381 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5382 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5383 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5384 | __ cmp(function, Operand::StaticArray(scratch, |
| 5385 | times_pointer_size, |
| 5386 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5387 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5388 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5389 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5390 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5391 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5392 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5393 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5394 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5395 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5396 | __ bind(&miss); |
| 5397 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5398 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5399 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5400 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5401 | |
| 5402 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5403 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5404 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5406 | // Update the global instanceof or call site inlined cache with the current |
| 5407 | // map and function. The cached answer will be set when it is known below. |
| 5408 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5409 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5410 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5411 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5412 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5413 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5414 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5415 | } else { |
| 5416 | // The constants for the code patching are based on no push instructions |
| 5417 | // at the call site. |
| 5418 | ASSERT(HasArgsInRegisters()); |
| 5419 | // Get return address and delta to inlined map check. |
| 5420 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5421 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5422 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5423 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5424 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5425 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5426 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5427 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5428 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5429 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5430 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5431 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5432 | // Loop through the prototype chain of the object looking for the function |
| 5433 | // prototype. |
| 5434 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5435 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5436 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5437 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5438 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5439 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5440 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5441 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5442 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5443 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5444 | __ jmp(&loop); |
| 5445 | |
| 5446 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5447 | if (!HasCallSiteInlineCheck()) { |
| 5448 | __ Set(eax, Immediate(0)); |
| 5449 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5450 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5451 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5452 | } else { |
| 5453 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5454 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5455 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5456 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5457 | if (FLAG_debug_code) { |
| 5458 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5459 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5460 | } |
| 5461 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5462 | if (!ReturnTrueFalseObject()) { |
| 5463 | __ Set(eax, Immediate(0)); |
| 5464 | } |
| 5465 | } |
| 5466 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5467 | |
| 5468 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5469 | if (!HasCallSiteInlineCheck()) { |
| 5470 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5471 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5472 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5473 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5474 | } else { |
| 5475 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5476 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5477 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5478 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5479 | if (FLAG_debug_code) { |
| 5480 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5481 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5482 | } |
| 5483 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5484 | if (!ReturnTrueFalseObject()) { |
| 5485 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5486 | } |
| 5487 | } |
| 5488 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5489 | |
| 5490 | Label object_not_null, object_not_null_or_smi; |
| 5491 | __ bind(¬_js_object); |
| 5492 | // Before null, smi and string value checks, check that the rhs is a function |
| 5493 | // 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] | 5494 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5495 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5496 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5497 | |
| 5498 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5499 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5500 | __ j(not_equal, &object_not_null, 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); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5503 | |
| 5504 | __ bind(&object_not_null); |
| 5505 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5506 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5507 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5508 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5509 | |
| 5510 | __ bind(&object_not_null_or_smi); |
| 5511 | // String values is not instance of anything. |
| 5512 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5513 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5514 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5515 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5516 | |
| 5517 | // Slow-case: Go through the JavaScript implementation. |
| 5518 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5519 | if (!ReturnTrueFalseObject()) { |
| 5520 | // Tail call the builtin which returns 0 or 1. |
| 5521 | if (HasArgsInRegisters()) { |
| 5522 | // Push arguments below return address. |
| 5523 | __ pop(scratch); |
| 5524 | __ push(object); |
| 5525 | __ push(function); |
| 5526 | __ push(scratch); |
| 5527 | } |
| 5528 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5529 | } else { |
| 5530 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5531 | { |
| 5532 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5533 | __ push(object); |
| 5534 | __ push(function); |
| 5535 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5536 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5537 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5538 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5539 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5540 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5541 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5542 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5543 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5544 | __ bind(&done); |
| 5545 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5546 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5550 | Register InstanceofStub::left() { return eax; } |
| 5551 | |
| 5552 | |
| 5553 | Register InstanceofStub::right() { return edx; } |
| 5554 | |
| 5555 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5556 | // ------------------------------------------------------------------------- |
| 5557 | // StringCharCodeAtGenerator |
| 5558 | |
| 5559 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5560 | // If the receiver is a smi trigger the non-string case. |
| 5561 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5562 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5563 | |
| 5564 | // Fetch the instance type of the receiver into result register. |
| 5565 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5566 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5567 | // If the receiver is not a string trigger the non-string case. |
| 5568 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5569 | __ j(not_zero, receiver_not_string_); |
| 5570 | |
| 5571 | // If the index is non-smi trigger the non-smi case. |
| 5572 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5573 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5574 | __ bind(&got_smi_index_); |
| 5575 | |
| 5576 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5577 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5578 | __ j(above_equal, index_out_of_range_); |
| 5579 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5580 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5581 | |
| 5582 | Factory* factory = masm->isolate()->factory(); |
| 5583 | StringCharLoadGenerator::Generate( |
| 5584 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5585 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5586 | __ SmiTag(result_); |
| 5587 | __ bind(&exit_); |
| 5588 | } |
| 5589 | |
| 5590 | |
| 5591 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5592 | MacroAssembler* masm, |
| 5593 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5594 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5595 | |
| 5596 | // Index is not a smi. |
| 5597 | __ bind(&index_not_smi_); |
| 5598 | // 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] | 5599 | __ CheckMap(index_, |
| 5600 | masm->isolate()->factory()->heap_number_map(), |
| 5601 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5602 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5603 | call_helper.BeforeCall(masm); |
| 5604 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | __ push(index_); // Consumed by runtime conversion function. |
| 5606 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5607 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5608 | } else { |
| 5609 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5610 | // NumberToSmi discards numbers that are not exact integers. |
| 5611 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5612 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5613 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5614 | // Save the conversion result before the pop instructions below |
| 5615 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5616 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5617 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5618 | __ pop(object_); |
| 5619 | // Reload the instance type. |
| 5620 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5621 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5622 | call_helper.AfterCall(masm); |
| 5623 | // If index is still not a smi, it must be out of range. |
| 5624 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5625 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5626 | // Otherwise, return to the fast path. |
| 5627 | __ jmp(&got_smi_index_); |
| 5628 | |
| 5629 | // Call runtime. We get here when the receiver is a string and the |
| 5630 | // index is a number, but the code of getting the actual character |
| 5631 | // is too complex (e.g., when the string needs to be flattened). |
| 5632 | __ bind(&call_runtime_); |
| 5633 | call_helper.BeforeCall(masm); |
| 5634 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5635 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5636 | __ push(index_); |
| 5637 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5638 | if (!result_.is(eax)) { |
| 5639 | __ mov(result_, eax); |
| 5640 | } |
| 5641 | call_helper.AfterCall(masm); |
| 5642 | __ jmp(&exit_); |
| 5643 | |
| 5644 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5645 | } |
| 5646 | |
| 5647 | |
| 5648 | // ------------------------------------------------------------------------- |
| 5649 | // StringCharFromCodeGenerator |
| 5650 | |
| 5651 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5652 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5653 | STATIC_ASSERT(kSmiTag == 0); |
| 5654 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5655 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5656 | __ test(code_, |
| 5657 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5658 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5659 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5661 | Factory* factory = masm->isolate()->factory(); |
| 5662 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5663 | STATIC_ASSERT(kSmiTag == 0); |
| 5664 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5665 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5666 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5667 | __ mov(result_, FieldOperand(result_, |
| 5668 | code_, times_half_pointer_size, |
| 5669 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5670 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5671 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5672 | __ bind(&exit_); |
| 5673 | } |
| 5674 | |
| 5675 | |
| 5676 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5677 | MacroAssembler* masm, |
| 5678 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5679 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5680 | |
| 5681 | __ bind(&slow_case_); |
| 5682 | call_helper.BeforeCall(masm); |
| 5683 | __ push(code_); |
| 5684 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5685 | if (!result_.is(eax)) { |
| 5686 | __ mov(result_, eax); |
| 5687 | } |
| 5688 | call_helper.AfterCall(masm); |
| 5689 | __ jmp(&exit_); |
| 5690 | |
| 5691 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5692 | } |
| 5693 | |
| 5694 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5695 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5696 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5697 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5698 | |
| 5699 | // Load the two arguments. |
| 5700 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5701 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5702 | |
| 5703 | // 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] | 5704 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5705 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5706 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5707 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5708 | |
| 5709 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5710 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5711 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5712 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5713 | } else { |
| 5714 | // Here at least one of the arguments is definitely a string. |
| 5715 | // We convert the one that is not known to be a string. |
| 5716 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5717 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5718 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5719 | &call_builtin); |
| 5720 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5721 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5722 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5723 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5724 | &call_builtin); |
| 5725 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5726 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | // Both arguments are strings. |
| 5730 | // eax: first string |
| 5731 | // edx: second string |
| 5732 | // 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] | 5733 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5734 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5735 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5736 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5737 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5738 | // 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] | 5739 | Counters* counters = masm->isolate()->counters(); |
| 5740 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5741 | __ ret(2 * kPointerSize); |
| 5742 | __ bind(&second_not_zero_length); |
| 5743 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5744 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5745 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5746 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5747 | // First string is empty, result is second string which is in edx. |
| 5748 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5749 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5750 | __ ret(2 * kPointerSize); |
| 5751 | |
| 5752 | // Both strings are non-empty. |
| 5753 | // eax: first string |
| 5754 | // ebx: length of first string as a smi |
| 5755 | // ecx: length of second string as a smi |
| 5756 | // edx: second string |
| 5757 | // Look at the length of the result of adding the two strings. |
| 5758 | Label string_add_flat_result, longer_than_two; |
| 5759 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5760 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5761 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5762 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5763 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5764 | // Use the symbol table when adding two one character strings, as it |
| 5765 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5766 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5767 | __ j(not_equal, &longer_than_two); |
| 5768 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5769 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5770 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5771 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5772 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5773 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5774 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5775 | |
| 5776 | // Try to lookup two character string in symbol table. If it is not found |
| 5777 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5778 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5779 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5780 | masm, ebx, ecx, eax, edx, edi, |
| 5781 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5782 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5783 | __ ret(2 * kPointerSize); |
| 5784 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5785 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5786 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5787 | // Reload the arguments. |
| 5788 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5789 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5790 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5791 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5792 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5793 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5794 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5795 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5796 | // Pack both characters in ebx. |
| 5797 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5798 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5799 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5800 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5801 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5802 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5803 | |
| 5804 | __ bind(&longer_than_two); |
| 5805 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5806 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5807 | __ j(below, &string_add_flat_result); |
| 5808 | |
| 5809 | // 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] | 5810 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5811 | Label non_ascii, allocated, ascii_data; |
| 5812 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5813 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5814 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5815 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5816 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5817 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5818 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5819 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5820 | __ j(zero, &non_ascii); |
| 5821 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5822 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5823 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5824 | __ bind(&allocated); |
| 5825 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5826 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5827 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5828 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5829 | Immediate(String::kEmptyHashField)); |
| 5830 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5831 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5832 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5833 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5834 | __ ret(2 * kPointerSize); |
| 5835 | __ bind(&non_ascii); |
| 5836 | // 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] | 5837 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | // ecx: first instance type AND second instance type. |
| 5839 | // edi: second instance type. |
| 5840 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5841 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5842 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5843 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5844 | __ xor_(edi, ecx); |
| 5845 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5846 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5847 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5848 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5849 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5850 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5851 | __ jmp(&allocated); |
| 5852 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5853 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5854 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5855 | // Handle creating a flat result from either external or sequential strings. |
| 5856 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5857 | // eax: first string |
| 5858 | // ebx: length of resulting flat string as a smi |
| 5859 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5860 | Label first_prepared, second_prepared; |
| 5861 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5862 | __ bind(&string_add_flat_result); |
| 5863 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5864 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5865 | // ecx: instance type of first string |
| 5866 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5867 | __ test_b(ecx, kStringRepresentationMask); |
| 5868 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5869 | // Rule out short external string and load string resource. |
| 5870 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5871 | __ test_b(ecx, kShortExternalStringMask); |
| 5872 | __ j(not_zero, &call_runtime); |
| 5873 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5874 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5875 | __ jmp(&first_prepared, Label::kNear); |
| 5876 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5877 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5878 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5879 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5880 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5881 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5882 | // Check whether both strings have same encoding. |
| 5883 | // edi: instance type of second string |
| 5884 | __ xor_(ecx, edi); |
| 5885 | __ test_b(ecx, kStringEncodingMask); |
| 5886 | __ j(not_zero, &call_runtime); |
| 5887 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5888 | __ test_b(edi, kStringRepresentationMask); |
| 5889 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5890 | // Rule out short external string and load string resource. |
| 5891 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5892 | __ test_b(edi, kShortExternalStringMask); |
| 5893 | __ j(not_zero, &call_runtime); |
| 5894 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5895 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5896 | __ jmp(&second_prepared, Label::kNear); |
| 5897 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5898 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5899 | __ bind(&second_prepared); |
| 5900 | |
| 5901 | // Push the addresses of both strings' first characters onto the stack. |
| 5902 | __ push(edx); |
| 5903 | __ push(eax); |
| 5904 | |
| 5905 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5906 | // edi: instance type of second string |
| 5907 | // First string and second string have the same encoding. |
| 5908 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5909 | __ test_b(edi, kStringEncodingMask); |
| 5910 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5911 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5912 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | // ebx: length of resulting flat string as a smi |
| 5914 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5915 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | // eax: result string |
| 5917 | __ mov(ecx, eax); |
| 5918 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5919 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5920 | // Load first argument's length and first character location. Account for |
| 5921 | // values currently on the stack when fetching arguments from it. |
| 5922 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5923 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5924 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5925 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5926 | // eax: result string |
| 5927 | // ecx: first character of result |
| 5928 | // edx: first char of first argument |
| 5929 | // edi: length of first argument |
| 5930 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5931 | // Load second argument's length and first character location. Account for |
| 5932 | // values currently on the stack when fetching arguments from it. |
| 5933 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5934 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5935 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5936 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5937 | // eax: result string |
| 5938 | // ecx: next character of result |
| 5939 | // edx: first char of second argument |
| 5940 | // edi: length of second argument |
| 5941 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5942 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5943 | __ ret(2 * kPointerSize); |
| 5944 | |
| 5945 | // Handle creating a flat two byte result. |
| 5946 | // eax: first string - known to be two byte |
| 5947 | // ebx: length of resulting flat string as a smi |
| 5948 | // edx: second string |
| 5949 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5950 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5951 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5952 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5953 | // eax: result string |
| 5954 | __ mov(ecx, eax); |
| 5955 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5956 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5957 | // Load second argument's length and first character location. Account for |
| 5958 | // values currently on the stack when fetching arguments from it. |
| 5959 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5960 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5961 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5962 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5963 | // eax: result string |
| 5964 | // ecx: first character of result |
| 5965 | // edx: first char of first argument |
| 5966 | // edi: length of first argument |
| 5967 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5968 | // Load second argument's length and first character location. Account for |
| 5969 | // values currently on the stack when fetching arguments from it. |
| 5970 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5971 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5972 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5973 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5974 | // eax: result string |
| 5975 | // ecx: next character of result |
| 5976 | // edx: first char of second argument |
| 5977 | // edi: length of second argument |
| 5978 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5979 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5980 | __ ret(2 * kPointerSize); |
| 5981 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5982 | // Recover stack pointer before jumping to runtime. |
| 5983 | __ bind(&call_runtime_drop_two); |
| 5984 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5985 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5986 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5987 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5988 | |
| 5989 | if (call_builtin.is_linked()) { |
| 5990 | __ bind(&call_builtin); |
| 5991 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | |
| 5996 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5997 | int stack_offset, |
| 5998 | Register arg, |
| 5999 | Register scratch1, |
| 6000 | Register scratch2, |
| 6001 | Register scratch3, |
| 6002 | Label* slow) { |
| 6003 | // First check if the argument is already a string. |
| 6004 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6005 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6006 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6007 | __ j(below, &done); |
| 6008 | |
| 6009 | // Check the number to string cache. |
| 6010 | Label not_cached; |
| 6011 | __ bind(¬_string); |
| 6012 | // Puts the cached result into scratch1. |
| 6013 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6014 | arg, |
| 6015 | scratch1, |
| 6016 | scratch2, |
| 6017 | scratch3, |
| 6018 | false, |
| 6019 | ¬_cached); |
| 6020 | __ mov(arg, scratch1); |
| 6021 | __ mov(Operand(esp, stack_offset), arg); |
| 6022 | __ jmp(&done); |
| 6023 | |
| 6024 | // Check if the argument is a safe string wrapper. |
| 6025 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6026 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6027 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6028 | __ j(not_equal, slow); |
| 6029 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6030 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6031 | __ j(zero, slow); |
| 6032 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6033 | __ mov(Operand(esp, stack_offset), arg); |
| 6034 | |
| 6035 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | |
| 6039 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6040 | Register dest, |
| 6041 | Register src, |
| 6042 | Register count, |
| 6043 | Register scratch, |
| 6044 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6045 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6046 | __ bind(&loop); |
| 6047 | // This loop just copies one character at a time, as it is only used for very |
| 6048 | // short strings. |
| 6049 | if (ascii) { |
| 6050 | __ mov_b(scratch, Operand(src, 0)); |
| 6051 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6052 | __ add(src, Immediate(1)); |
| 6053 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6054 | } else { |
| 6055 | __ mov_w(scratch, Operand(src, 0)); |
| 6056 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6057 | __ add(src, Immediate(2)); |
| 6058 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6059 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6060 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6061 | __ j(not_zero, &loop); |
| 6062 | } |
| 6063 | |
| 6064 | |
| 6065 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6066 | Register dest, |
| 6067 | Register src, |
| 6068 | Register count, |
| 6069 | Register scratch, |
| 6070 | bool ascii) { |
| 6071 | // Copy characters using rep movs of doublewords. |
| 6072 | // The destination is aligned on a 4 byte boundary because we are |
| 6073 | // copying to the beginning of a newly allocated string. |
| 6074 | ASSERT(dest.is(edi)); // rep movs destination |
| 6075 | ASSERT(src.is(esi)); // rep movs source |
| 6076 | ASSERT(count.is(ecx)); // rep movs count |
| 6077 | ASSERT(!scratch.is(dest)); |
| 6078 | ASSERT(!scratch.is(src)); |
| 6079 | ASSERT(!scratch.is(count)); |
| 6080 | |
| 6081 | // Nothing to do for zero characters. |
| 6082 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6083 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6084 | __ j(zero, &done); |
| 6085 | |
| 6086 | // Make count the number of bytes to copy. |
| 6087 | if (!ascii) { |
| 6088 | __ shl(count, 1); |
| 6089 | } |
| 6090 | |
| 6091 | // 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] | 6092 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6093 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6094 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6095 | |
| 6096 | // Copy from edi to esi using rep movs instruction. |
| 6097 | __ mov(scratch, count); |
| 6098 | __ sar(count, 2); // Number of doublewords to copy. |
| 6099 | __ cld(); |
| 6100 | __ rep_movs(); |
| 6101 | |
| 6102 | // Find number of bytes left. |
| 6103 | __ mov(count, scratch); |
| 6104 | __ and_(count, 3); |
| 6105 | |
| 6106 | // Check if there are more bytes to copy. |
| 6107 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6108 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6109 | __ j(zero, &done); |
| 6110 | |
| 6111 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6112 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6113 | __ bind(&loop); |
| 6114 | __ mov_b(scratch, Operand(src, 0)); |
| 6115 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6116 | __ add(src, Immediate(1)); |
| 6117 | __ add(dest, Immediate(1)); |
| 6118 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6119 | __ j(not_zero, &loop); |
| 6120 | |
| 6121 | __ bind(&done); |
| 6122 | } |
| 6123 | |
| 6124 | |
| 6125 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 6126 | Register c1, |
| 6127 | Register c2, |
| 6128 | Register scratch1, |
| 6129 | Register scratch2, |
| 6130 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6131 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6132 | Label* not_found) { |
| 6133 | // Register scratch3 is the general scratch register in this function. |
| 6134 | Register scratch = scratch3; |
| 6135 | |
| 6136 | // Make sure that both characters are not digits as such strings has a |
| 6137 | // 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] | 6138 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6139 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6140 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6141 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6142 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6143 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6144 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6145 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6146 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6147 | |
| 6148 | __ bind(¬_array_index); |
| 6149 | // Calculate the two character string hash. |
| 6150 | Register hash = scratch1; |
| 6151 | GenerateHashInit(masm, hash, c1, scratch); |
| 6152 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6153 | GenerateHashGetHash(masm, hash, scratch); |
| 6154 | |
| 6155 | // Collect the two characters in a register. |
| 6156 | Register chars = c1; |
| 6157 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6158 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6159 | |
| 6160 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6161 | // hash: hash of two character string. |
| 6162 | |
| 6163 | // Load the symbol table. |
| 6164 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6165 | ExternalReference roots_array_start = |
| 6166 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 6168 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6169 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6170 | |
| 6171 | // Calculate capacity mask from the symbol table capacity. |
| 6172 | Register mask = scratch2; |
| 6173 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 6174 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6175 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6176 | |
| 6177 | // Registers |
| 6178 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6179 | // hash: hash of two character string |
| 6180 | // symbol_table: symbol table |
| 6181 | // mask: capacity mask |
| 6182 | // scratch: - |
| 6183 | |
| 6184 | // Perform a number of probes in the symbol table. |
| 6185 | static const int kProbes = 4; |
| 6186 | Label found_in_symbol_table; |
| 6187 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6188 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6189 | for (int i = 0; i < kProbes; i++) { |
| 6190 | // Calculate entry in symbol table. |
| 6191 | __ mov(scratch, hash); |
| 6192 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6193 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6194 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6195 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6196 | |
| 6197 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6198 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6199 | __ mov(candidate, |
| 6200 | FieldOperand(symbol_table, |
| 6201 | scratch, |
| 6202 | times_pointer_size, |
| 6203 | SymbolTable::kElementsStartOffset)); |
| 6204 | |
| 6205 | // 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] | 6206 | Factory* factory = masm->isolate()->factory(); |
| 6207 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6208 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6209 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6210 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6211 | |
| 6212 | // If length is not 2 the string is not a candidate. |
| 6213 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6214 | Immediate(Smi::FromInt(2))); |
| 6215 | __ j(not_equal, &next_probe[i]); |
| 6216 | |
| 6217 | // As we are out of registers save the mask on the stack and use that |
| 6218 | // register as a temporary. |
| 6219 | __ push(mask); |
| 6220 | Register temp = mask; |
| 6221 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6222 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6223 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6224 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6225 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6226 | temp, temp, &next_probe_pop_mask[i]); |
| 6227 | |
| 6228 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6229 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6230 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6231 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6232 | __ j(equal, &found_in_symbol_table); |
| 6233 | __ bind(&next_probe_pop_mask[i]); |
| 6234 | __ pop(mask); |
| 6235 | __ bind(&next_probe[i]); |
| 6236 | } |
| 6237 | |
| 6238 | // No matching 2 character string found by probing. |
| 6239 | __ jmp(not_found); |
| 6240 | |
| 6241 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6242 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6243 | __ bind(&found_in_symbol_table); |
| 6244 | __ pop(mask); // Pop saved mask from the stack. |
| 6245 | if (!result.is(eax)) { |
| 6246 | __ mov(eax, result); |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | |
| 6251 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6252 | Register hash, |
| 6253 | Register character, |
| 6254 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6255 | // hash = (seed + character) + ((seed + character) << 10); |
| 6256 | if (Serializer::enabled()) { |
| 6257 | ExternalReference roots_array_start = |
| 6258 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6259 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6260 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6261 | times_pointer_size, |
| 6262 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6263 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6264 | __ add(scratch, character); |
| 6265 | __ mov(hash, scratch); |
| 6266 | __ shl(scratch, 10); |
| 6267 | __ add(hash, scratch); |
| 6268 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6269 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6270 | __ lea(scratch, Operand(character, seed)); |
| 6271 | __ shl(scratch, 10); |
| 6272 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6273 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | // hash ^= hash >> 6; |
| 6275 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6276 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6277 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | |
| 6281 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6282 | Register hash, |
| 6283 | Register character, |
| 6284 | Register scratch) { |
| 6285 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6286 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6287 | // hash += hash << 10; |
| 6288 | __ mov(scratch, hash); |
| 6289 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6290 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6291 | // hash ^= hash >> 6; |
| 6292 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6293 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6294 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6295 | } |
| 6296 | |
| 6297 | |
| 6298 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6299 | Register hash, |
| 6300 | Register scratch) { |
| 6301 | // hash += hash << 3; |
| 6302 | __ mov(scratch, hash); |
| 6303 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6304 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6305 | // hash ^= hash >> 11; |
| 6306 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6307 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6308 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6309 | // hash += hash << 15; |
| 6310 | __ mov(scratch, hash); |
| 6311 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6312 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6313 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6314 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6315 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6316 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6317 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6318 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6319 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6320 | __ bind(&hash_not_zero); |
| 6321 | } |
| 6322 | |
| 6323 | |
| 6324 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6325 | Label runtime; |
| 6326 | |
| 6327 | // Stack frame on entry. |
| 6328 | // esp[0]: return address |
| 6329 | // esp[4]: to |
| 6330 | // esp[8]: from |
| 6331 | // esp[12]: string |
| 6332 | |
| 6333 | // Make sure first argument is a string. |
| 6334 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6335 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6336 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6337 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6338 | __ j(NegateCondition(is_string), &runtime); |
| 6339 | |
| 6340 | // eax: string |
| 6341 | // ebx: instance type |
| 6342 | |
| 6343 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6344 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6345 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6346 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6347 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6348 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6349 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6350 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6351 | // Shorter than original string's length: an actual substring. |
| 6352 | __ j(below, ¬_original_string, Label::kNear); |
| 6353 | // Longer than original string's length or negative: unsafe arguments. |
| 6354 | __ j(above, &runtime); |
| 6355 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6356 | Counters* counters = masm->isolate()->counters(); |
| 6357 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6358 | __ ret(3 * kPointerSize); |
| 6359 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6360 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame^] | 6361 | Label single_char; |
| 6362 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6363 | __ j(equal, &single_char); |
| 6364 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6365 | // eax: string |
| 6366 | // ebx: instance type |
| 6367 | // ecx: sub string length (smi) |
| 6368 | // edx: from index (smi) |
| 6369 | // Deal with different string types: update the index if necessary |
| 6370 | // and put the underlying string into edi. |
| 6371 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6372 | // If the string is not indirect, it can only be sequential or external. |
| 6373 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6374 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6375 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6376 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6377 | |
| 6378 | Factory* factory = masm->isolate()->factory(); |
| 6379 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6380 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6381 | // Cons string. Check whether it is flat, then fetch first part. |
| 6382 | // Flat cons strings have an empty second part. |
| 6383 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6384 | factory->empty_string()); |
| 6385 | __ j(not_equal, &runtime); |
| 6386 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6387 | // Update instance type. |
| 6388 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6389 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6390 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6391 | |
| 6392 | __ bind(&sliced_string); |
| 6393 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6394 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6395 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6396 | // Update instance type. |
| 6397 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6398 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6399 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6400 | |
| 6401 | __ bind(&seq_or_external_string); |
| 6402 | // Sequential or external string. Just move string to the expected register. |
| 6403 | __ mov(edi, eax); |
| 6404 | |
| 6405 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6406 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6407 | if (FLAG_string_slices) { |
| 6408 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6409 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6410 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6411 | // edx: adjusted start index (smi) |
| 6412 | // ecx: length (smi) |
| 6413 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6414 | // Short slice. Copy instead of slicing. |
| 6415 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6416 | // Allocate new sliced string. At this point we do not reload the instance |
| 6417 | // type including the string encoding because we simply rely on the info |
| 6418 | // provided by the original string. It does not matter if the original |
| 6419 | // string's encoding is wrong because we always have to recheck encoding of |
| 6420 | // the newly created string's parent anyways due to externalized strings. |
| 6421 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6422 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6423 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6424 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6425 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6426 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6427 | __ jmp(&set_slice_header, Label::kNear); |
| 6428 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6429 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6430 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6431 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6432 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6433 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6434 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6435 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6436 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6437 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6438 | |
| 6439 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6440 | } |
| 6441 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6442 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6443 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6444 | // edx: adjusted start index (smi) |
| 6445 | // ecx: length (smi) |
| 6446 | // The subject string can only be external or sequential string of either |
| 6447 | // encoding at this point. |
| 6448 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6449 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6450 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6451 | __ test_b(ebx, kExternalStringTag); |
| 6452 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6453 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6454 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6455 | // Rule out short external strings. |
| 6456 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6457 | __ test_b(ebx, kShortExternalStringMask); |
| 6458 | __ j(not_zero, &runtime); |
| 6459 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6460 | // 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] | 6461 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6462 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6463 | |
| 6464 | __ bind(&sequential_string); |
| 6465 | // Stash away (adjusted) index and (underlying) string. |
| 6466 | __ push(edx); |
| 6467 | __ push(edi); |
| 6468 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6469 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6470 | __ test_b(ebx, kStringEncodingMask); |
| 6471 | __ j(zero, &two_byte_sequential); |
| 6472 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6473 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6474 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6475 | |
| 6476 | // eax: result string |
| 6477 | // ecx: result string length |
| 6478 | __ mov(edx, esi); // esi used by following code. |
| 6479 | // Locate first character of result. |
| 6480 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6481 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6482 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6483 | __ pop(esi); |
| 6484 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6485 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6486 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6487 | |
| 6488 | // eax: result string |
| 6489 | // ecx: result length |
| 6490 | // edx: original value of esi |
| 6491 | // edi: first character of result |
| 6492 | // esi: character of sub string start |
| 6493 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6494 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6495 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6496 | __ ret(3 * kPointerSize); |
| 6497 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6498 | __ bind(&two_byte_sequential); |
| 6499 | // Sequential two-byte string. Allocate the result. |
| 6500 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6501 | |
| 6502 | // eax: result string |
| 6503 | // ecx: result string length |
| 6504 | __ mov(edx, esi); // esi used by following code. |
| 6505 | // Locate first character of result. |
| 6506 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6507 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6508 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6509 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6510 | __ pop(esi); |
| 6511 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6512 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6513 | // byte character. |
| 6514 | STATIC_ASSERT(kSmiTag == 0); |
| 6515 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6516 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6517 | |
| 6518 | // eax: result string |
| 6519 | // ecx: result length |
| 6520 | // edx: original value of esi |
| 6521 | // edi: first character of result |
| 6522 | // esi: character of sub string start |
| 6523 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6524 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6525 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6526 | __ ret(3 * kPointerSize); |
| 6527 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6528 | // Drop pushed values on the stack before tail call. |
| 6529 | __ bind(&runtime_drop_two); |
| 6530 | __ Drop(2); |
| 6531 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6532 | // Just jump to runtime to create the sub string. |
| 6533 | __ bind(&runtime); |
| 6534 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame^] | 6535 | |
| 6536 | __ bind(&single_char); |
| 6537 | // eax: string |
| 6538 | // ebx: instance type |
| 6539 | // ecx: sub string length (smi) |
| 6540 | // edx: from index (smi) |
| 6541 | StringCharAtGenerator generator( |
| 6542 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6543 | generator.GenerateFast(masm); |
| 6544 | __ ret(3 * kPointerSize); |
| 6545 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6549 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6550 | Register left, |
| 6551 | Register right, |
| 6552 | Register scratch1, |
| 6553 | Register scratch2) { |
| 6554 | Register length = scratch1; |
| 6555 | |
| 6556 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6557 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6558 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6559 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6560 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6561 | __ bind(&strings_not_equal); |
| 6562 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6563 | __ ret(0); |
| 6564 | |
| 6565 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6566 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6567 | __ bind(&check_zero_length); |
| 6568 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6569 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6570 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6571 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6572 | __ ret(0); |
| 6573 | |
| 6574 | // Compare characters. |
| 6575 | __ bind(&compare_chars); |
| 6576 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6577 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6578 | |
| 6579 | // Characters are equal. |
| 6580 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6581 | __ ret(0); |
| 6582 | } |
| 6583 | |
| 6584 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6585 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6586 | Register left, |
| 6587 | Register right, |
| 6588 | Register scratch1, |
| 6589 | Register scratch2, |
| 6590 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6591 | Counters* counters = masm->isolate()->counters(); |
| 6592 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6593 | |
| 6594 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6595 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6596 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6597 | __ mov(scratch3, scratch1); |
| 6598 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6599 | |
| 6600 | Register length_delta = scratch3; |
| 6601 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6602 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6603 | // 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] | 6604 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6605 | __ bind(&left_shorter); |
| 6606 | |
| 6607 | Register min_length = scratch1; |
| 6608 | |
| 6609 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6610 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6611 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6612 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6613 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6614 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6615 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6616 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6617 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6618 | |
| 6619 | // Compare lengths - strings up to min-length are equal. |
| 6620 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6621 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6622 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6623 | __ j(not_zero, &result_not_equal, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6624 | #else |
| 6625 | Label length_not_equal; |
| 6626 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 6627 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6628 | |
| 6629 | // Result is EQUAL. |
| 6630 | STATIC_ASSERT(EQUAL == 0); |
| 6631 | STATIC_ASSERT(kSmiTag == 0); |
| 6632 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6633 | __ ret(0); |
| 6634 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6635 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6636 | #ifdef ENABLE_LATIN_1 |
| 6637 | Label result_less; |
| 6638 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6639 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6640 | __ jmp(&result_less, Label::kNear); |
| 6641 | #endif |
| 6642 | __ bind(&result_not_equal); |
| 6643 | #ifndef ENABLE_LATIN_1 |
| 6644 | __ j(greater, &result_greater, Label::kNear); |
| 6645 | #else |
| 6646 | __ j(above, &result_greater, Label::kNear); |
| 6647 | __ bind(&result_less); |
| 6648 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6649 | |
| 6650 | // Result is LESS. |
| 6651 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6652 | __ ret(0); |
| 6653 | |
| 6654 | // Result is GREATER. |
| 6655 | __ bind(&result_greater); |
| 6656 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6657 | __ ret(0); |
| 6658 | } |
| 6659 | |
| 6660 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6661 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6662 | MacroAssembler* masm, |
| 6663 | Register left, |
| 6664 | Register right, |
| 6665 | Register length, |
| 6666 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6667 | Label* chars_not_equal, |
| 6668 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6669 | // Change index to run from -length to -1 by adding length to string |
| 6670 | // start. This means that loop ends when index reaches zero, which |
| 6671 | // doesn't need an additional compare. |
| 6672 | __ SmiUntag(length); |
| 6673 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6674 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6675 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6676 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6677 | __ neg(length); |
| 6678 | Register index = length; // index = -length; |
| 6679 | |
| 6680 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6681 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6682 | __ bind(&loop); |
| 6683 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6684 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6685 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6686 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6687 | __ j(not_zero, &loop); |
| 6688 | } |
| 6689 | |
| 6690 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6691 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6692 | Label runtime; |
| 6693 | |
| 6694 | // Stack frame on entry. |
| 6695 | // esp[0]: return address |
| 6696 | // esp[4]: right string |
| 6697 | // esp[8]: left string |
| 6698 | |
| 6699 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6700 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6701 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6702 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6703 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6704 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6705 | STATIC_ASSERT(EQUAL == 0); |
| 6706 | STATIC_ASSERT(kSmiTag == 0); |
| 6707 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6708 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6709 | __ ret(2 * kPointerSize); |
| 6710 | |
| 6711 | __ bind(¬_same); |
| 6712 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6713 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6714 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6715 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6716 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6717 | // Drop arguments from the stack. |
| 6718 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6719 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6720 | __ push(ecx); |
| 6721 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6722 | |
| 6723 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6724 | // tagged as a small integer. |
| 6725 | __ bind(&runtime); |
| 6726 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6727 | } |
| 6728 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6729 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6730 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6731 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6732 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6733 | __ mov(ecx, edx); |
| 6734 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6735 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6736 | |
| 6737 | if (GetCondition() == equal) { |
| 6738 | // 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] | 6739 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6740 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6741 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6742 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6743 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6744 | // Correct sign of result in case of overflow. |
| 6745 | __ not_(edx); |
| 6746 | __ bind(&done); |
| 6747 | __ mov(eax, edx); |
| 6748 | } |
| 6749 | __ ret(0); |
| 6750 | |
| 6751 | __ bind(&miss); |
| 6752 | GenerateMiss(masm); |
| 6753 | } |
| 6754 | |
| 6755 | |
| 6756 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6757 | ASSERT(state_ == CompareIC::HEAP_NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6758 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6759 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6760 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6761 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6762 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6763 | if (left_ == CompareIC::SMI) { |
| 6764 | __ JumpIfNotSmi(edx, &miss); |
| 6765 | } |
| 6766 | if (right_ == CompareIC::SMI) { |
| 6767 | __ JumpIfNotSmi(eax, &miss); |
| 6768 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6769 | |
| 6770 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6771 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6772 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6773 | CpuFeatures::Scope scope1(SSE2); |
| 6774 | CpuFeatures::Scope scope2(CMOV); |
| 6775 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6776 | // Load left and right operand. |
| 6777 | Label done, left, left_smi, right_smi; |
| 6778 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6779 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6780 | masm->isolate()->factory()->heap_number_map()); |
| 6781 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6782 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6783 | __ jmp(&left, Label::kNear); |
| 6784 | __ bind(&right_smi); |
| 6785 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6786 | __ SmiUntag(ecx); |
| 6787 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6788 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6789 | __ bind(&left); |
| 6790 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6791 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6792 | masm->isolate()->factory()->heap_number_map()); |
| 6793 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6794 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6795 | __ jmp(&done); |
| 6796 | __ bind(&left_smi); |
| 6797 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6798 | __ SmiUntag(ecx); |
| 6799 | __ cvtsi2sd(xmm0, ecx); |
| 6800 | |
| 6801 | __ bind(&done); |
| 6802 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6803 | __ ucomisd(xmm0, xmm1); |
| 6804 | |
| 6805 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6806 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6807 | |
| 6808 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6809 | // Performing mov, because xor would destroy the flag register. |
| 6810 | __ mov(eax, 0); // equal |
| 6811 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6812 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6813 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6814 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6815 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6816 | } else { |
| 6817 | __ mov(ecx, edx); |
| 6818 | __ and_(ecx, eax); |
| 6819 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6820 | |
| 6821 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6822 | masm->isolate()->factory()->heap_number_map()); |
| 6823 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6824 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6825 | masm->isolate()->factory()->heap_number_map()); |
| 6826 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6827 | } |
| 6828 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6829 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6830 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6831 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6832 | CompareIC::GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6833 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6834 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6835 | __ bind(&maybe_undefined1); |
| 6836 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6837 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6838 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6839 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6840 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6841 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6842 | __ jmp(&unordered); |
| 6843 | } |
| 6844 | |
| 6845 | __ bind(&maybe_undefined2); |
| 6846 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6847 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6848 | __ j(equal, &unordered); |
| 6849 | } |
| 6850 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6851 | __ bind(&miss); |
| 6852 | GenerateMiss(masm); |
| 6853 | } |
| 6854 | |
| 6855 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6856 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6857 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6858 | ASSERT(GetCondition() == equal); |
| 6859 | |
| 6860 | // Registers containing left and right operands respectively. |
| 6861 | Register left = edx; |
| 6862 | Register right = eax; |
| 6863 | Register tmp1 = ecx; |
| 6864 | Register tmp2 = ebx; |
| 6865 | |
| 6866 | // Check that both operands are heap objects. |
| 6867 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6868 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6869 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6870 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6871 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6872 | |
| 6873 | // Check that both operands are symbols. |
| 6874 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6875 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6876 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6877 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6878 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6879 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6880 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6881 | __ j(zero, &miss, Label::kNear); |
| 6882 | |
| 6883 | // Symbols are compared by identity. |
| 6884 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6885 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6886 | // Make sure eax is non-zero. At this point input operands are |
| 6887 | // guaranteed to be non-zero. |
| 6888 | ASSERT(right.is(eax)); |
| 6889 | __ j(not_equal, &done, Label::kNear); |
| 6890 | STATIC_ASSERT(EQUAL == 0); |
| 6891 | STATIC_ASSERT(kSmiTag == 0); |
| 6892 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6893 | __ bind(&done); |
| 6894 | __ ret(0); |
| 6895 | |
| 6896 | __ bind(&miss); |
| 6897 | GenerateMiss(masm); |
| 6898 | } |
| 6899 | |
| 6900 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6901 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6902 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6903 | Label miss; |
| 6904 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6905 | bool equality = Token::IsEqualityOp(op_); |
| 6906 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6907 | // Registers containing left and right operands respectively. |
| 6908 | Register left = edx; |
| 6909 | Register right = eax; |
| 6910 | Register tmp1 = ecx; |
| 6911 | Register tmp2 = ebx; |
| 6912 | Register tmp3 = edi; |
| 6913 | |
| 6914 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6915 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6916 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6917 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6918 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6919 | |
| 6920 | // Check that both operands are strings. This leaves the instance |
| 6921 | // types loaded in tmp1 and tmp2. |
| 6922 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6923 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6924 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6925 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6926 | __ mov(tmp3, tmp1); |
| 6927 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6928 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6929 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6930 | __ j(not_zero, &miss); |
| 6931 | |
| 6932 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6933 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6934 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6935 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6936 | STATIC_ASSERT(EQUAL == 0); |
| 6937 | STATIC_ASSERT(kSmiTag == 0); |
| 6938 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6939 | __ ret(0); |
| 6940 | |
| 6941 | // Handle not identical strings. |
| 6942 | __ bind(¬_same); |
| 6943 | |
| 6944 | // 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] | 6945 | // because we already know they are not identical. But in the case of |
| 6946 | // non-equality compare, we still need to determine the order. |
| 6947 | if (equality) { |
| 6948 | Label do_compare; |
| 6949 | STATIC_ASSERT(kSymbolTag != 0); |
| 6950 | __ and_(tmp1, tmp2); |
| 6951 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6952 | __ j(zero, &do_compare, Label::kNear); |
| 6953 | // Make sure eax is non-zero. At this point input operands are |
| 6954 | // guaranteed to be non-zero. |
| 6955 | ASSERT(right.is(eax)); |
| 6956 | __ ret(0); |
| 6957 | __ bind(&do_compare); |
| 6958 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6959 | |
| 6960 | // Check that both strings are sequential ASCII. |
| 6961 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6962 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6963 | |
| 6964 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6965 | if (equality) { |
| 6966 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6967 | masm, left, right, tmp1, tmp2); |
| 6968 | } else { |
| 6969 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6970 | masm, left, right, tmp1, tmp2, tmp3); |
| 6971 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6972 | |
| 6973 | // Handle more complex cases in runtime. |
| 6974 | __ bind(&runtime); |
| 6975 | __ pop(tmp1); // Return address. |
| 6976 | __ push(left); |
| 6977 | __ push(right); |
| 6978 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6979 | if (equality) { |
| 6980 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6981 | } else { |
| 6982 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6983 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6984 | |
| 6985 | __ bind(&miss); |
| 6986 | GenerateMiss(masm); |
| 6987 | } |
| 6988 | |
| 6989 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6990 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6991 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6992 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6993 | __ mov(ecx, edx); |
| 6994 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6995 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6996 | |
| 6997 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6998 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6999 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7000 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7001 | |
| 7002 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7003 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7004 | __ ret(0); |
| 7005 | |
| 7006 | __ bind(&miss); |
| 7007 | GenerateMiss(masm); |
| 7008 | } |
| 7009 | |
| 7010 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7011 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7012 | Label miss; |
| 7013 | __ mov(ecx, edx); |
| 7014 | __ and_(ecx, eax); |
| 7015 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7016 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7017 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7018 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7019 | __ cmp(ecx, known_map_); |
| 7020 | __ j(not_equal, &miss, Label::kNear); |
| 7021 | __ cmp(ebx, known_map_); |
| 7022 | __ j(not_equal, &miss, Label::kNear); |
| 7023 | |
| 7024 | __ sub(eax, edx); |
| 7025 | __ ret(0); |
| 7026 | |
| 7027 | __ bind(&miss); |
| 7028 | GenerateMiss(masm); |
| 7029 | } |
| 7030 | |
| 7031 | |
| 7032 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7033 | { |
| 7034 | // Call the runtime system in a fresh internal frame. |
| 7035 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7036 | masm->isolate()); |
| 7037 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7038 | __ push(edx); // Preserve edx and eax. |
| 7039 | __ push(eax); |
| 7040 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7041 | __ push(eax); |
| 7042 | __ push(Immediate(Smi::FromInt(op_))); |
| 7043 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7044 | // Compute the entry point of the rewritten stub. |
| 7045 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7046 | __ pop(eax); |
| 7047 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7048 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7049 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7050 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7051 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7055 | // Helper function used to check that the dictionary doesn't contain |
| 7056 | // the property. This function may return false negatives, so miss_label |
| 7057 | // must always call a backup property check that is complete. |
| 7058 | // This function is safe to call if the receiver has fast properties. |
| 7059 | // 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] | 7060 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7061 | Label* miss, |
| 7062 | Label* done, |
| 7063 | Register properties, |
| 7064 | Handle<String> name, |
| 7065 | Register r0) { |
| 7066 | ASSERT(name->IsSymbol()); |
| 7067 | |
| 7068 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7069 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7070 | // undefined value), it guarantees the hash table doesn't contain the |
| 7071 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7072 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7073 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7074 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7075 | Register index = r0; |
| 7076 | // Capacity is smi 2^n. |
| 7077 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7078 | __ dec(index); |
| 7079 | __ and_(index, |
| 7080 | Immediate(Smi::FromInt(name->Hash() + |
| 7081 | StringDictionary::GetProbeOffset(i)))); |
| 7082 | |
| 7083 | // Scale the index by multiplying by the entry size. |
| 7084 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7085 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7086 | Register entity_name = r0; |
| 7087 | // Having undefined at this place means the name is not contained. |
| 7088 | ASSERT_EQ(kSmiTagSize, 1); |
| 7089 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7090 | kElementsStartOffset - kHeapObjectTag)); |
| 7091 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7092 | __ j(equal, done); |
| 7093 | |
| 7094 | // Stop if found the property. |
| 7095 | __ cmp(entity_name, Handle<String>(name)); |
| 7096 | __ j(equal, miss); |
| 7097 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7098 | Label the_hole; |
| 7099 | // Check for the hole and skip. |
| 7100 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 7101 | __ j(equal, &the_hole, Label::kNear); |
| 7102 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7103 | // Check if the entry name is not a symbol. |
| 7104 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7105 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7106 | kIsSymbolMask); |
| 7107 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7108 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | StringDictionaryLookupStub stub(properties, |
| 7112 | r0, |
| 7113 | r0, |
| 7114 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 7115 | __ push(Immediate(Handle<Object>(name))); |
| 7116 | __ push(Immediate(name->Hash())); |
| 7117 | __ CallStub(&stub); |
| 7118 | __ test(r0, r0); |
| 7119 | __ j(not_zero, miss); |
| 7120 | __ jmp(done); |
| 7121 | } |
| 7122 | |
| 7123 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7124 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7125 | // |done| label if a property with the given name is found leaving the |
| 7126 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7127 | // otherwise. |
| 7128 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7129 | Label* miss, |
| 7130 | Label* done, |
| 7131 | Register elements, |
| 7132 | Register name, |
| 7133 | Register r0, |
| 7134 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7135 | ASSERT(!elements.is(r0)); |
| 7136 | ASSERT(!elements.is(r1)); |
| 7137 | ASSERT(!name.is(r0)); |
| 7138 | ASSERT(!name.is(r1)); |
| 7139 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7140 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7141 | |
| 7142 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7143 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7144 | __ dec(r1); |
| 7145 | |
| 7146 | // Generate an unrolled loop that performs a few probes before |
| 7147 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7148 | // cover ~93% of loads from dictionaries. |
| 7149 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7150 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7151 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7152 | __ shr(r0, String::kHashShift); |
| 7153 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7154 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7155 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7156 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7157 | |
| 7158 | // Scale the index by multiplying by the entry size. |
| 7159 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7160 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7161 | |
| 7162 | // Check if the key is identical to the name. |
| 7163 | __ cmp(name, Operand(elements, |
| 7164 | r0, |
| 7165 | times_4, |
| 7166 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7167 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | StringDictionaryLookupStub stub(elements, |
| 7171 | r1, |
| 7172 | r0, |
| 7173 | POSITIVE_LOOKUP); |
| 7174 | __ push(name); |
| 7175 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7176 | __ shr(r0, String::kHashShift); |
| 7177 | __ push(r0); |
| 7178 | __ CallStub(&stub); |
| 7179 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7180 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7181 | __ j(zero, miss); |
| 7182 | __ jmp(done); |
| 7183 | } |
| 7184 | |
| 7185 | |
| 7186 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7187 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7188 | // 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] | 7189 | // Stack frame on entry: |
| 7190 | // esp[0 * kPointerSize]: return address. |
| 7191 | // esp[1 * kPointerSize]: key's hash. |
| 7192 | // esp[2 * kPointerSize]: key. |
| 7193 | // Registers: |
| 7194 | // dictionary_: StringDictionary to probe. |
| 7195 | // result_: used as scratch. |
| 7196 | // index_: will hold an index of entry if lookup is successful. |
| 7197 | // might alias with result_. |
| 7198 | // Returns: |
| 7199 | // result_ is zero if lookup failed, non zero otherwise. |
| 7200 | |
| 7201 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7202 | |
| 7203 | Register scratch = result_; |
| 7204 | |
| 7205 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7206 | __ dec(scratch); |
| 7207 | __ SmiUntag(scratch); |
| 7208 | __ push(scratch); |
| 7209 | |
| 7210 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7211 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7212 | // undefined value), it guarantees the hash table doesn't contain the |
| 7213 | // property. It's true even if some slots represent deleted properties |
| 7214 | // (their names are the null value). |
| 7215 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7216 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7217 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7218 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7219 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7220 | } |
| 7221 | __ and_(scratch, Operand(esp, 0)); |
| 7222 | |
| 7223 | // Scale the index by multiplying by the entry size. |
| 7224 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7225 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7226 | |
| 7227 | // Having undefined at this place means the name is not contained. |
| 7228 | ASSERT_EQ(kSmiTagSize, 1); |
| 7229 | __ mov(scratch, Operand(dictionary_, |
| 7230 | index_, |
| 7231 | times_pointer_size, |
| 7232 | kElementsStartOffset - kHeapObjectTag)); |
| 7233 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7234 | __ j(equal, ¬_in_dictionary); |
| 7235 | |
| 7236 | // Stop if found the property. |
| 7237 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7238 | __ j(equal, &in_dictionary); |
| 7239 | |
| 7240 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7241 | // If we hit a non symbol key during negative lookup |
| 7242 | // we have to bailout as this key might be equal to the |
| 7243 | // key we are looking for. |
| 7244 | |
| 7245 | // Check if the entry name is not a symbol. |
| 7246 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7247 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7248 | kIsSymbolMask); |
| 7249 | __ j(zero, &maybe_in_dictionary); |
| 7250 | } |
| 7251 | } |
| 7252 | |
| 7253 | __ bind(&maybe_in_dictionary); |
| 7254 | // If we are doing negative lookup then probing failure should be |
| 7255 | // treated as a lookup success. For positive lookup probing failure |
| 7256 | // should be treated as lookup failure. |
| 7257 | if (mode_ == POSITIVE_LOOKUP) { |
| 7258 | __ mov(result_, Immediate(0)); |
| 7259 | __ Drop(1); |
| 7260 | __ ret(2 * kPointerSize); |
| 7261 | } |
| 7262 | |
| 7263 | __ bind(&in_dictionary); |
| 7264 | __ mov(result_, Immediate(1)); |
| 7265 | __ Drop(1); |
| 7266 | __ ret(2 * kPointerSize); |
| 7267 | |
| 7268 | __ bind(¬_in_dictionary); |
| 7269 | __ mov(result_, Immediate(0)); |
| 7270 | __ Drop(1); |
| 7271 | __ ret(2 * kPointerSize); |
| 7272 | } |
| 7273 | |
| 7274 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7275 | struct AheadOfTimeWriteBarrierStubList { |
| 7276 | Register object, value, address; |
| 7277 | RememberedSetAction action; |
| 7278 | }; |
| 7279 | |
| 7280 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7281 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7282 | |
| 7283 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7284 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7285 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7286 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7287 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7288 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7289 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7290 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7291 | // Used in StoreStubCompiler::CompileStoreField and |
| 7292 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7293 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7294 | // GenerateStoreField calls the stub with two different permutations of |
| 7295 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7296 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7297 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7298 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7299 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7300 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7301 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7302 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7303 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7304 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7305 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7306 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7307 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7308 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7309 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7310 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7311 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7312 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7313 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7314 | // FastNewClosureStub |
| 7315 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7316 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7317 | { 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] | 7318 | }; |
| 7319 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7320 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7321 | |
| 7322 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7323 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7324 | !entry->object.is(no_reg); |
| 7325 | entry++) { |
| 7326 | if (object_.is(entry->object) && |
| 7327 | value_.is(entry->value) && |
| 7328 | address_.is(entry->address) && |
| 7329 | remembered_set_action_ == entry->action && |
| 7330 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7331 | return true; |
| 7332 | } |
| 7333 | } |
| 7334 | return false; |
| 7335 | } |
| 7336 | |
| 7337 | |
| 7338 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7339 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7340 | stub1.GetCode()->set_is_pregenerated(true); |
| 7341 | |
| 7342 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7343 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7344 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7345 | stub2.GetCode()->set_is_pregenerated(true); |
| 7346 | } |
| 7347 | } |
| 7348 | |
| 7349 | |
| 7350 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7351 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7352 | !entry->object.is(no_reg); |
| 7353 | entry++) { |
| 7354 | RecordWriteStub stub(entry->object, |
| 7355 | entry->value, |
| 7356 | entry->address, |
| 7357 | entry->action, |
| 7358 | kDontSaveFPRegs); |
| 7359 | stub.GetCode()->set_is_pregenerated(true); |
| 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7364 | bool CodeStub::CanUseFPRegisters() { |
| 7365 | return CpuFeatures::IsSupported(SSE2); |
| 7366 | } |
| 7367 | |
| 7368 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7369 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7370 | // the value has just been written into the object, now this stub makes sure |
| 7371 | // we keep the GC informed. The word in the object where the value has been |
| 7372 | // written is in the address register. |
| 7373 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7374 | Label skip_to_incremental_noncompacting; |
| 7375 | Label skip_to_incremental_compacting; |
| 7376 | |
| 7377 | // The first two instructions are generated with labels so as to get the |
| 7378 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7379 | // forth between a compare instructions (a nop in this position) and the |
| 7380 | // real branch when we start and stop incremental heap marking. |
| 7381 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7382 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7383 | |
| 7384 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7385 | __ RememberedSetHelper(object_, |
| 7386 | address_, |
| 7387 | value_, |
| 7388 | save_fp_regs_mode_, |
| 7389 | MacroAssembler::kReturnAtEnd); |
| 7390 | } else { |
| 7391 | __ ret(0); |
| 7392 | } |
| 7393 | |
| 7394 | __ bind(&skip_to_incremental_noncompacting); |
| 7395 | GenerateIncremental(masm, INCREMENTAL); |
| 7396 | |
| 7397 | __ bind(&skip_to_incremental_compacting); |
| 7398 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7399 | |
| 7400 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7401 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7402 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7403 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7404 | } |
| 7405 | |
| 7406 | |
| 7407 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7408 | regs_.Save(masm); |
| 7409 | |
| 7410 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7411 | Label dont_need_remembered_set; |
| 7412 | |
| 7413 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7414 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7415 | regs_.scratch0(), |
| 7416 | &dont_need_remembered_set); |
| 7417 | |
| 7418 | __ CheckPageFlag(regs_.object(), |
| 7419 | regs_.scratch0(), |
| 7420 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7421 | not_zero, |
| 7422 | &dont_need_remembered_set); |
| 7423 | |
| 7424 | // First notify the incremental marker if necessary, then update the |
| 7425 | // remembered set. |
| 7426 | CheckNeedsToInformIncrementalMarker( |
| 7427 | masm, |
| 7428 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7429 | mode); |
| 7430 | InformIncrementalMarker(masm, mode); |
| 7431 | regs_.Restore(masm); |
| 7432 | __ RememberedSetHelper(object_, |
| 7433 | address_, |
| 7434 | value_, |
| 7435 | save_fp_regs_mode_, |
| 7436 | MacroAssembler::kReturnAtEnd); |
| 7437 | |
| 7438 | __ bind(&dont_need_remembered_set); |
| 7439 | } |
| 7440 | |
| 7441 | CheckNeedsToInformIncrementalMarker( |
| 7442 | masm, |
| 7443 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7444 | mode); |
| 7445 | InformIncrementalMarker(masm, mode); |
| 7446 | regs_.Restore(masm); |
| 7447 | __ ret(0); |
| 7448 | } |
| 7449 | |
| 7450 | |
| 7451 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7452 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7453 | int argument_count = 3; |
| 7454 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7455 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7456 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7457 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7458 | Immediate(ExternalReference::isolate_address())); |
| 7459 | |
| 7460 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7461 | if (mode == INCREMENTAL_COMPACTION) { |
| 7462 | __ CallCFunction( |
| 7463 | ExternalReference::incremental_evacuation_record_write_function( |
| 7464 | masm->isolate()), |
| 7465 | argument_count); |
| 7466 | } else { |
| 7467 | ASSERT(mode == INCREMENTAL); |
| 7468 | __ CallCFunction( |
| 7469 | ExternalReference::incremental_marking_record_write_function( |
| 7470 | masm->isolate()), |
| 7471 | argument_count); |
| 7472 | } |
| 7473 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7474 | } |
| 7475 | |
| 7476 | |
| 7477 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7478 | MacroAssembler* masm, |
| 7479 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7480 | Mode mode) { |
| 7481 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7482 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7483 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7484 | __ and_(regs_.scratch0(), regs_.object()); |
| 7485 | __ mov(regs_.scratch1(), |
| 7486 | Operand(regs_.scratch0(), |
| 7487 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7488 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7489 | __ mov(Operand(regs_.scratch0(), |
| 7490 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7491 | regs_.scratch1()); |
| 7492 | __ j(negative, &need_incremental); |
| 7493 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7494 | // Let's look at the color of the object: If it is not black we don't have |
| 7495 | // to inform the incremental marker. |
| 7496 | __ JumpIfBlack(regs_.object(), |
| 7497 | regs_.scratch0(), |
| 7498 | regs_.scratch1(), |
| 7499 | &object_is_black, |
| 7500 | Label::kNear); |
| 7501 | |
| 7502 | regs_.Restore(masm); |
| 7503 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7504 | __ RememberedSetHelper(object_, |
| 7505 | address_, |
| 7506 | value_, |
| 7507 | save_fp_regs_mode_, |
| 7508 | MacroAssembler::kReturnAtEnd); |
| 7509 | } else { |
| 7510 | __ ret(0); |
| 7511 | } |
| 7512 | |
| 7513 | __ bind(&object_is_black); |
| 7514 | |
| 7515 | // Get the value from the slot. |
| 7516 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7517 | |
| 7518 | if (mode == INCREMENTAL_COMPACTION) { |
| 7519 | Label ensure_not_white; |
| 7520 | |
| 7521 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7522 | regs_.scratch1(), // Scratch. |
| 7523 | MemoryChunk::kEvacuationCandidateMask, |
| 7524 | zero, |
| 7525 | &ensure_not_white, |
| 7526 | Label::kNear); |
| 7527 | |
| 7528 | __ CheckPageFlag(regs_.object(), |
| 7529 | regs_.scratch1(), // Scratch. |
| 7530 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7531 | not_zero, |
| 7532 | &ensure_not_white, |
| 7533 | Label::kNear); |
| 7534 | |
| 7535 | __ jmp(&need_incremental); |
| 7536 | |
| 7537 | __ bind(&ensure_not_white); |
| 7538 | } |
| 7539 | |
| 7540 | // We need an extra register for this, so we push the object register |
| 7541 | // temporarily. |
| 7542 | __ push(regs_.object()); |
| 7543 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7544 | regs_.scratch1(), // Scratch. |
| 7545 | regs_.object(), // Scratch. |
| 7546 | &need_incremental_pop_object, |
| 7547 | Label::kNear); |
| 7548 | __ pop(regs_.object()); |
| 7549 | |
| 7550 | regs_.Restore(masm); |
| 7551 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7552 | __ RememberedSetHelper(object_, |
| 7553 | address_, |
| 7554 | value_, |
| 7555 | save_fp_regs_mode_, |
| 7556 | MacroAssembler::kReturnAtEnd); |
| 7557 | } else { |
| 7558 | __ ret(0); |
| 7559 | } |
| 7560 | |
| 7561 | __ bind(&need_incremental_pop_object); |
| 7562 | __ pop(regs_.object()); |
| 7563 | |
| 7564 | __ bind(&need_incremental); |
| 7565 | |
| 7566 | // Fall through when we need to inform the incremental marker. |
| 7567 | } |
| 7568 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7569 | |
| 7570 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7571 | // ----------- S t a t e ------------- |
| 7572 | // -- eax : element value to store |
| 7573 | // -- ebx : array literal |
| 7574 | // -- edi : map of array literal |
| 7575 | // -- ecx : element index as smi |
| 7576 | // -- edx : array literal index in function |
| 7577 | // -- esp[0] : return address |
| 7578 | // ----------------------------------- |
| 7579 | |
| 7580 | Label element_done; |
| 7581 | Label double_elements; |
| 7582 | Label smi_element; |
| 7583 | Label slow_elements; |
| 7584 | Label slow_elements_from_double; |
| 7585 | Label fast_elements; |
| 7586 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7587 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7588 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7589 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7590 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7591 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7592 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7593 | // Store into the array literal requires a elements transition. Call into |
| 7594 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7595 | |
| 7596 | __ bind(&slow_elements); |
| 7597 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7598 | // call. |
| 7599 | __ push(ebx); |
| 7600 | __ push(ecx); |
| 7601 | __ push(eax); |
| 7602 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7603 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7604 | __ push(edx); |
| 7605 | __ push(edi); // Return return address so that tail call returns to right |
| 7606 | // place. |
| 7607 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7608 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7609 | __ bind(&slow_elements_from_double); |
| 7610 | __ pop(edx); |
| 7611 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7612 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7613 | // 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] | 7614 | __ bind(&fast_elements); |
| 7615 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7616 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7617 | FixedArrayBase::kHeaderSize)); |
| 7618 | __ mov(Operand(ecx, 0), eax); |
| 7619 | // Update the write barrier for the array store. |
| 7620 | __ RecordWrite(ebx, ecx, eax, |
| 7621 | kDontSaveFPRegs, |
| 7622 | EMIT_REMEMBERED_SET, |
| 7623 | OMIT_SMI_CHECK); |
| 7624 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7625 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7626 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7627 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7628 | __ bind(&smi_element); |
| 7629 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7630 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7631 | FixedArrayBase::kHeaderSize), eax); |
| 7632 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7633 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7634 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7635 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7636 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7637 | __ push(edx); |
| 7638 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7639 | __ StoreNumberToDoubleElements(eax, |
| 7640 | edx, |
| 7641 | ecx, |
| 7642 | edi, |
| 7643 | xmm0, |
| 7644 | &slow_elements_from_double, |
| 7645 | false); |
| 7646 | __ pop(edx); |
| 7647 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7648 | } |
| 7649 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7650 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7651 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7652 | ASSERT(!Serializer::enabled()); |
| 7653 | bool save_fp_regs = CpuFeatures::IsSupported(SSE2); |
| 7654 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
| 7655 | __ call(ces.GetCode(), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7656 | int parameter_count_offset = |
| 7657 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7658 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7659 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7660 | __ pop(ecx); |
| 7661 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, |
| 7662 | extra_expression_stack_count_ * kPointerSize)); |
| 7663 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7667 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7668 | if (entry_hook_ != NULL) { |
| 7669 | ProfileEntryHookStub stub; |
| 7670 | masm->CallStub(&stub); |
| 7671 | } |
| 7672 | } |
| 7673 | |
| 7674 | |
| 7675 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7676 | // Ecx is the only volatile register we must save. |
| 7677 | __ push(ecx); |
| 7678 | |
| 7679 | // Calculate and push the original stack pointer. |
| 7680 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7681 | __ push(eax); |
| 7682 | |
| 7683 | // Calculate and push the function address. |
| 7684 | __ mov(eax, Operand(eax, 0)); |
| 7685 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7686 | __ push(eax); |
| 7687 | |
| 7688 | // Call the entry hook. |
| 7689 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7690 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7691 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7692 | |
| 7693 | // Restore ecx. |
| 7694 | __ pop(ecx); |
| 7695 | __ ret(0); |
| 7696 | } |
| 7697 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7698 | #undef __ |
| 7699 | |
| 7700 | } } // namespace v8::internal |
| 7701 | |
| 7702 | #endif // V8_TARGET_ARCH_IA32 |