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; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame^] | 51 | descriptor->stack_parameter_count_ = NULL; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 52 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 53 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 57 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { eax, ebx }; |
| 61 | descriptor->register_param_count_ = 2; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = |
| 64 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 65 | } |
| 66 | |
| 67 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 68 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 69 | |
| 70 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 71 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 72 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 73 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 74 | __ ret(0); |
| 75 | |
| 76 | __ bind(&check_heap_number); |
| 77 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 78 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 79 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 80 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 81 | __ ret(0); |
| 82 | |
| 83 | __ bind(&call_builtin); |
| 84 | __ pop(ecx); // Pop return address. |
| 85 | __ push(eax); |
| 86 | __ push(ecx); // Push return address. |
| 87 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 88 | } |
| 89 | |
| 90 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 91 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 92 | // Create a new closure from the given function info in new |
| 93 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 94 | Counters* counters = masm->isolate()->counters(); |
| 95 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 96 | Label gc; |
| 97 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 98 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 99 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 100 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 101 | // Get the function info from the stack. |
| 102 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 103 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 104 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 105 | ? Context::FUNCTION_MAP_INDEX |
| 106 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 107 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 108 | // 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] | 109 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 110 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 111 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 112 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 113 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 114 | |
| 115 | // Initialize the rest of the function. We don't have to update the |
| 116 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 117 | Factory* factory = masm->isolate()->factory(); |
| 118 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 119 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 120 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 121 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 122 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 123 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 124 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 125 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 126 | |
| 127 | // Initialize the code pointer in the function to be the one |
| 128 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 129 | // But first check if there is an optimized version for our context. |
| 130 | Label check_optimized; |
| 131 | Label install_unoptimized; |
| 132 | if (FLAG_cache_optimized_code) { |
| 133 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 134 | __ test(ebx, ebx); |
| 135 | __ j(not_zero, &check_optimized, Label::kNear); |
| 136 | } |
| 137 | __ bind(&install_unoptimized); |
| 138 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 139 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 140 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 141 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 142 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 143 | |
| 144 | // Return and remove the on-stack parameter. |
| 145 | __ ret(1 * kPointerSize); |
| 146 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 147 | __ bind(&check_optimized); |
| 148 | |
| 149 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 150 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 151 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 152 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 153 | // Map must never be empty, so check the first elements. |
| 154 | Label install_optimized; |
| 155 | // Speculatively move code object into edx. |
| 156 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 157 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 158 | __ j(equal, &install_optimized); |
| 159 | |
| 160 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 161 | Label loop; |
| 162 | Label restore; |
| 163 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 164 | __ bind(&loop); |
| 165 | // Do not double check first entry. |
| 166 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 167 | __ j(equal, &restore); |
| 168 | __ sub(edx, Immediate(Smi::FromInt( |
| 169 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 170 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 171 | __ j(not_equal, &loop, Label::kNear); |
| 172 | // Hit: fetch the optimized code. |
| 173 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 174 | |
| 175 | __ bind(&install_optimized); |
| 176 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 177 | |
| 178 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 179 | // map and either unmangle them on marking or do nothing as the whole map is |
| 180 | // discarded on major GC anyway. |
| 181 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 182 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 183 | |
| 184 | // Now link a function into a list of optimized functions. |
| 185 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 186 | |
| 187 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 188 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 189 | |
| 190 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 191 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 192 | // it clobbers all the registers passed. |
| 193 | __ mov(edx, eax); |
| 194 | __ RecordWriteContextSlot( |
| 195 | ecx, |
| 196 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 197 | edx, |
| 198 | ebx, |
| 199 | kDontSaveFPRegs); |
| 200 | |
| 201 | // Return and remove the on-stack parameter. |
| 202 | __ ret(1 * kPointerSize); |
| 203 | |
| 204 | __ bind(&restore); |
| 205 | // Restore SharedFunctionInfo into edx. |
| 206 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 207 | __ jmp(&install_unoptimized); |
| 208 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 209 | // Create a new closure through the slower runtime call. |
| 210 | __ bind(&gc); |
| 211 | __ pop(ecx); // Temporarily remove return address. |
| 212 | __ pop(edx); |
| 213 | __ push(esi); |
| 214 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 215 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 216 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 217 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 222 | // Try to allocate the context in new space. |
| 223 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 224 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 225 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 226 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 227 | |
| 228 | // Get the function from the stack. |
| 229 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 230 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 231 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 232 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 233 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 234 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 235 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 236 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 237 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 238 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 239 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 240 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 241 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 242 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 243 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 244 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 245 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 246 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 247 | |
| 248 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 249 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 250 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 251 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 252 | } |
| 253 | |
| 254 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 255 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 256 | __ ret(1 * kPointerSize); |
| 257 | |
| 258 | // Need to collect. Call into runtime system. |
| 259 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 260 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 264 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 265 | // Stack layout on entry: |
| 266 | // |
| 267 | // [esp + (1 * kPointerSize)]: function |
| 268 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 269 | |
| 270 | // Try to allocate the context in new space. |
| 271 | Label gc; |
| 272 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 273 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 274 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 275 | |
| 276 | // Get the function or sentinel from the stack. |
| 277 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 278 | |
| 279 | // Get the serialized scope info from the stack. |
| 280 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 281 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 282 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 283 | Factory* factory = masm->isolate()->factory(); |
| 284 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 285 | factory->block_context_map()); |
| 286 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 287 | Immediate(Smi::FromInt(length))); |
| 288 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 289 | // 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] | 290 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 291 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 292 | // we still have to look up. |
| 293 | Label after_sentinel; |
| 294 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 295 | if (FLAG_debug_code) { |
| 296 | const char* message = "Expected 0 as a Smi sentinel"; |
| 297 | __ cmp(ecx, 0); |
| 298 | __ Assert(equal, message); |
| 299 | } |
| 300 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 301 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 302 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 303 | __ bind(&after_sentinel); |
| 304 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 305 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 306 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 307 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 308 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 309 | |
| 310 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 311 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 312 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 313 | |
| 314 | // Initialize the rest of the slots to the hole value. |
| 315 | if (slots_ == 1) { |
| 316 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 317 | factory->the_hole_value()); |
| 318 | } else { |
| 319 | __ mov(ebx, factory->the_hole_value()); |
| 320 | for (int i = 0; i < slots_; i++) { |
| 321 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // Return and remove the on-stack parameters. |
| 326 | __ mov(esi, eax); |
| 327 | __ ret(2 * kPointerSize); |
| 328 | |
| 329 | // Need to collect. Call into runtime system. |
| 330 | __ bind(&gc); |
| 331 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 332 | } |
| 333 | |
| 334 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 335 | static void GenerateFastCloneShallowArrayCommon( |
| 336 | MacroAssembler* masm, |
| 337 | int length, |
| 338 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 339 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 340 | Label* fail) { |
| 341 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 342 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 343 | // ecx: boilerplate literal array. |
| 344 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 345 | |
| 346 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 347 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 348 | if (length > 0) { |
| 349 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 350 | ? FixedDoubleArray::SizeFor(length) |
| 351 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 352 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 353 | int size = JSArray::kSize; |
| 354 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 355 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 356 | size += AllocationSiteInfo::kSize; |
| 357 | } |
| 358 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 359 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 360 | // Allocate both the JS array and the elements array in one big |
| 361 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 362 | AllocationFlags flags = TAG_OBJECT; |
| 363 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 364 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 365 | } |
| 366 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 367 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 368 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 369 | __ mov(FieldOperand(eax, allocation_info_start), |
| 370 | Immediate(Handle<Map>(masm->isolate()->heap()-> |
| 371 | allocation_site_info_map()))); |
| 372 | __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); |
| 373 | } |
| 374 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 375 | // Copy the JS array part. |
| 376 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 377 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 378 | __ mov(ebx, FieldOperand(ecx, i)); |
| 379 | __ mov(FieldOperand(eax, i), ebx); |
| 380 | } |
| 381 | } |
| 382 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 383 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 384 | // Get hold of the elements array of the boilerplate and setup the |
| 385 | // elements pointer in the resulting object. |
| 386 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 387 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 388 | __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 389 | } else { |
| 390 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 391 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 392 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 393 | |
| 394 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 395 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 396 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 397 | __ mov(ebx, FieldOperand(ecx, i)); |
| 398 | __ mov(FieldOperand(edx, i), ebx); |
| 399 | } |
| 400 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 401 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 402 | int i; |
| 403 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 404 | __ mov(ebx, FieldOperand(ecx, i)); |
| 405 | __ mov(FieldOperand(edx, i), ebx); |
| 406 | } |
| 407 | while (i < elements_size) { |
| 408 | __ fld_d(FieldOperand(ecx, i)); |
| 409 | __ fstp_d(FieldOperand(edx, i)); |
| 410 | i += kDoubleSize; |
| 411 | } |
| 412 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 415 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 416 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 417 | |
| 418 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 419 | // Stack layout on entry: |
| 420 | // |
| 421 | // [esp + kPointerSize]: constant elements. |
| 422 | // [esp + (2 * kPointerSize)]: literal index. |
| 423 | // [esp + (3 * kPointerSize)]: literals array. |
| 424 | |
| 425 | // Load boilerplate object into ecx and check if we need to create a |
| 426 | // boilerplate. |
| 427 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 428 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 429 | STATIC_ASSERT(kPointerSize == 4); |
| 430 | STATIC_ASSERT(kSmiTagSize == 1); |
| 431 | STATIC_ASSERT(kSmiTag == 0); |
| 432 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 433 | FixedArray::kHeaderSize)); |
| 434 | Factory* factory = masm->isolate()->factory(); |
| 435 | __ cmp(ecx, factory->undefined_value()); |
| 436 | Label slow_case; |
| 437 | __ j(equal, &slow_case); |
| 438 | |
| 439 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 440 | // ecx is boilerplate object. |
| 441 | if (mode == CLONE_ANY_ELEMENTS) { |
| 442 | Label double_elements, check_fast_elements; |
| 443 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 444 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 445 | &check_fast_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 446 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 447 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 448 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 449 | __ ret(3 * kPointerSize); |
| 450 | |
| 451 | __ bind(&check_fast_elements); |
| 452 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 453 | &double_elements, DONT_DO_SMI_CHECK); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 454 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 455 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 456 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 457 | __ ret(3 * kPointerSize); |
| 458 | |
| 459 | __ bind(&double_elements); |
| 460 | mode = CLONE_DOUBLE_ELEMENTS; |
| 461 | // Fall through to generate the code to handle double elements. |
| 462 | } |
| 463 | |
| 464 | if (FLAG_debug_code) { |
| 465 | const char* message; |
| 466 | Handle<Map> expected_map; |
| 467 | if (mode == CLONE_ELEMENTS) { |
| 468 | message = "Expected (writable) fixed array"; |
| 469 | expected_map = factory->fixed_array_map(); |
| 470 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 471 | message = "Expected (writable) fixed double array"; |
| 472 | expected_map = factory->fixed_double_array_map(); |
| 473 | } else { |
| 474 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 475 | message = "Expected copy-on-write fixed array"; |
| 476 | expected_map = factory->fixed_cow_array_map(); |
| 477 | } |
| 478 | __ push(ecx); |
| 479 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 480 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 481 | __ Assert(equal, message); |
| 482 | __ pop(ecx); |
| 483 | } |
| 484 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 485 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 486 | allocation_site_mode_, |
| 487 | &slow_case); |
| 488 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 489 | // Return and remove the on-stack parameters. |
| 490 | __ ret(3 * kPointerSize); |
| 491 | |
| 492 | __ bind(&slow_case); |
| 493 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 494 | } |
| 495 | |
| 496 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 497 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 498 | // Stack layout on entry: |
| 499 | // |
| 500 | // [esp + kPointerSize]: object literal flags. |
| 501 | // [esp + (2 * kPointerSize)]: constant properties. |
| 502 | // [esp + (3 * kPointerSize)]: literal index. |
| 503 | // [esp + (4 * kPointerSize)]: literals array. |
| 504 | |
| 505 | // Load boilerplate object into ecx and check if we need to create a |
| 506 | // boilerplate. |
| 507 | Label slow_case; |
| 508 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 509 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 510 | STATIC_ASSERT(kPointerSize == 4); |
| 511 | STATIC_ASSERT(kSmiTagSize == 1); |
| 512 | STATIC_ASSERT(kSmiTag == 0); |
| 513 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 514 | FixedArray::kHeaderSize)); |
| 515 | Factory* factory = masm->isolate()->factory(); |
| 516 | __ cmp(ecx, factory->undefined_value()); |
| 517 | __ j(equal, &slow_case); |
| 518 | |
| 519 | // Check that the boilerplate contains only fast properties and we can |
| 520 | // statically determine the instance size. |
| 521 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 522 | __ mov(eax, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 523 | __ movzx_b(eax, FieldOperand(eax, Map::kInstanceSizeOffset)); |
| 524 | __ cmp(eax, Immediate(size >> kPointerSizeLog2)); |
| 525 | __ j(not_equal, &slow_case); |
| 526 | |
| 527 | // Allocate the JS object and copy header together with all in-object |
| 528 | // properties from the boilerplate. |
| 529 | __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); |
| 530 | for (int i = 0; i < size; i += kPointerSize) { |
| 531 | __ mov(ebx, FieldOperand(ecx, i)); |
| 532 | __ mov(FieldOperand(eax, i), ebx); |
| 533 | } |
| 534 | |
| 535 | // Return and remove the on-stack parameters. |
| 536 | __ ret(4 * kPointerSize); |
| 537 | |
| 538 | __ bind(&slow_case); |
| 539 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 540 | } |
| 541 | |
| 542 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 543 | // The stub expects its argument on the stack and returns its result in tos_: |
| 544 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 545 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 546 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 547 | // 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] | 548 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 549 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 550 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 551 | const Register map = edx; |
| 552 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 553 | if (!types_.IsEmpty()) { |
| 554 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 555 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 556 | |
| 557 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 558 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 559 | |
| 560 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 561 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 562 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 563 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 564 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 565 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 566 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 567 | if (types_.Contains(SMI)) { |
| 568 | // Smis: 0 -> false, all other -> true |
| 569 | Label not_smi; |
| 570 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 571 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 572 | if (!tos_.is(argument)) { |
| 573 | __ mov(tos_, argument); |
| 574 | } |
| 575 | __ ret(1 * kPointerSize); |
| 576 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 577 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 578 | // If we need a map later and have a Smi -> patch. |
| 579 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 580 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 581 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 582 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 583 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 584 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 585 | if (types_.CanBeUndetectable()) { |
| 586 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 587 | 1 << Map::kIsUndetectable); |
| 588 | // Undetectable -> false. |
| 589 | Label not_undetectable; |
| 590 | __ j(zero, ¬_undetectable, Label::kNear); |
| 591 | __ Set(tos_, Immediate(0)); |
| 592 | __ ret(1 * kPointerSize); |
| 593 | __ bind(¬_undetectable); |
| 594 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 595 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 596 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 597 | if (types_.Contains(SPEC_OBJECT)) { |
| 598 | // spec object -> true. |
| 599 | Label not_js_object; |
| 600 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 601 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 602 | // argument contains the correct return value already. |
| 603 | if (!tos_.is(argument)) { |
| 604 | __ Set(tos_, Immediate(1)); |
| 605 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 606 | __ ret(1 * kPointerSize); |
| 607 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 608 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 609 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 610 | if (types_.Contains(STRING)) { |
| 611 | // String value -> false iff empty. |
| 612 | Label not_string; |
| 613 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 614 | __ j(above_equal, ¬_string, Label::kNear); |
| 615 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 616 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 617 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | if (types_.Contains(HEAP_NUMBER)) { |
| 621 | // heap number -> false iff +0, -0, or NaN. |
| 622 | Label not_heap_number, false_result; |
| 623 | __ cmp(map, factory->heap_number_map()); |
| 624 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 625 | __ fldz(); |
| 626 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 627 | __ FCmp(); |
| 628 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 629 | // argument contains the correct return value already. |
| 630 | if (!tos_.is(argument)) { |
| 631 | __ Set(tos_, Immediate(1)); |
| 632 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 633 | __ ret(1 * kPointerSize); |
| 634 | __ bind(&false_result); |
| 635 | __ Set(tos_, Immediate(0)); |
| 636 | __ ret(1 * kPointerSize); |
| 637 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 638 | } |
| 639 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 640 | __ bind(&patch); |
| 641 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 645 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 646 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 647 | // store the registers in any particular way, but we do have to store and |
| 648 | // restore them. |
| 649 | __ pushad(); |
| 650 | if (save_doubles_ == kSaveFPRegs) { |
| 651 | CpuFeatures::Scope scope(SSE2); |
| 652 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 653 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 654 | XMMRegister reg = XMMRegister::from_code(i); |
| 655 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 656 | } |
| 657 | } |
| 658 | const int argument_count = 1; |
| 659 | |
| 660 | AllowExternalCallThatCantCauseGC scope(masm); |
| 661 | __ PrepareCallCFunction(argument_count, ecx); |
| 662 | __ mov(Operand(esp, 0 * kPointerSize), |
| 663 | Immediate(ExternalReference::isolate_address())); |
| 664 | __ CallCFunction( |
| 665 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 666 | argument_count); |
| 667 | if (save_doubles_ == kSaveFPRegs) { |
| 668 | CpuFeatures::Scope scope(SSE2); |
| 669 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 670 | XMMRegister reg = XMMRegister::from_code(i); |
| 671 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 672 | } |
| 673 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 674 | } |
| 675 | __ popad(); |
| 676 | __ ret(0); |
| 677 | } |
| 678 | |
| 679 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 680 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 681 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 682 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 683 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 684 | const Register argument = eax; |
| 685 | if (types_.Contains(type)) { |
| 686 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 687 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 688 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 689 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 690 | if (!result) { |
| 691 | // If we have to return zero, there is no way around clearing tos_. |
| 692 | __ Set(tos_, Immediate(0)); |
| 693 | } else if (!tos_.is(argument)) { |
| 694 | // If we have to return non-zero, we can re-use the argument if it is the |
| 695 | // same register as the result, because we never see Smi-zero here. |
| 696 | __ Set(tos_, Immediate(1)); |
| 697 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 698 | __ ret(1 * kPointerSize); |
| 699 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 705 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 706 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 707 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 708 | __ push(ecx); // Push return address. |
| 709 | // Patch the caller to an appropriate specialized stub and return the |
| 710 | // operation result to the caller of the stub. |
| 711 | __ TailCallExternalReference( |
| 712 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 713 | 3, |
| 714 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 718 | class FloatingPointHelper : public AllStatic { |
| 719 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 720 | enum ArgLocation { |
| 721 | ARGS_ON_STACK, |
| 722 | ARGS_IN_REGISTERS |
| 723 | }; |
| 724 | |
| 725 | // Code pattern for loading a floating point value. Input value must |
| 726 | // be either a smi or a heap number object (fp value). Requirements: |
| 727 | // operand in register number. Returns operand as floating point number |
| 728 | // on FPU stack. |
| 729 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 730 | |
| 731 | // Code pattern for loading floating point values. Input values must |
| 732 | // be either smi or heap number objects (fp values). Requirements: |
| 733 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 734 | // Returns operands as floating point numbers on FPU stack. |
| 735 | static void LoadFloatOperands(MacroAssembler* masm, |
| 736 | Register scratch, |
| 737 | ArgLocation arg_location = ARGS_ON_STACK); |
| 738 | |
| 739 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 740 | // Expects operands in edx, eax. |
| 741 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 742 | |
| 743 | // Test if operands are smi or number objects (fp). Requirements: |
| 744 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 745 | // operands, jumps to the non_float label otherwise. |
| 746 | static void CheckFloatOperands(MacroAssembler* masm, |
| 747 | Label* non_float, |
| 748 | Register scratch); |
| 749 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 750 | // Checks that the two floating point numbers on top of the FPU stack |
| 751 | // have int32 values. |
| 752 | static void CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 753 | Label* non_int32); |
| 754 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 755 | // Takes the operands in edx and eax and loads them as integers in eax |
| 756 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 757 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 758 | bool use_sse3, |
| 759 | Label* operand_conversion_failure); |
| 760 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 761 | // Must only be called after LoadUnknownsAsIntegers. Assumes that the |
| 762 | // operands are pushed on the stack, and that their conversions to int32 |
| 763 | // are in eax and ecx. Checks that the original numbers were in the int32 |
| 764 | // range. |
| 765 | static void CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 766 | bool use_sse3, |
| 767 | Label* not_int32); |
| 768 | |
| 769 | // Assumes that operands are smis or heap numbers and loads them |
| 770 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 771 | // Leaves operands unchanged. |
| 772 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 773 | |
| 774 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 775 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 776 | // either operand is not a number. Operands are in edx and eax. |
| 777 | // Leaves operands unchanged. |
| 778 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 779 | |
| 780 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 781 | // Expects operands in edx, eax. |
| 782 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 783 | |
| 784 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 785 | // have int32 values. |
| 786 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 787 | Label* non_int32, |
| 788 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 789 | |
| 790 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 791 | Label* non_int32, |
| 792 | XMMRegister operand, |
| 793 | Register scratch, |
| 794 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 795 | }; |
| 796 | |
| 797 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 798 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 799 | // is faster than using the built-in instructions on floating point registers. |
| 800 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 801 | // trashed registers. |
| 802 | static void IntegerConvert(MacroAssembler* masm, |
| 803 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 804 | bool use_sse3, |
| 805 | Label* conversion_failure) { |
| 806 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 807 | Label done, right_exponent, normal_exponent; |
| 808 | Register scratch = ebx; |
| 809 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 810 | // Get exponent word. |
| 811 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 812 | // Get exponent alone in scratch2. |
| 813 | __ mov(scratch2, scratch); |
| 814 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 815 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 816 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 817 | // Load ecx with zero. We use this either for the final shift or |
| 818 | // for the answer. |
| 819 | __ xor_(ecx, ecx); |
| 820 | // If the exponent is above 83, the number contains no significant |
| 821 | // bits in the range 0..2^31, so the result is zero. |
| 822 | static const uint32_t kResultIsZeroExponent = 83; |
| 823 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 824 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 825 | if (use_sse3) { |
| 826 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 827 | // 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] | 828 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 829 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 830 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 831 | // Load x87 register with heap number. |
| 832 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 833 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 834 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 835 | // Do conversion, which cannot fail because we checked the exponent. |
| 836 | __ fisttp_d(Operand(esp, 0)); |
| 837 | __ 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] | 838 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 839 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 841 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 842 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 843 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 844 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 845 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 846 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 847 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 848 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 849 | // If the exponent is higher than that then go to slow case. This catches |
| 850 | // 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] | 851 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 852 | |
| 853 | { |
| 854 | // Handle a big exponent. The only reason we have this code is that the |
| 855 | // >>> 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] | 856 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 857 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 858 | __ j(not_equal, conversion_failure); |
| 859 | // We have the big exponent, typically from >>>. This means the number is |
| 860 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 861 | __ mov(scratch2, scratch); |
| 862 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 863 | // Put back the implicit 1. |
| 864 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 865 | // Shift up the mantissa bits to take up the space the exponent used to |
| 866 | // take. We just orred in the implicit bit so that took care of one and |
| 867 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 868 | // shift distance. |
| 869 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 870 | __ shl(scratch2, big_shift_distance); |
| 871 | // Get the second half of the double. |
| 872 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 873 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 874 | // mantissa word. |
| 875 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 876 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 877 | // 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] | 878 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 879 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 880 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 881 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 885 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 886 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 887 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 888 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 889 | |
| 890 | __ bind(&right_exponent); |
| 891 | // Here ecx is the shift, scratch is the exponent word. |
| 892 | // Get the top bits of the mantissa. |
| 893 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 894 | // Put back the implicit 1. |
| 895 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 896 | // Shift up the mantissa bits to take up the space the exponent used to |
| 897 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 898 | // word. Shift them to the top bits. |
| 899 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 900 | __ shl(scratch, shift_distance); |
| 901 | // Get the second half of the double. For some exponents we don't |
| 902 | // actually need this because the bits get shifted out again, but |
| 903 | // it's probably slower to test than just to do it. |
| 904 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 905 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 906 | // mantissa word. |
| 907 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 908 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 909 | // Move down according to the exponent. |
| 910 | __ shr_cl(scratch2); |
| 911 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 912 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 913 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 914 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 915 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 916 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 917 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 918 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 919 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 920 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 921 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 922 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 926 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 927 | const char* op_name = Token::Name(op_); |
| 928 | const char* overwrite_name = NULL; // Make g++ happy. |
| 929 | switch (mode_) { |
| 930 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 931 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 932 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 933 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 934 | op_name, |
| 935 | overwrite_name, |
| 936 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
| 940 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 941 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 942 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 943 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 944 | GenerateTypeTransition(masm); |
| 945 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 946 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 947 | GenerateSmiStub(masm); |
| 948 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 949 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 950 | GenerateHeapNumberStub(masm); |
| 951 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 952 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 953 | GenerateGenericStub(masm); |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 959 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 960 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 961 | |
| 962 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 963 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 964 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 965 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 966 | |
| 967 | __ push(ecx); // Push return address. |
| 968 | |
| 969 | // Patch the caller to an appropriate specialized stub and return the |
| 970 | // operation result to the caller of the stub. |
| 971 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 972 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | |
| 976 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 977 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 978 | switch (op_) { |
| 979 | case Token::SUB: |
| 980 | GenerateSmiStubSub(masm); |
| 981 | break; |
| 982 | case Token::BIT_NOT: |
| 983 | GenerateSmiStubBitNot(masm); |
| 984 | break; |
| 985 | default: |
| 986 | UNREACHABLE(); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 991 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 992 | Label non_smi, undo, slow; |
| 993 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 994 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 995 | __ bind(&undo); |
| 996 | GenerateSmiCodeUndo(masm); |
| 997 | __ bind(&non_smi); |
| 998 | __ bind(&slow); |
| 999 | GenerateTypeTransition(masm); |
| 1000 | } |
| 1001 | |
| 1002 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1003 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1004 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1005 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1006 | __ bind(&non_smi); |
| 1007 | GenerateTypeTransition(masm); |
| 1008 | } |
| 1009 | |
| 1010 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1011 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 1012 | Label* non_smi, |
| 1013 | Label* undo, |
| 1014 | Label* slow, |
| 1015 | Label::Distance non_smi_near, |
| 1016 | Label::Distance undo_near, |
| 1017 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1018 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1019 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1020 | |
| 1021 | // 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] | 1022 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1023 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1024 | |
| 1025 | // 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] | 1026 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1027 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1028 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1029 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1030 | __ ret(0); |
| 1031 | } |
| 1032 | |
| 1033 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1034 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1035 | MacroAssembler* masm, |
| 1036 | Label* non_smi, |
| 1037 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1038 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1039 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1040 | |
| 1041 | // Flip bits and revert inverted smi-tag. |
| 1042 | __ not_(eax); |
| 1043 | __ and_(eax, ~kSmiTagMask); |
| 1044 | __ ret(0); |
| 1045 | } |
| 1046 | |
| 1047 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1048 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1049 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1054 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1055 | switch (op_) { |
| 1056 | case Token::SUB: |
| 1057 | GenerateHeapNumberStubSub(masm); |
| 1058 | break; |
| 1059 | case Token::BIT_NOT: |
| 1060 | GenerateHeapNumberStubBitNot(masm); |
| 1061 | break; |
| 1062 | default: |
| 1063 | UNREACHABLE(); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1068 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1069 | Label non_smi, undo, slow, call_builtin; |
| 1070 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1071 | __ bind(&non_smi); |
| 1072 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1073 | __ bind(&undo); |
| 1074 | GenerateSmiCodeUndo(masm); |
| 1075 | __ bind(&slow); |
| 1076 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1077 | __ bind(&call_builtin); |
| 1078 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1082 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1083 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1084 | Label non_smi, slow; |
| 1085 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1086 | __ bind(&non_smi); |
| 1087 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1088 | __ bind(&slow); |
| 1089 | GenerateTypeTransition(masm); |
| 1090 | } |
| 1091 | |
| 1092 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1093 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1094 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1095 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1096 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1097 | __ j(not_equal, slow); |
| 1098 | |
| 1099 | if (mode_ == UNARY_OVERWRITE) { |
| 1100 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1101 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1102 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1103 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1104 | // edx: operand |
| 1105 | |
| 1106 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1107 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1108 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1109 | |
| 1110 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1111 | { |
| 1112 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1113 | __ push(edx); |
| 1114 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1115 | __ pop(edx); |
| 1116 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1117 | |
| 1118 | __ bind(&heapnumber_allocated); |
| 1119 | // eax: allocated 'empty' number |
| 1120 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1121 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1122 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1123 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1124 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1125 | } |
| 1126 | __ ret(0); |
| 1127 | } |
| 1128 | |
| 1129 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1130 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1131 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1132 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1133 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1134 | __ j(not_equal, slow); |
| 1135 | |
| 1136 | // 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] | 1137 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1138 | |
| 1139 | // 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] | 1140 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1141 | __ not_(ecx); |
| 1142 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1143 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1144 | |
| 1145 | // Tag the result as a smi and we're done. |
| 1146 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1147 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1148 | __ ret(0); |
| 1149 | |
| 1150 | // Try to store the result in a heap number. |
| 1151 | __ bind(&try_float); |
| 1152 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1153 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1154 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1155 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1156 | __ jmp(&heapnumber_allocated); |
| 1157 | |
| 1158 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1159 | { |
| 1160 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1161 | // Push the original HeapNumber on the stack. The integer value can't |
| 1162 | // be stored since it's untagged and not in the smi range (so we can't |
| 1163 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1164 | __ push(ebx); |
| 1165 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1166 | // New HeapNumber is in eax. |
| 1167 | __ pop(edx); |
| 1168 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1169 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1170 | // This conversion won't go slow-case. |
| 1171 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1172 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1173 | |
| 1174 | __ bind(&heapnumber_allocated); |
| 1175 | } |
| 1176 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1177 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1178 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1179 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1180 | } else { |
| 1181 | __ push(ecx); |
| 1182 | __ fild_s(Operand(esp, 0)); |
| 1183 | __ pop(ecx); |
| 1184 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1185 | } |
| 1186 | __ ret(0); |
| 1187 | } |
| 1188 | |
| 1189 | |
| 1190 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1191 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1192 | switch (op_) { |
| 1193 | case Token::SUB: |
| 1194 | GenerateGenericStubSub(masm); |
| 1195 | break; |
| 1196 | case Token::BIT_NOT: |
| 1197 | GenerateGenericStubBitNot(masm); |
| 1198 | break; |
| 1199 | default: |
| 1200 | UNREACHABLE(); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1205 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1206 | Label non_smi, undo, slow; |
| 1207 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1208 | __ bind(&non_smi); |
| 1209 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1210 | __ bind(&undo); |
| 1211 | GenerateSmiCodeUndo(masm); |
| 1212 | __ bind(&slow); |
| 1213 | GenerateGenericCodeFallback(masm); |
| 1214 | } |
| 1215 | |
| 1216 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1217 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1218 | Label non_smi, slow; |
| 1219 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1220 | __ bind(&non_smi); |
| 1221 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1222 | __ bind(&slow); |
| 1223 | GenerateGenericCodeFallback(masm); |
| 1224 | } |
| 1225 | |
| 1226 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1227 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1228 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1229 | __ pop(ecx); // pop return address. |
| 1230 | __ push(eax); |
| 1231 | __ push(ecx); // push return address |
| 1232 | switch (op_) { |
| 1233 | case Token::SUB: |
| 1234 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1235 | break; |
| 1236 | case Token::BIT_NOT: |
| 1237 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1238 | break; |
| 1239 | default: |
| 1240 | UNREACHABLE(); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1245 | void BinaryOpStub::Initialize() { |
| 1246 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1247 | } |
| 1248 | |
| 1249 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1250 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1251 | __ pop(ecx); // Save return address. |
| 1252 | __ push(edx); |
| 1253 | __ push(eax); |
| 1254 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1255 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1256 | |
| 1257 | __ push(ecx); // Push return address. |
| 1258 | |
| 1259 | // Patch the caller to an appropriate specialized stub and return the |
| 1260 | // operation result to the caller of the stub. |
| 1261 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1262 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1263 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1264 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1265 | 1); |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | // Prepare for a type transition runtime call when the args are already on |
| 1270 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1271 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1272 | __ pop(ecx); // Save return address. |
| 1273 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1274 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1275 | |
| 1276 | __ push(ecx); // Push return address. |
| 1277 | |
| 1278 | // Patch the caller to an appropriate specialized stub and return the |
| 1279 | // operation result to the caller of the stub. |
| 1280 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1281 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1282 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1283 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1284 | 1); |
| 1285 | } |
| 1286 | |
| 1287 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1288 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1289 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1290 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1291 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1292 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1294 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1295 | Comment load_comment(masm, "-- Load arguments"); |
| 1296 | Register left = edx; |
| 1297 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1298 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | left = eax; |
| 1300 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1301 | __ mov(ebx, eax); |
| 1302 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | // 2. Prepare the smi check of both operands by oring them together. |
| 1307 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1308 | Label not_smis; |
| 1309 | Register combined = ecx; |
| 1310 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1311 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1312 | case Token::BIT_OR: |
| 1313 | // Perform the operation into eax and smi check the result. Preserve |
| 1314 | // eax in case the result is not a smi. |
| 1315 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1316 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1317 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1318 | combined = right; |
| 1319 | break; |
| 1320 | |
| 1321 | case Token::BIT_XOR: |
| 1322 | case Token::BIT_AND: |
| 1323 | case Token::ADD: |
| 1324 | case Token::SUB: |
| 1325 | case Token::MUL: |
| 1326 | case Token::DIV: |
| 1327 | case Token::MOD: |
| 1328 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1329 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | |
| 1332 | case Token::SHL: |
| 1333 | case Token::SAR: |
| 1334 | case Token::SHR: |
| 1335 | // Move the right operand into ecx for the shift operation, use eax |
| 1336 | // for the smi check register. |
| 1337 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1338 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1339 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1340 | combined = right; |
| 1341 | break; |
| 1342 | |
| 1343 | default: |
| 1344 | break; |
| 1345 | } |
| 1346 | |
| 1347 | // 3. Perform the smi check of the operands. |
| 1348 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1349 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1350 | |
| 1351 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1352 | // eax and check the result if necessary. |
| 1353 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1354 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1355 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1356 | case Token::BIT_OR: |
| 1357 | // Nothing to do. |
| 1358 | break; |
| 1359 | |
| 1360 | case Token::BIT_XOR: |
| 1361 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1362 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | case Token::BIT_AND: |
| 1366 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1367 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1368 | break; |
| 1369 | |
| 1370 | case Token::SHL: |
| 1371 | // Remove tags from operands (but keep sign). |
| 1372 | __ SmiUntag(left); |
| 1373 | __ SmiUntag(ecx); |
| 1374 | // Perform the operation. |
| 1375 | __ shl_cl(left); |
| 1376 | // Check that the *signed* result fits in a smi. |
| 1377 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1378 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1379 | // Tag the result and store it in register eax. |
| 1380 | __ SmiTag(left); |
| 1381 | __ mov(eax, left); |
| 1382 | break; |
| 1383 | |
| 1384 | case Token::SAR: |
| 1385 | // Remove tags from operands (but keep sign). |
| 1386 | __ SmiUntag(left); |
| 1387 | __ SmiUntag(ecx); |
| 1388 | // Perform the operation. |
| 1389 | __ sar_cl(left); |
| 1390 | // Tag the result and store it in register eax. |
| 1391 | __ SmiTag(left); |
| 1392 | __ mov(eax, left); |
| 1393 | break; |
| 1394 | |
| 1395 | case Token::SHR: |
| 1396 | // Remove tags from operands (but keep sign). |
| 1397 | __ SmiUntag(left); |
| 1398 | __ SmiUntag(ecx); |
| 1399 | // Perform the operation. |
| 1400 | __ shr_cl(left); |
| 1401 | // Check that the *unsigned* result fits in a smi. |
| 1402 | // Neither of the two high-order bits can be set: |
| 1403 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1404 | // - 0x40000000: this number would convert to negative when |
| 1405 | // Smi tagging these two cases can only happen with shifts |
| 1406 | // by 0 or 1 when handed a valid smi. |
| 1407 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1408 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1409 | // Tag the result and store it in register eax. |
| 1410 | __ SmiTag(left); |
| 1411 | __ mov(eax, left); |
| 1412 | break; |
| 1413 | |
| 1414 | case Token::ADD: |
| 1415 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1416 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1417 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | |
| 1420 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1421 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1422 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1423 | __ mov(eax, left); |
| 1424 | break; |
| 1425 | |
| 1426 | case Token::MUL: |
| 1427 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1428 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1429 | // We can't revert the multiplication if the result is not a smi |
| 1430 | // so save the right operand. |
| 1431 | __ mov(ebx, right); |
| 1432 | // Remove tag from one of the operands (but keep sign). |
| 1433 | __ SmiUntag(right); |
| 1434 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1435 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1436 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1437 | // Check for negative zero result. Use combined = left | right. |
| 1438 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1439 | break; |
| 1440 | |
| 1441 | case Token::DIV: |
| 1442 | // We can't revert the division if the result is not a smi so |
| 1443 | // save the left operand. |
| 1444 | __ mov(edi, left); |
| 1445 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1446 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1447 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1448 | // Sign extend left into edx:eax. |
| 1449 | ASSERT(left.is(eax)); |
| 1450 | __ cdq(); |
| 1451 | // Divide edx:eax by right. |
| 1452 | __ idiv(right); |
| 1453 | // Check for the corner case of dividing the most negative smi by |
| 1454 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1455 | // instruction. |
| 1456 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1457 | __ cmp(eax, 0x40000000); |
| 1458 | __ j(equal, &use_fp_on_smis); |
| 1459 | // Check for negative zero result. Use combined = left | right. |
| 1460 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1461 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1462 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1463 | __ j(not_zero, &use_fp_on_smis); |
| 1464 | // Tag the result and store it in register eax. |
| 1465 | __ SmiTag(eax); |
| 1466 | break; |
| 1467 | |
| 1468 | case Token::MOD: |
| 1469 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1470 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1471 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1472 | |
| 1473 | // Sign extend left into edx:eax. |
| 1474 | ASSERT(left.is(eax)); |
| 1475 | __ cdq(); |
| 1476 | // Divide edx:eax by right. |
| 1477 | __ idiv(right); |
| 1478 | // Check for negative zero result. Use combined = left | right. |
| 1479 | __ NegativeZeroTest(edx, combined, slow); |
| 1480 | // Move remainder to register eax. |
| 1481 | __ mov(eax, edx); |
| 1482 | break; |
| 1483 | |
| 1484 | default: |
| 1485 | UNREACHABLE(); |
| 1486 | } |
| 1487 | |
| 1488 | // 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] | 1489 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1490 | case Token::ADD: |
| 1491 | case Token::SUB: |
| 1492 | case Token::MUL: |
| 1493 | case Token::DIV: |
| 1494 | __ ret(0); |
| 1495 | break; |
| 1496 | case Token::MOD: |
| 1497 | case Token::BIT_OR: |
| 1498 | case Token::BIT_AND: |
| 1499 | case Token::BIT_XOR: |
| 1500 | case Token::SAR: |
| 1501 | case Token::SHL: |
| 1502 | case Token::SHR: |
| 1503 | __ ret(2 * kPointerSize); |
| 1504 | break; |
| 1505 | default: |
| 1506 | UNREACHABLE(); |
| 1507 | } |
| 1508 | |
| 1509 | // 6. For some operations emit inline code to perform floating point |
| 1510 | // operations on known smis (e.g., if the result of the operation |
| 1511 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1512 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1513 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1514 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1515 | // Undo the effects of some operations, and some register moves. |
| 1516 | case Token::SHL: |
| 1517 | // The arguments are saved on the stack, and only used from there. |
| 1518 | break; |
| 1519 | case Token::ADD: |
| 1520 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1521 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1522 | break; |
| 1523 | case Token::SUB: |
| 1524 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1525 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | case Token::MUL: |
| 1528 | // Right was clobbered but a copy is in ebx. |
| 1529 | __ mov(right, ebx); |
| 1530 | break; |
| 1531 | case Token::DIV: |
| 1532 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1533 | // division. They should be in eax, ebx for jump to not_smi. |
| 1534 | __ mov(eax, edi); |
| 1535 | break; |
| 1536 | default: |
| 1537 | // No other operators jump to use_fp_on_smis. |
| 1538 | break; |
| 1539 | } |
| 1540 | __ jmp(¬_smis); |
| 1541 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1542 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1543 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1544 | case Token::SHL: |
| 1545 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1546 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1547 | __ bind(&use_fp_on_smis); |
| 1548 | // Result we want is in left == edx, so we can put the allocated heap |
| 1549 | // number in eax. |
| 1550 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1551 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1552 | // It's OK to overwrite the arguments on the stack because we |
| 1553 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1554 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1556 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1557 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1558 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1559 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1560 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1561 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1562 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1563 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1564 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1565 | } else { |
| 1566 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1567 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1568 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1569 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1570 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1571 | __ ret(2 * kPointerSize); |
| 1572 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | case Token::ADD: |
| 1576 | case Token::SUB: |
| 1577 | case Token::MUL: |
| 1578 | case Token::DIV: { |
| 1579 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1580 | __ bind(&use_fp_on_smis); |
| 1581 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1582 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1583 | case Token::ADD: |
| 1584 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1585 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1586 | break; |
| 1587 | case Token::SUB: |
| 1588 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1589 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1590 | break; |
| 1591 | case Token::MUL: |
| 1592 | // Right was clobbered but a copy is in ebx. |
| 1593 | __ mov(right, ebx); |
| 1594 | break; |
| 1595 | case Token::DIV: |
| 1596 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1597 | // division. |
| 1598 | __ mov(edx, edi); |
| 1599 | __ mov(eax, right); |
| 1600 | break; |
| 1601 | default: UNREACHABLE(); |
| 1602 | break; |
| 1603 | } |
| 1604 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1605 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1606 | CpuFeatures::Scope use_sse2(SSE2); |
| 1607 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1608 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1609 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1610 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1611 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1612 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1613 | default: UNREACHABLE(); |
| 1614 | } |
| 1615 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1616 | } else { // SSE2 not available, use FPU. |
| 1617 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1618 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1619 | case Token::ADD: __ faddp(1); break; |
| 1620 | case Token::SUB: __ fsubp(1); break; |
| 1621 | case Token::MUL: __ fmulp(1); break; |
| 1622 | case Token::DIV: __ fdivp(1); break; |
| 1623 | default: UNREACHABLE(); |
| 1624 | } |
| 1625 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1626 | } |
| 1627 | __ mov(eax, ecx); |
| 1628 | __ ret(0); |
| 1629 | break; |
| 1630 | } |
| 1631 | |
| 1632 | default: |
| 1633 | break; |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1638 | // edx and eax. |
| 1639 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1640 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1641 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1642 | case Token::BIT_OR: |
| 1643 | case Token::SHL: |
| 1644 | case Token::SAR: |
| 1645 | case Token::SHR: |
| 1646 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1647 | // check. |
| 1648 | __ mov(eax, ecx); |
| 1649 | break; |
| 1650 | |
| 1651 | case Token::DIV: |
| 1652 | case Token::MOD: |
| 1653 | // Operands are in eax, ebx at this point. |
| 1654 | __ mov(edx, eax); |
| 1655 | __ mov(eax, ebx); |
| 1656 | break; |
| 1657 | |
| 1658 | default: |
| 1659 | break; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1664 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1665 | Label call_runtime; |
| 1666 | |
| 1667 | switch (op_) { |
| 1668 | case Token::ADD: |
| 1669 | case Token::SUB: |
| 1670 | case Token::MUL: |
| 1671 | case Token::DIV: |
| 1672 | break; |
| 1673 | case Token::MOD: |
| 1674 | case Token::BIT_OR: |
| 1675 | case Token::BIT_AND: |
| 1676 | case Token::BIT_XOR: |
| 1677 | case Token::SAR: |
| 1678 | case Token::SHL: |
| 1679 | case Token::SHR: |
| 1680 | GenerateRegisterArgsPush(masm); |
| 1681 | break; |
| 1682 | default: |
| 1683 | UNREACHABLE(); |
| 1684 | } |
| 1685 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1686 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1687 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1688 | BinaryOpStub_GenerateSmiCode( |
| 1689 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1690 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1691 | BinaryOpStub_GenerateSmiCode( |
| 1692 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1693 | } |
| 1694 | __ bind(&call_runtime); |
| 1695 | switch (op_) { |
| 1696 | case Token::ADD: |
| 1697 | case Token::SUB: |
| 1698 | case Token::MUL: |
| 1699 | case Token::DIV: |
| 1700 | GenerateTypeTransition(masm); |
| 1701 | break; |
| 1702 | case Token::MOD: |
| 1703 | case Token::BIT_OR: |
| 1704 | case Token::BIT_AND: |
| 1705 | case Token::BIT_XOR: |
| 1706 | case Token::SAR: |
| 1707 | case Token::SHL: |
| 1708 | case Token::SHR: |
| 1709 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1710 | break; |
| 1711 | default: |
| 1712 | UNREACHABLE(); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1717 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1718 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1719 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1720 | ASSERT(op_ == Token::ADD); |
| 1721 | // If both arguments are strings, call the string add stub. |
| 1722 | // Otherwise, do a transition. |
| 1723 | |
| 1724 | // Registers containing left and right operands respectively. |
| 1725 | Register left = edx; |
| 1726 | Register right = eax; |
| 1727 | |
| 1728 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1729 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1730 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1731 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1732 | |
| 1733 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1734 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1735 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1736 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1737 | |
| 1738 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1739 | GenerateRegisterArgsPush(masm); |
| 1740 | __ TailCallStub(&string_add_stub); |
| 1741 | |
| 1742 | __ bind(&call_runtime); |
| 1743 | GenerateTypeTransition(masm); |
| 1744 | } |
| 1745 | |
| 1746 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1747 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1748 | Label* alloc_failure, |
| 1749 | OverwriteMode mode); |
| 1750 | |
| 1751 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1752 | // Input: |
| 1753 | // edx: left operand (tagged) |
| 1754 | // eax: right operand (tagged) |
| 1755 | // Output: |
| 1756 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1757 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1758 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1759 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1760 | |
| 1761 | // Floating point case. |
| 1762 | switch (op_) { |
| 1763 | case Token::ADD: |
| 1764 | case Token::SUB: |
| 1765 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1766 | case Token::DIV: |
| 1767 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1768 | Label not_floats; |
| 1769 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1770 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1771 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1772 | // It could be that only SMIs have been seen at either the left |
| 1773 | // or the right operand. For precise type feedback, patch the IC |
| 1774 | // again if this changes. |
| 1775 | // In theory, we would need the same check in the non-SSE2 case, |
| 1776 | // but since we don't support Crankshaft on such hardware we can |
| 1777 | // afford not to care about precise type feedback. |
| 1778 | if (left_type_ == BinaryOpIC::SMI) { |
| 1779 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1780 | } |
| 1781 | if (right_type_ == BinaryOpIC::SMI) { |
| 1782 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1783 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1784 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1785 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1786 | if (op_ == Token::MOD) { |
| 1787 | GenerateRegisterArgsPush(masm); |
| 1788 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1789 | } else { |
| 1790 | switch (op_) { |
| 1791 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1792 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1793 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1794 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1795 | default: UNREACHABLE(); |
| 1796 | } |
| 1797 | // Check result type if it is currently Int32. |
| 1798 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1799 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1800 | masm, ¬_int32, xmm0, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1801 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1802 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1803 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1804 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1805 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1806 | } else { // SSE2 not available, use FPU. |
| 1807 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1808 | FloatingPointHelper::LoadFloatOperands( |
| 1809 | masm, |
| 1810 | ecx, |
| 1811 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1812 | FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1813 | if (op_ == Token::MOD) { |
| 1814 | // The operands are now on the FPU stack, but we don't need them. |
| 1815 | __ fstp(0); |
| 1816 | __ fstp(0); |
| 1817 | GenerateRegisterArgsPush(masm); |
| 1818 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1819 | } else { |
| 1820 | switch (op_) { |
| 1821 | case Token::ADD: __ faddp(1); break; |
| 1822 | case Token::SUB: __ fsubp(1); break; |
| 1823 | case Token::MUL: __ fmulp(1); break; |
| 1824 | case Token::DIV: __ fdivp(1); break; |
| 1825 | default: UNREACHABLE(); |
| 1826 | } |
| 1827 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1828 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1829 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1830 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1831 | __ ret(0); |
| 1832 | __ bind(&after_alloc_failure); |
| 1833 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1834 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1835 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | __ bind(¬_floats); |
| 1839 | __ bind(¬_int32); |
| 1840 | GenerateTypeTransition(masm); |
| 1841 | break; |
| 1842 | } |
| 1843 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1844 | case Token::BIT_OR: |
| 1845 | case Token::BIT_AND: |
| 1846 | case Token::BIT_XOR: |
| 1847 | case Token::SAR: |
| 1848 | case Token::SHL: |
| 1849 | case Token::SHR: { |
| 1850 | GenerateRegisterArgsPush(masm); |
| 1851 | Label not_floats; |
| 1852 | Label not_int32; |
| 1853 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1854 | // We do not check the input arguments here, as any value is |
| 1855 | // unconditionally truncated to an int32 anyway. To get the |
| 1856 | // right optimized code, int32 type feedback is just right. |
| 1857 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1858 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1859 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1860 | ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1861 | FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1862 | ¬_int32); |
| 1863 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1864 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1865 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1866 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1867 | case Token::SAR: __ sar_cl(eax); break; |
| 1868 | case Token::SHL: __ shl_cl(eax); break; |
| 1869 | case Token::SHR: __ shr_cl(eax); break; |
| 1870 | default: UNREACHABLE(); |
| 1871 | } |
| 1872 | if (op_ == Token::SHR) { |
| 1873 | // Check if result is non-negative and fits in a smi. |
| 1874 | __ test(eax, Immediate(0xc0000000)); |
| 1875 | __ j(not_zero, &call_runtime); |
| 1876 | } else { |
| 1877 | // Check if result fits in a smi. |
| 1878 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1879 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1880 | } |
| 1881 | // Tag smi result and return. |
| 1882 | __ SmiTag(eax); |
| 1883 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1884 | |
| 1885 | // All ops except SHR return a signed int32 that we load in |
| 1886 | // a HeapNumber. |
| 1887 | if (op_ != Token::SHR) { |
| 1888 | __ bind(&non_smi_result); |
| 1889 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1890 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1891 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1892 | switch (mode_) { |
| 1893 | case OVERWRITE_LEFT: |
| 1894 | case OVERWRITE_RIGHT: |
| 1895 | // If the operand was an object, we skip the |
| 1896 | // allocation of a heap number. |
| 1897 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1898 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1899 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | // Fall through! |
| 1901 | case NO_OVERWRITE: |
| 1902 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1903 | __ bind(&skip_allocation); |
| 1904 | break; |
| 1905 | default: UNREACHABLE(); |
| 1906 | } |
| 1907 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1908 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1909 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1910 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1911 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1912 | } else { |
| 1913 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1914 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1915 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1916 | } |
| 1917 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1918 | } |
| 1919 | |
| 1920 | __ bind(¬_floats); |
| 1921 | __ bind(¬_int32); |
| 1922 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1923 | break; |
| 1924 | } |
| 1925 | default: UNREACHABLE(); break; |
| 1926 | } |
| 1927 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1928 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1929 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1930 | __ bind(&call_runtime); |
| 1931 | |
| 1932 | switch (op_) { |
| 1933 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1934 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1935 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1936 | case Token::DIV: |
| 1937 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1938 | break; |
| 1939 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1940 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1944 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1946 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | default: |
| 1949 | UNREACHABLE(); |
| 1950 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1951 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1955 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1956 | if (op_ == Token::ADD) { |
| 1957 | // Handle string addition here, because it is the only operation |
| 1958 | // that does not do a ToNumber conversion on the operands. |
| 1959 | GenerateAddStrings(masm); |
| 1960 | } |
| 1961 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1962 | Factory* factory = masm->isolate()->factory(); |
| 1963 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1964 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1965 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1966 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1967 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1968 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1969 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1970 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1971 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1972 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1973 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1974 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1975 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1976 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1977 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1978 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1979 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1980 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1981 | } |
| 1982 | __ bind(&done); |
| 1983 | |
| 1984 | GenerateHeapNumberStub(masm); |
| 1985 | } |
| 1986 | |
| 1987 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1988 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1989 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1990 | |
| 1991 | // Floating point case. |
| 1992 | switch (op_) { |
| 1993 | case Token::ADD: |
| 1994 | case Token::SUB: |
| 1995 | case Token::MUL: |
| 1996 | case Token::DIV: { |
| 1997 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1998 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2000 | |
| 2001 | // It could be that only SMIs have been seen at either the left |
| 2002 | // or the right operand. For precise type feedback, patch the IC |
| 2003 | // again if this changes. |
| 2004 | // In theory, we would need the same check in the non-SSE2 case, |
| 2005 | // but since we don't support Crankshaft on such hardware we can |
| 2006 | // afford not to care about precise type feedback. |
| 2007 | if (left_type_ == BinaryOpIC::SMI) { |
| 2008 | __ JumpIfNotSmi(edx, ¬_floats); |
| 2009 | } |
| 2010 | if (right_type_ == BinaryOpIC::SMI) { |
| 2011 | __ JumpIfNotSmi(eax, ¬_floats); |
| 2012 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2013 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2014 | if (left_type_ == BinaryOpIC::INT32) { |
| 2015 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 2016 | masm, ¬_floats, xmm0, ecx, xmm2); |
| 2017 | } |
| 2018 | if (right_type_ == BinaryOpIC::INT32) { |
| 2019 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 2020 | masm, ¬_floats, xmm1, ecx, xmm2); |
| 2021 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2022 | |
| 2023 | switch (op_) { |
| 2024 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2025 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2026 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2027 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2028 | default: UNREACHABLE(); |
| 2029 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2030 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2031 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2032 | __ ret(0); |
| 2033 | } else { // SSE2 not available, use FPU. |
| 2034 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2035 | FloatingPointHelper::LoadFloatOperands( |
| 2036 | masm, |
| 2037 | ecx, |
| 2038 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2039 | switch (op_) { |
| 2040 | case Token::ADD: __ faddp(1); break; |
| 2041 | case Token::SUB: __ fsubp(1); break; |
| 2042 | case Token::MUL: __ fmulp(1); break; |
| 2043 | case Token::DIV: __ fdivp(1); break; |
| 2044 | default: UNREACHABLE(); |
| 2045 | } |
| 2046 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2047 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2048 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2049 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2050 | __ ret(0); |
| 2051 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2052 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2053 | __ jmp(&call_runtime); |
| 2054 | } |
| 2055 | |
| 2056 | __ bind(¬_floats); |
| 2057 | GenerateTypeTransition(masm); |
| 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | case Token::MOD: { |
| 2062 | // For MOD we go directly to runtime in the non-smi case. |
| 2063 | break; |
| 2064 | } |
| 2065 | case Token::BIT_OR: |
| 2066 | case Token::BIT_AND: |
| 2067 | case Token::BIT_XOR: |
| 2068 | case Token::SAR: |
| 2069 | case Token::SHL: |
| 2070 | case Token::SHR: { |
| 2071 | GenerateRegisterArgsPush(masm); |
| 2072 | Label not_floats; |
| 2073 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2074 | // We do not check the input arguments here, as any value is |
| 2075 | // unconditionally truncated to an int32 anyway. To get the |
| 2076 | // right optimized code, int32 type feedback is just right. |
| 2077 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2078 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2079 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2080 | ¬_floats); |
| 2081 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2082 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2083 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2084 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2085 | case Token::SAR: __ sar_cl(eax); break; |
| 2086 | case Token::SHL: __ shl_cl(eax); break; |
| 2087 | case Token::SHR: __ shr_cl(eax); break; |
| 2088 | default: UNREACHABLE(); |
| 2089 | } |
| 2090 | if (op_ == Token::SHR) { |
| 2091 | // Check if result is non-negative and fits in a smi. |
| 2092 | __ test(eax, Immediate(0xc0000000)); |
| 2093 | __ j(not_zero, &call_runtime); |
| 2094 | } else { |
| 2095 | // Check if result fits in a smi. |
| 2096 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2097 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2098 | } |
| 2099 | // Tag smi result and return. |
| 2100 | __ SmiTag(eax); |
| 2101 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2102 | |
| 2103 | // All ops except SHR return a signed int32 that we load in |
| 2104 | // a HeapNumber. |
| 2105 | if (op_ != Token::SHR) { |
| 2106 | __ bind(&non_smi_result); |
| 2107 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2108 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2109 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2110 | switch (mode_) { |
| 2111 | case OVERWRITE_LEFT: |
| 2112 | case OVERWRITE_RIGHT: |
| 2113 | // If the operand was an object, we skip the |
| 2114 | // allocation of a heap number. |
| 2115 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2116 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2117 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2118 | // Fall through! |
| 2119 | case NO_OVERWRITE: |
| 2120 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2121 | __ bind(&skip_allocation); |
| 2122 | break; |
| 2123 | default: UNREACHABLE(); |
| 2124 | } |
| 2125 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2126 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2127 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2128 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2130 | } else { |
| 2131 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2132 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2133 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2134 | } |
| 2135 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2136 | } |
| 2137 | |
| 2138 | __ bind(¬_floats); |
| 2139 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2140 | break; |
| 2141 | } |
| 2142 | default: UNREACHABLE(); break; |
| 2143 | } |
| 2144 | |
| 2145 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2146 | // use the runtime system to get the correct result. |
| 2147 | __ bind(&call_runtime); |
| 2148 | |
| 2149 | switch (op_) { |
| 2150 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2151 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2152 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2154 | case Token::MOD: |
| 2155 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2158 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2160 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2161 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2162 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2163 | break; |
| 2164 | default: |
| 2165 | UNREACHABLE(); |
| 2166 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2167 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2171 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2172 | Label call_runtime; |
| 2173 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2174 | Counters* counters = masm->isolate()->counters(); |
| 2175 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2176 | |
| 2177 | switch (op_) { |
| 2178 | case Token::ADD: |
| 2179 | case Token::SUB: |
| 2180 | case Token::MUL: |
| 2181 | case Token::DIV: |
| 2182 | break; |
| 2183 | case Token::MOD: |
| 2184 | case Token::BIT_OR: |
| 2185 | case Token::BIT_AND: |
| 2186 | case Token::BIT_XOR: |
| 2187 | case Token::SAR: |
| 2188 | case Token::SHL: |
| 2189 | case Token::SHR: |
| 2190 | GenerateRegisterArgsPush(masm); |
| 2191 | break; |
| 2192 | default: |
| 2193 | UNREACHABLE(); |
| 2194 | } |
| 2195 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2196 | BinaryOpStub_GenerateSmiCode( |
| 2197 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2198 | |
| 2199 | // Floating point case. |
| 2200 | switch (op_) { |
| 2201 | case Token::ADD: |
| 2202 | case Token::SUB: |
| 2203 | case Token::MUL: |
| 2204 | case Token::DIV: { |
| 2205 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2206 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2207 | CpuFeatures::Scope use_sse2(SSE2); |
| 2208 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2209 | |
| 2210 | switch (op_) { |
| 2211 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2212 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2213 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2214 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2215 | default: UNREACHABLE(); |
| 2216 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2217 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2218 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2219 | __ ret(0); |
| 2220 | } else { // SSE2 not available, use FPU. |
| 2221 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2222 | FloatingPointHelper::LoadFloatOperands( |
| 2223 | masm, |
| 2224 | ecx, |
| 2225 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2226 | switch (op_) { |
| 2227 | case Token::ADD: __ faddp(1); break; |
| 2228 | case Token::SUB: __ fsubp(1); break; |
| 2229 | case Token::MUL: __ fmulp(1); break; |
| 2230 | case Token::DIV: __ fdivp(1); break; |
| 2231 | default: UNREACHABLE(); |
| 2232 | } |
| 2233 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2234 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2235 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2236 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2237 | __ ret(0); |
| 2238 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2239 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2240 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2241 | } |
| 2242 | __ bind(¬_floats); |
| 2243 | break; |
| 2244 | } |
| 2245 | case Token::MOD: { |
| 2246 | // For MOD we go directly to runtime in the non-smi case. |
| 2247 | break; |
| 2248 | } |
| 2249 | case Token::BIT_OR: |
| 2250 | case Token::BIT_AND: |
| 2251 | case Token::BIT_XOR: |
| 2252 | case Token::SAR: |
| 2253 | case Token::SHL: |
| 2254 | case Token::SHR: { |
| 2255 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2256 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2257 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2258 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | &call_runtime); |
| 2260 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2261 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2262 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2263 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2264 | case Token::SAR: __ sar_cl(eax); break; |
| 2265 | case Token::SHL: __ shl_cl(eax); break; |
| 2266 | case Token::SHR: __ shr_cl(eax); break; |
| 2267 | default: UNREACHABLE(); |
| 2268 | } |
| 2269 | if (op_ == Token::SHR) { |
| 2270 | // Check if result is non-negative and fits in a smi. |
| 2271 | __ test(eax, Immediate(0xc0000000)); |
| 2272 | __ j(not_zero, &call_runtime); |
| 2273 | } else { |
| 2274 | // Check if result fits in a smi. |
| 2275 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2276 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2277 | } |
| 2278 | // Tag smi result and return. |
| 2279 | __ SmiTag(eax); |
| 2280 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2281 | |
| 2282 | // All ops except SHR return a signed int32 that we load in |
| 2283 | // a HeapNumber. |
| 2284 | if (op_ != Token::SHR) { |
| 2285 | __ bind(&non_smi_result); |
| 2286 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2287 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2288 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2289 | switch (mode_) { |
| 2290 | case OVERWRITE_LEFT: |
| 2291 | case OVERWRITE_RIGHT: |
| 2292 | // If the operand was an object, we skip the |
| 2293 | // allocation of a heap number. |
| 2294 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2295 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2296 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2297 | // Fall through! |
| 2298 | case NO_OVERWRITE: |
| 2299 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2300 | __ bind(&skip_allocation); |
| 2301 | break; |
| 2302 | default: UNREACHABLE(); |
| 2303 | } |
| 2304 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2305 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2306 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2307 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2308 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2309 | } else { |
| 2310 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2311 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2312 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2313 | } |
| 2314 | __ ret(2 * kPointerSize); |
| 2315 | } |
| 2316 | break; |
| 2317 | } |
| 2318 | default: UNREACHABLE(); break; |
| 2319 | } |
| 2320 | |
| 2321 | // If all else fails, use the runtime system to get the correct |
| 2322 | // result. |
| 2323 | __ bind(&call_runtime); |
| 2324 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2325 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2326 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2327 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2328 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2329 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2330 | case Token::DIV: |
| 2331 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | break; |
| 2333 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2334 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2336 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2337 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2338 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2339 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2340 | break; |
| 2341 | default: |
| 2342 | UNREACHABLE(); |
| 2343 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2344 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2348 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2349 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2350 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2351 | |
| 2352 | // Registers containing left and right operands respectively. |
| 2353 | Register left = edx; |
| 2354 | Register right = eax; |
| 2355 | |
| 2356 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2357 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2358 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2359 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2360 | |
| 2361 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2362 | GenerateRegisterArgsPush(masm); |
| 2363 | __ TailCallStub(&string_add_left_stub); |
| 2364 | |
| 2365 | // Left operand is not a string, test right. |
| 2366 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2367 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2368 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2369 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2370 | |
| 2371 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2372 | GenerateRegisterArgsPush(masm); |
| 2373 | __ TailCallStub(&string_add_right_stub); |
| 2374 | |
| 2375 | // Neither argument is a string. |
| 2376 | __ bind(&call_runtime); |
| 2377 | } |
| 2378 | |
| 2379 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2380 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2381 | Label* alloc_failure, |
| 2382 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2383 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2384 | switch (mode) { |
| 2385 | case OVERWRITE_LEFT: { |
| 2386 | // If the argument in edx is already an object, we skip the |
| 2387 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2388 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2389 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2390 | // for the possible runtime call. |
| 2391 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2392 | // Now edx can be overwritten losing one of the arguments as we are |
| 2393 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2394 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2395 | __ bind(&skip_allocation); |
| 2396 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2397 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | } |
| 2400 | case OVERWRITE_RIGHT: |
| 2401 | // If the argument in eax is already an object, we skip the |
| 2402 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2403 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2404 | // Fall through! |
| 2405 | case NO_OVERWRITE: |
| 2406 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2407 | // for the possible runtime call. |
| 2408 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2409 | // Now eax can be overwritten losing one of the arguments as we are |
| 2410 | // now done and will not need it any more. |
| 2411 | __ mov(eax, ebx); |
| 2412 | __ bind(&skip_allocation); |
| 2413 | break; |
| 2414 | default: UNREACHABLE(); |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2419 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2420 | __ pop(ecx); |
| 2421 | __ push(edx); |
| 2422 | __ push(eax); |
| 2423 | __ push(ecx); |
| 2424 | } |
| 2425 | |
| 2426 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2427 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2428 | // TAGGED case: |
| 2429 | // Input: |
| 2430 | // esp[4]: tagged number input argument (should be number). |
| 2431 | // esp[0]: return address. |
| 2432 | // Output: |
| 2433 | // eax: tagged double result. |
| 2434 | // UNTAGGED case: |
| 2435 | // Input:: |
| 2436 | // esp[0]: return address. |
| 2437 | // xmm1: untagged double input argument |
| 2438 | // Output: |
| 2439 | // xmm1: untagged double result. |
| 2440 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2441 | Label runtime_call; |
| 2442 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2443 | Label skip_cache; |
| 2444 | const bool tagged = (argument_type_ == TAGGED); |
| 2445 | if (tagged) { |
| 2446 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2447 | Label input_not_smi; |
| 2448 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2449 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2450 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2451 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2452 | // Then load the low and high words of the double into ebx, edx. |
| 2453 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2454 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2455 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2456 | __ mov(Operand(esp, 0), eax); |
| 2457 | __ fild_s(Operand(esp, 0)); |
| 2458 | __ fst_d(Operand(esp, 0)); |
| 2459 | __ pop(edx); |
| 2460 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2461 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2462 | __ bind(&input_not_smi); |
| 2463 | // Check if input is a HeapNumber. |
| 2464 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2465 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2466 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2467 | __ j(not_equal, &runtime_call); |
| 2468 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2469 | // low and high words into ebx, edx. |
| 2470 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2471 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2472 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2473 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2474 | __ bind(&loaded); |
| 2475 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2476 | CpuFeatures::Scope scope(SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2477 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2478 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2479 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2480 | } else { |
| 2481 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2482 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2483 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2484 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2488 | // ebx = low 32 bits of double value |
| 2489 | // edx = high 32 bits of double value |
| 2490 | // Compute hash (the shifts are arithmetic): |
| 2491 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2492 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2493 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2494 | __ mov(eax, ecx); |
| 2495 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2497 | __ mov(eax, ecx); |
| 2498 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2499 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2500 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2501 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2502 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2503 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2504 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2505 | // ebx = low 32 bits of double value. |
| 2506 | // edx = high 32 bits of double value. |
| 2507 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2508 | ExternalReference cache_array = |
| 2509 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2510 | __ mov(eax, Immediate(cache_array)); |
| 2511 | int cache_array_index = |
| 2512 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2513 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2514 | // Eax points to the cache for the type type_. |
| 2515 | // 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] | 2516 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2517 | __ j(zero, &runtime_call_clear_stack); |
| 2518 | #ifdef DEBUG |
| 2519 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2520 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2521 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2522 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2523 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2524 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2525 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2526 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2527 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2528 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2529 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2530 | } |
| 2531 | #endif |
| 2532 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2533 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2534 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2535 | // 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] | 2536 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2537 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2538 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2539 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2540 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2541 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2542 | Counters* counters = masm->isolate()->counters(); |
| 2543 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2544 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2545 | if (tagged) { |
| 2546 | __ fstp(0); |
| 2547 | __ ret(kPointerSize); |
| 2548 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2549 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2550 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2551 | __ Ret(); |
| 2552 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2553 | |
| 2554 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2555 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2556 | // Update cache with new value. |
| 2557 | // We are short on registers, so use no_reg as scratch. |
| 2558 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2559 | if (tagged) { |
| 2560 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2561 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2562 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2563 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2564 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2565 | __ movdbl(Operand(esp, 0), xmm1); |
| 2566 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2567 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2568 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2569 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2570 | __ mov(Operand(ecx, 0), ebx); |
| 2571 | __ mov(Operand(ecx, kIntSize), edx); |
| 2572 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2573 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2574 | if (tagged) { |
| 2575 | __ ret(kPointerSize); |
| 2576 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2577 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2578 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2579 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2580 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2581 | // Skip cache and return answer directly, only in untagged case. |
| 2582 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2583 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2584 | __ movdbl(Operand(esp, 0), xmm1); |
| 2585 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2586 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2587 | __ fstp_d(Operand(esp, 0)); |
| 2588 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2589 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2590 | // We return the value in xmm1 without adding it to the cache, but |
| 2591 | // 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] | 2592 | { |
| 2593 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2594 | // Allocate an unused object bigger than a HeapNumber. |
| 2595 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2596 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2597 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2598 | __ Ret(); |
| 2599 | } |
| 2600 | |
| 2601 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2602 | if (tagged) { |
| 2603 | __ bind(&runtime_call_clear_stack); |
| 2604 | __ fstp(0); |
| 2605 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2606 | ExternalReference runtime = |
| 2607 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2608 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2609 | } else { // UNTAGGED. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2610 | CpuFeatures::Scope scope(SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2611 | __ bind(&runtime_call_clear_stack); |
| 2612 | __ bind(&runtime_call); |
| 2613 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2614 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2615 | { |
| 2616 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2617 | __ push(eax); |
| 2618 | __ CallRuntime(RuntimeFunction(), 1); |
| 2619 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2620 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2621 | __ Ret(); |
| 2622 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | |
| 2626 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2627 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2628 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2629 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2630 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2631 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2632 | default: |
| 2633 | UNIMPLEMENTED(); |
| 2634 | return Runtime::kAbort; |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2639 | void TranscendentalCacheStub::GenerateOperation( |
| 2640 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2641 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2642 | // Input value is on FP stack, and also in ebx/edx. |
| 2643 | // Input value is possibly in xmm1. |
| 2644 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2645 | if (type == TranscendentalCache::SIN || |
| 2646 | type == TranscendentalCache::COS || |
| 2647 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2648 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2649 | // return NaN for infinities and NaN. They can share all code except |
| 2650 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2651 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2652 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2653 | // work. We must reduce it to the appropriate range. |
| 2654 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2655 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2656 | int supported_exponent_limit = |
| 2657 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2658 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2659 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2660 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2661 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2662 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2663 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2664 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2665 | __ fstp(0); |
| 2666 | // NaN is represented by 0x7ff8000000000000. |
| 2667 | __ push(Immediate(0x7ff80000)); |
| 2668 | __ push(Immediate(0)); |
| 2669 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2670 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2671 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2672 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2673 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2674 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2675 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2676 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2677 | __ fldpi(); |
| 2678 | __ fadd(0); |
| 2679 | __ fld(1); |
| 2680 | // FPU Stack: input, 2*pi, input. |
| 2681 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2682 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2683 | __ fwait(); |
| 2684 | __ fnstsw_ax(); |
| 2685 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2686 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2687 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2688 | __ fnclex(); |
| 2689 | __ bind(&no_exceptions); |
| 2690 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2691 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2692 | // Compute st(0) % st(1) |
| 2693 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2694 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2695 | __ bind(&partial_remainder_loop); |
| 2696 | __ fprem1(); |
| 2697 | __ fwait(); |
| 2698 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2699 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2700 | // If C2 is set, computation only has partial result. Loop to |
| 2701 | // continue computation. |
| 2702 | __ j(not_zero, &partial_remainder_loop); |
| 2703 | } |
| 2704 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2705 | __ fstp(2); |
| 2706 | __ fstp(0); |
| 2707 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2708 | |
| 2709 | // FPU Stack: input % 2*pi |
| 2710 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2711 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2712 | case TranscendentalCache::SIN: |
| 2713 | __ fsin(); |
| 2714 | break; |
| 2715 | case TranscendentalCache::COS: |
| 2716 | __ fcos(); |
| 2717 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2718 | case TranscendentalCache::TAN: |
| 2719 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2720 | // FP register stack. |
| 2721 | __ fptan(); |
| 2722 | __ fstp(0); // Pop FP register stack. |
| 2723 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2724 | default: |
| 2725 | UNREACHABLE(); |
| 2726 | } |
| 2727 | __ bind(&done); |
| 2728 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2729 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2730 | __ fldln2(); |
| 2731 | __ fxch(); |
| 2732 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2733 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2737 | // Input: edx, eax are the left and right objects of a bit op. |
| 2738 | // Output: eax, ecx are left and right integers for a bit op. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2739 | void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 2740 | bool use_sse3, |
| 2741 | Label* conversion_failure) { |
| 2742 | // Check float operands. |
| 2743 | Label arg1_is_object, check_undefined_arg1; |
| 2744 | Label arg2_is_object, check_undefined_arg2; |
| 2745 | Label load_arg2, done; |
| 2746 | |
| 2747 | // Test if arg1 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2748 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2749 | |
| 2750 | __ SmiUntag(edx); |
| 2751 | __ jmp(&load_arg2); |
| 2752 | |
| 2753 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2754 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2755 | Factory* factory = masm->isolate()->factory(); |
| 2756 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2757 | __ j(not_equal, conversion_failure); |
| 2758 | __ mov(edx, Immediate(0)); |
| 2759 | __ jmp(&load_arg2); |
| 2760 | |
| 2761 | __ bind(&arg1_is_object); |
| 2762 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2763 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2764 | __ j(not_equal, &check_undefined_arg1); |
| 2765 | |
| 2766 | // Get the untagged integer version of the edx heap number in ecx. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2767 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2768 | __ mov(edx, ecx); |
| 2769 | |
| 2770 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2771 | __ bind(&load_arg2); |
| 2772 | |
| 2773 | // Test if arg2 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2774 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2775 | |
| 2776 | __ SmiUntag(eax); |
| 2777 | __ mov(ecx, eax); |
| 2778 | __ jmp(&done); |
| 2779 | |
| 2780 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2781 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2782 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2783 | __ j(not_equal, conversion_failure); |
| 2784 | __ mov(ecx, Immediate(0)); |
| 2785 | __ jmp(&done); |
| 2786 | |
| 2787 | __ bind(&arg2_is_object); |
| 2788 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2789 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2790 | __ j(not_equal, &check_undefined_arg2); |
| 2791 | |
| 2792 | // Get the untagged integer version of the eax heap number in ecx. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2793 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2794 | __ bind(&done); |
| 2795 | __ mov(eax, edx); |
| 2796 | } |
| 2797 | |
| 2798 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2799 | void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 2800 | bool use_sse3, |
| 2801 | Label* not_int32) { |
| 2802 | return; |
| 2803 | } |
| 2804 | |
| 2805 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2806 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2807 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2808 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2809 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2810 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2811 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2812 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2813 | |
| 2814 | __ bind(&load_smi); |
| 2815 | __ SmiUntag(number); |
| 2816 | __ push(number); |
| 2817 | __ fild_s(Operand(esp, 0)); |
| 2818 | __ pop(number); |
| 2819 | |
| 2820 | __ bind(&done); |
| 2821 | } |
| 2822 | |
| 2823 | |
| 2824 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2825 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2827 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2828 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2829 | |
| 2830 | __ bind(&load_eax); |
| 2831 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2832 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2833 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2834 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2835 | |
| 2836 | __ bind(&load_smi_edx); |
| 2837 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2838 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2839 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2840 | __ jmp(&load_eax); |
| 2841 | |
| 2842 | __ bind(&load_smi_eax); |
| 2843 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2844 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2845 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2846 | |
| 2847 | __ bind(&done); |
| 2848 | } |
| 2849 | |
| 2850 | |
| 2851 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2852 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2853 | 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] | 2854 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2855 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2856 | Factory* factory = masm->isolate()->factory(); |
| 2857 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2859 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2860 | __ bind(&load_eax); |
| 2861 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2862 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2863 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2864 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2866 | __ bind(&load_smi_edx); |
| 2867 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2868 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2869 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2870 | __ jmp(&load_eax); |
| 2871 | __ bind(&load_smi_eax); |
| 2872 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2873 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2874 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2875 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2876 | __ bind(&load_float_eax); |
| 2877 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2878 | __ bind(&done); |
| 2879 | } |
| 2880 | |
| 2881 | |
| 2882 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2883 | Register scratch) { |
| 2884 | const Register left = edx; |
| 2885 | const Register right = eax; |
| 2886 | __ mov(scratch, left); |
| 2887 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2888 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2889 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2890 | |
| 2891 | __ mov(scratch, right); |
| 2892 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2893 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2897 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2898 | Label* non_int32, |
| 2899 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2900 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, xmm2); |
| 2901 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, xmm2); |
| 2902 | } |
| 2903 | |
| 2904 | |
| 2905 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2906 | Label* non_int32, |
| 2907 | XMMRegister operand, |
| 2908 | Register scratch, |
| 2909 | XMMRegister xmm_scratch) { |
| 2910 | __ cvttsd2si(scratch, Operand(operand)); |
| 2911 | __ cvtsi2sd(xmm_scratch, scratch); |
| 2912 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2913 | __ movmskps(scratch, xmm_scratch); |
| 2914 | // Two least significant bits should be both set. |
| 2915 | __ not_(scratch); |
| 2916 | __ test(scratch, Immediate(3)); |
| 2917 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2921 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2922 | Register scratch, |
| 2923 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2924 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2925 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2926 | __ mov(scratch, edx); |
| 2927 | } else { |
| 2928 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2929 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2930 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2932 | __ bind(&done_load_1); |
| 2933 | |
| 2934 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2935 | __ mov(scratch, eax); |
| 2936 | } else { |
| 2937 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2938 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2939 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2940 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2941 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2942 | |
| 2943 | __ bind(&load_smi_1); |
| 2944 | __ SmiUntag(scratch); |
| 2945 | __ push(scratch); |
| 2946 | __ fild_s(Operand(esp, 0)); |
| 2947 | __ pop(scratch); |
| 2948 | __ jmp(&done_load_1); |
| 2949 | |
| 2950 | __ bind(&load_smi_2); |
| 2951 | __ SmiUntag(scratch); |
| 2952 | __ push(scratch); |
| 2953 | __ fild_s(Operand(esp, 0)); |
| 2954 | __ pop(scratch); |
| 2955 | |
| 2956 | __ bind(&done); |
| 2957 | } |
| 2958 | |
| 2959 | |
| 2960 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2961 | Register scratch) { |
| 2962 | const Register left = edx; |
| 2963 | const Register right = eax; |
| 2964 | __ mov(scratch, left); |
| 2965 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2966 | __ SmiUntag(scratch); |
| 2967 | __ push(scratch); |
| 2968 | __ fild_s(Operand(esp, 0)); |
| 2969 | |
| 2970 | __ mov(scratch, right); |
| 2971 | __ SmiUntag(scratch); |
| 2972 | __ mov(Operand(esp, 0), scratch); |
| 2973 | __ fild_s(Operand(esp, 0)); |
| 2974 | __ pop(scratch); |
| 2975 | } |
| 2976 | |
| 2977 | |
| 2978 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2979 | Label* non_float, |
| 2980 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2981 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2982 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2983 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2984 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2985 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2986 | Factory* factory = masm->isolate()->factory(); |
| 2987 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2988 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2989 | |
| 2990 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2991 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2992 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2993 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2994 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2995 | |
| 2996 | // Fall-through: Both operands are numbers. |
| 2997 | __ bind(&done); |
| 2998 | } |
| 2999 | |
| 3000 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3001 | void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 3002 | Label* non_int32) { |
| 3003 | return; |
| 3004 | } |
| 3005 | |
| 3006 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3007 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3008 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3009 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3010 | const Register exponent = eax; |
| 3011 | const Register base = edx; |
| 3012 | const Register scratch = ecx; |
| 3013 | const XMMRegister double_result = xmm3; |
| 3014 | const XMMRegister double_base = xmm2; |
| 3015 | const XMMRegister double_exponent = xmm1; |
| 3016 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3017 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3018 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3019 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3020 | // Save 1 in double_result - we need this several times later on. |
| 3021 | __ mov(scratch, Immediate(1)); |
| 3022 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3023 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3024 | if (exponent_type_ == ON_STACK) { |
| 3025 | Label base_is_smi, unpack_exponent; |
| 3026 | // The exponent and base are supplied as arguments on the stack. |
| 3027 | // This can only happen if the stub is called from non-optimized code. |
| 3028 | // Load input parameters from stack. |
| 3029 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3030 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3031 | |
| 3032 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3033 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3034 | factory->heap_number_map()); |
| 3035 | __ j(not_equal, &call_runtime); |
| 3036 | |
| 3037 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3038 | __ jmp(&unpack_exponent, Label::kNear); |
| 3039 | |
| 3040 | __ bind(&base_is_smi); |
| 3041 | __ SmiUntag(base); |
| 3042 | __ cvtsi2sd(double_base, base); |
| 3043 | |
| 3044 | __ bind(&unpack_exponent); |
| 3045 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3046 | __ SmiUntag(exponent); |
| 3047 | __ jmp(&int_exponent); |
| 3048 | |
| 3049 | __ bind(&exponent_not_smi); |
| 3050 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3051 | factory->heap_number_map()); |
| 3052 | __ j(not_equal, &call_runtime); |
| 3053 | __ movdbl(double_exponent, |
| 3054 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3055 | } else if (exponent_type_ == TAGGED) { |
| 3056 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3057 | __ SmiUntag(exponent); |
| 3058 | __ jmp(&int_exponent); |
| 3059 | |
| 3060 | __ bind(&exponent_not_smi); |
| 3061 | __ movdbl(double_exponent, |
| 3062 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3063 | } |
| 3064 | |
| 3065 | if (exponent_type_ != INTEGER) { |
| 3066 | Label fast_power; |
| 3067 | // Detect integer exponents stored as double. |
| 3068 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3069 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3070 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3071 | __ j(equal, &call_runtime); |
| 3072 | __ cvtsi2sd(double_scratch, exponent); |
| 3073 | // Already ruled out NaNs for exponent. |
| 3074 | __ ucomisd(double_exponent, double_scratch); |
| 3075 | __ j(equal, &int_exponent); |
| 3076 | |
| 3077 | if (exponent_type_ == ON_STACK) { |
| 3078 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3079 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3080 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3081 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3082 | // Test for 0.5. |
| 3083 | // Load double_scratch with 0.5. |
| 3084 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3085 | __ movd(double_scratch, scratch); |
| 3086 | __ cvtss2sd(double_scratch, double_scratch); |
| 3087 | // Already ruled out NaNs for exponent. |
| 3088 | __ ucomisd(double_scratch, double_exponent); |
| 3089 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3090 | |
| 3091 | // Calculates square root of base. Check for the special case of |
| 3092 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3093 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3094 | // 9 bits set and the lowest 23 bits cleared. |
| 3095 | __ mov(scratch, 0xFF800000u); |
| 3096 | __ movd(double_scratch, scratch); |
| 3097 | __ cvtss2sd(double_scratch, double_scratch); |
| 3098 | __ ucomisd(double_base, double_scratch); |
| 3099 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3100 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3101 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3102 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3103 | |
| 3104 | // Set result to Infinity in the special case. |
| 3105 | __ xorps(double_result, double_result); |
| 3106 | __ subsd(double_result, double_scratch); |
| 3107 | __ jmp(&done); |
| 3108 | |
| 3109 | __ bind(&continue_sqrt); |
| 3110 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3111 | __ xorps(double_scratch, double_scratch); |
| 3112 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3113 | __ sqrtsd(double_result, double_scratch); |
| 3114 | __ jmp(&done); |
| 3115 | |
| 3116 | // Test for -0.5. |
| 3117 | __ bind(¬_plus_half); |
| 3118 | // Load double_exponent with -0.5 by substracting 1. |
| 3119 | __ subsd(double_scratch, double_result); |
| 3120 | // Already ruled out NaNs for exponent. |
| 3121 | __ ucomisd(double_scratch, double_exponent); |
| 3122 | __ j(not_equal, &fast_power, Label::kNear); |
| 3123 | |
| 3124 | // Calculates reciprocal of square root of base. Check for the special |
| 3125 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3126 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3127 | // 9 bits set and the lowest 23 bits cleared. |
| 3128 | __ mov(scratch, 0xFF800000u); |
| 3129 | __ movd(double_scratch, scratch); |
| 3130 | __ cvtss2sd(double_scratch, double_scratch); |
| 3131 | __ ucomisd(double_base, double_scratch); |
| 3132 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3133 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3134 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3135 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3136 | |
| 3137 | // Set result to 0 in the special case. |
| 3138 | __ xorps(double_result, double_result); |
| 3139 | __ jmp(&done); |
| 3140 | |
| 3141 | __ bind(&continue_rsqrt); |
| 3142 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3143 | __ xorps(double_exponent, double_exponent); |
| 3144 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3145 | __ sqrtsd(double_exponent, double_exponent); |
| 3146 | __ divsd(double_result, double_exponent); |
| 3147 | __ jmp(&done); |
| 3148 | } |
| 3149 | |
| 3150 | // Using FPU instructions to calculate power. |
| 3151 | Label fast_power_failed; |
| 3152 | __ bind(&fast_power); |
| 3153 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3154 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3155 | __ sub(esp, Immediate(kDoubleSize)); |
| 3156 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3157 | __ fld_d(Operand(esp, 0)); // E |
| 3158 | __ movdbl(Operand(esp, 0), double_base); |
| 3159 | __ fld_d(Operand(esp, 0)); // B, E |
| 3160 | |
| 3161 | // Exponent is in st(1) and base is in st(0) |
| 3162 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3163 | // FYL2X calculates st(1) * log2(st(0)) |
| 3164 | __ fyl2x(); // X |
| 3165 | __ fld(0); // X, X |
| 3166 | __ frndint(); // rnd(X), X |
| 3167 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3168 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3169 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3170 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3171 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3172 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3173 | // FSCALE calculates st(0) * 2^st(1) |
| 3174 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3175 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3176 | // Bail out to runtime in case of exceptions in the status word. |
| 3177 | __ fnstsw_ax(); |
| 3178 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3179 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3180 | __ fstp_d(Operand(esp, 0)); |
| 3181 | __ movdbl(double_result, Operand(esp, 0)); |
| 3182 | __ add(esp, Immediate(kDoubleSize)); |
| 3183 | __ jmp(&done); |
| 3184 | |
| 3185 | __ bind(&fast_power_failed); |
| 3186 | __ fninit(); |
| 3187 | __ add(esp, Immediate(kDoubleSize)); |
| 3188 | __ jmp(&call_runtime); |
| 3189 | } |
| 3190 | |
| 3191 | // Calculate power with integer exponent. |
| 3192 | __ bind(&int_exponent); |
| 3193 | const XMMRegister double_scratch2 = double_exponent; |
| 3194 | __ mov(scratch, exponent); // Back up exponent. |
| 3195 | __ movsd(double_scratch, double_base); // Back up base. |
| 3196 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3197 | |
| 3198 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3199 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3200 | __ test(scratch, scratch); |
| 3201 | __ j(positive, &no_neg, Label::kNear); |
| 3202 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3203 | __ bind(&no_neg); |
| 3204 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3205 | __ j(zero, &while_false, Label::kNear); |
| 3206 | __ shr(scratch, 1); |
| 3207 | // Above condition means CF==0 && ZF==0. This means that the |
| 3208 | // bit that has been shifted out is 0 and the result is not 0. |
| 3209 | __ j(above, &while_true, Label::kNear); |
| 3210 | __ movsd(double_result, double_scratch); |
| 3211 | __ j(zero, &while_false, Label::kNear); |
| 3212 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3213 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3214 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3215 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3216 | __ j(above, &while_true, Label::kNear); |
| 3217 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3218 | __ j(not_zero, &while_true); |
| 3219 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3220 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3221 | // scratch has the original value of the exponent - if the exponent is |
| 3222 | // negative, return 1/result. |
| 3223 | __ test(exponent, exponent); |
| 3224 | __ j(positive, &done); |
| 3225 | __ divsd(double_scratch2, double_result); |
| 3226 | __ movsd(double_result, double_scratch2); |
| 3227 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3228 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3229 | __ xorps(double_scratch2, double_scratch2); |
| 3230 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3231 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3232 | // and may not have contained the exponent value in the first place when the |
| 3233 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3234 | __ j(not_equal, &done); |
| 3235 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3236 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3237 | // Returning or bailing out. |
| 3238 | Counters* counters = masm->isolate()->counters(); |
| 3239 | if (exponent_type_ == ON_STACK) { |
| 3240 | // The arguments are still on the stack. |
| 3241 | __ bind(&call_runtime); |
| 3242 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3243 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3244 | // The stub is called from non-optimized code, which expects the result |
| 3245 | // as heap number in exponent. |
| 3246 | __ bind(&done); |
| 3247 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3248 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3249 | __ IncrementCounter(counters->math_pow(), 1); |
| 3250 | __ ret(2 * kPointerSize); |
| 3251 | } else { |
| 3252 | __ bind(&call_runtime); |
| 3253 | { |
| 3254 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3255 | __ PrepareCallCFunction(4, scratch); |
| 3256 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3257 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3258 | __ CallCFunction( |
| 3259 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3260 | } |
| 3261 | // Return value is in st(0) on ia32. |
| 3262 | // Store it into the (fixed) result register. |
| 3263 | __ sub(esp, Immediate(kDoubleSize)); |
| 3264 | __ fstp_d(Operand(esp, 0)); |
| 3265 | __ movdbl(double_result, Operand(esp, 0)); |
| 3266 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3267 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3268 | __ bind(&done); |
| 3269 | __ IncrementCounter(counters->math_pow(), 1); |
| 3270 | __ ret(0); |
| 3271 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3275 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3276 | // ----------- S t a t e ------------- |
| 3277 | // -- ecx : name |
| 3278 | // -- edx : receiver |
| 3279 | // -- esp[0] : return address |
| 3280 | // ----------------------------------- |
| 3281 | Label miss; |
| 3282 | |
| 3283 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3284 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3285 | __ j(not_equal, &miss); |
| 3286 | } |
| 3287 | |
| 3288 | StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss); |
| 3289 | __ bind(&miss); |
| 3290 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3291 | } |
| 3292 | |
| 3293 | |
| 3294 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3295 | // ----------- S t a t e ------------- |
| 3296 | // -- ecx : name |
| 3297 | // -- edx : receiver |
| 3298 | // -- esp[0] : return address |
| 3299 | // ----------------------------------- |
| 3300 | Label miss; |
| 3301 | |
| 3302 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3303 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_symbol())); |
| 3304 | __ j(not_equal, &miss); |
| 3305 | } |
| 3306 | |
| 3307 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3308 | __ bind(&miss); |
| 3309 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3310 | } |
| 3311 | |
| 3312 | |
| 3313 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3314 | // ----------- S t a t e ------------- |
| 3315 | // -- ecx : name |
| 3316 | // -- edx : receiver |
| 3317 | // -- esp[0] : return address |
| 3318 | // ----------------------------------- |
| 3319 | Label miss; |
| 3320 | |
| 3321 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3322 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3323 | __ j(not_equal, &miss); |
| 3324 | } |
| 3325 | |
| 3326 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3327 | support_wrapper_); |
| 3328 | __ bind(&miss); |
| 3329 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 3330 | } |
| 3331 | |
| 3332 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3333 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3334 | // ----------- S t a t e ------------- |
| 3335 | // -- eax : value |
| 3336 | // -- ecx : name |
| 3337 | // -- edx : receiver |
| 3338 | // -- esp[0] : return address |
| 3339 | // ----------------------------------- |
| 3340 | // |
| 3341 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3342 | // (currently anything except for external arrays which means anything with |
| 3343 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3344 | // accepted as the most common case. |
| 3345 | |
| 3346 | Label miss; |
| 3347 | |
| 3348 | Register receiver = edx; |
| 3349 | Register value = eax; |
| 3350 | Register scratch = ebx; |
| 3351 | |
| 3352 | if (kind() == Code::KEYED_LOAD_IC) { |
| 3353 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol())); |
| 3354 | __ j(not_equal, &miss); |
| 3355 | } |
| 3356 | |
| 3357 | // Check that the receiver isn't a smi. |
| 3358 | __ JumpIfSmi(receiver, &miss); |
| 3359 | |
| 3360 | // Check that the object is a JS array. |
| 3361 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3362 | __ j(not_equal, &miss); |
| 3363 | |
| 3364 | // Check that elements are FixedArray. |
| 3365 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3366 | // fast elements (including COW). |
| 3367 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3368 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3369 | __ j(not_equal, &miss); |
| 3370 | |
| 3371 | // Check that the array has fast properties, otherwise the length |
| 3372 | // property might have been redefined. |
| 3373 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3374 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3375 | Heap::kHashTableMapRootIndex); |
| 3376 | __ j(equal, &miss); |
| 3377 | |
| 3378 | // Check that value is a smi. |
| 3379 | __ JumpIfNotSmi(value, &miss); |
| 3380 | |
| 3381 | // Prepare tail call to StoreIC_ArrayLength. |
| 3382 | __ pop(scratch); |
| 3383 | __ push(receiver); |
| 3384 | __ push(value); |
| 3385 | __ push(scratch); // return address |
| 3386 | |
| 3387 | ExternalReference ref = |
| 3388 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3389 | __ TailCallExternalReference(ref, 2, 1); |
| 3390 | |
| 3391 | __ bind(&miss); |
| 3392 | |
| 3393 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 3394 | } |
| 3395 | |
| 3396 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3397 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3398 | // The key is in edx and the parameter count is in eax. |
| 3399 | |
| 3400 | // The displacement is used for skipping the frame pointer on the |
| 3401 | // stack. It is the offset of the last parameter (if any) relative |
| 3402 | // to the frame pointer. |
| 3403 | static const int kDisplacement = 1 * kPointerSize; |
| 3404 | |
| 3405 | // Check that the key is a smi. |
| 3406 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3407 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3408 | |
| 3409 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3410 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3411 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3412 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3413 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3414 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3415 | |
| 3416 | // Check index against formal parameters count limit passed in |
| 3417 | // through register eax. Use unsigned comparison to get negative |
| 3418 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3419 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3420 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3421 | |
| 3422 | // Read the argument from the stack and return it. |
| 3423 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3424 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3425 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3426 | __ neg(edx); |
| 3427 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3428 | __ ret(0); |
| 3429 | |
| 3430 | // Arguments adaptor case: Check index against actual arguments |
| 3431 | // limit found in the arguments adaptor frame. Use unsigned |
| 3432 | // comparison to get negative check for free. |
| 3433 | __ bind(&adaptor); |
| 3434 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3435 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3436 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3437 | |
| 3438 | // Read the argument from the stack and return it. |
| 3439 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3440 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3441 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3442 | __ neg(edx); |
| 3443 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3444 | __ ret(0); |
| 3445 | |
| 3446 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3447 | // by calling the runtime system. |
| 3448 | __ bind(&slow); |
| 3449 | __ pop(ebx); // Return address. |
| 3450 | __ push(edx); |
| 3451 | __ push(ebx); |
| 3452 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3453 | } |
| 3454 | |
| 3455 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3456 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3457 | // esp[0] : return address |
| 3458 | // esp[4] : number of parameters |
| 3459 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3460 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3461 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3462 | // Check if the calling frame is an arguments adaptor frame. |
| 3463 | Label runtime; |
| 3464 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3465 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3466 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3467 | __ j(not_equal, &runtime, Label::kNear); |
| 3468 | |
| 3469 | // Patch the arguments.length and the parameters pointer. |
| 3470 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3471 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3472 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3473 | StandardFrameConstants::kCallerSPOffset)); |
| 3474 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3475 | |
| 3476 | __ bind(&runtime); |
| 3477 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3478 | } |
| 3479 | |
| 3480 | |
| 3481 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3482 | // esp[0] : return address |
| 3483 | // esp[4] : number of parameters (tagged) |
| 3484 | // esp[8] : receiver displacement |
| 3485 | // esp[12] : function |
| 3486 | |
| 3487 | // ebx = parameter count (tagged) |
| 3488 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3489 | |
| 3490 | // Check if the calling frame is an arguments adaptor frame. |
| 3491 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3492 | // Generate* functions. |
| 3493 | Label runtime; |
| 3494 | Label adaptor_frame, try_allocate; |
| 3495 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3496 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3497 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3498 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3499 | |
| 3500 | // No adaptor, parameter count = argument count. |
| 3501 | __ mov(ecx, ebx); |
| 3502 | __ jmp(&try_allocate, Label::kNear); |
| 3503 | |
| 3504 | // We have an adaptor frame. Patch the parameters pointer. |
| 3505 | __ bind(&adaptor_frame); |
| 3506 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3507 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3508 | StandardFrameConstants::kCallerSPOffset)); |
| 3509 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3510 | |
| 3511 | // ebx = parameter count (tagged) |
| 3512 | // ecx = argument count (tagged) |
| 3513 | // esp[4] = parameter count (tagged) |
| 3514 | // esp[8] = address of receiver argument |
| 3515 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3516 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3517 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3518 | __ mov(ebx, ecx); |
| 3519 | |
| 3520 | __ bind(&try_allocate); |
| 3521 | |
| 3522 | // Save mapped parameter count. |
| 3523 | __ push(ebx); |
| 3524 | |
| 3525 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3526 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3527 | const int kParameterMapHeaderSize = |
| 3528 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3529 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3530 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3531 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3532 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3533 | __ bind(&no_parameter_map); |
| 3534 | |
| 3535 | // 2. Backing store. |
| 3536 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3537 | |
| 3538 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3539 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3540 | |
| 3541 | // Do the allocation of all three objects in one go. |
| 3542 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3543 | |
| 3544 | // eax = address of new object(s) (tagged) |
| 3545 | // ecx = argument count (tagged) |
| 3546 | // esp[0] = mapped parameter count (tagged) |
| 3547 | // esp[8] = parameter count (tagged) |
| 3548 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3549 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3550 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3551 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3552 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3553 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3554 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3555 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3556 | __ mov(edi, Operand(edi, |
| 3557 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3558 | __ jmp(©, Label::kNear); |
| 3559 | |
| 3560 | __ bind(&has_mapped_parameters); |
| 3561 | __ mov(edi, Operand(edi, |
| 3562 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3563 | __ bind(©); |
| 3564 | |
| 3565 | // eax = address of new object (tagged) |
| 3566 | // ebx = mapped parameter count (tagged) |
| 3567 | // ecx = argument count (tagged) |
| 3568 | // edi = address of boilerplate object (tagged) |
| 3569 | // esp[0] = mapped parameter count (tagged) |
| 3570 | // esp[8] = parameter count (tagged) |
| 3571 | // esp[12] = address of receiver argument |
| 3572 | // Copy the JS object part. |
| 3573 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3574 | __ mov(edx, FieldOperand(edi, i)); |
| 3575 | __ mov(FieldOperand(eax, i), edx); |
| 3576 | } |
| 3577 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3578 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3579 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3580 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3581 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3582 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3583 | edx); |
| 3584 | |
| 3585 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3586 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3587 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3588 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3589 | ecx); |
| 3590 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3591 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3592 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3593 | // backing store. |
| 3594 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3595 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3596 | |
| 3597 | // eax = address of new object (tagged) |
| 3598 | // ebx = mapped parameter count (tagged) |
| 3599 | // ecx = argument count (tagged) |
| 3600 | // edi = address of parameter map or backing store (tagged) |
| 3601 | // esp[0] = mapped parameter count (tagged) |
| 3602 | // esp[8] = parameter count (tagged) |
| 3603 | // esp[12] = address of receiver argument |
| 3604 | // Free a register. |
| 3605 | __ push(eax); |
| 3606 | |
| 3607 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3608 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3609 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3610 | __ j(zero, &skip_parameter_map); |
| 3611 | |
| 3612 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3613 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3614 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3615 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3616 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3617 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3618 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3619 | |
| 3620 | // Copy the parameter slots and the holes in the arguments. |
| 3621 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3622 | // where parameters are stored in reverse order, at |
| 3623 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3624 | // The mapped parameter thus need to get indices |
| 3625 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3626 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3627 | // We loop from right to left. |
| 3628 | Label parameters_loop, parameters_test; |
| 3629 | __ push(ecx); |
| 3630 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3631 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3632 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3633 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3634 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3635 | __ mov(edx, edi); |
| 3636 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3637 | // eax = loop variable (tagged) |
| 3638 | // ebx = mapping index (tagged) |
| 3639 | // ecx = the hole value |
| 3640 | // edx = address of parameter map (tagged) |
| 3641 | // edi = address of backing store (tagged) |
| 3642 | // esp[0] = argument count (tagged) |
| 3643 | // esp[4] = address of new object (tagged) |
| 3644 | // esp[8] = mapped parameter count (tagged) |
| 3645 | // esp[16] = parameter count (tagged) |
| 3646 | // esp[20] = address of receiver argument |
| 3647 | __ jmp(¶meters_test, Label::kNear); |
| 3648 | |
| 3649 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3650 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3651 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3652 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3653 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3654 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3655 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3656 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3657 | __ pop(ecx); |
| 3658 | |
| 3659 | __ bind(&skip_parameter_map); |
| 3660 | |
| 3661 | // ecx = argument count (tagged) |
| 3662 | // edi = address of backing store (tagged) |
| 3663 | // esp[0] = address of new object (tagged) |
| 3664 | // esp[4] = mapped parameter count (tagged) |
| 3665 | // esp[12] = parameter count (tagged) |
| 3666 | // esp[16] = address of receiver argument |
| 3667 | // Copy arguments header and remaining slots (if there are any). |
| 3668 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3669 | Immediate(FACTORY->fixed_array_map())); |
| 3670 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3671 | |
| 3672 | Label arguments_loop, arguments_test; |
| 3673 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3674 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3675 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3676 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3677 | __ jmp(&arguments_test, Label::kNear); |
| 3678 | |
| 3679 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3680 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3681 | __ mov(eax, Operand(edx, 0)); |
| 3682 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3683 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3684 | |
| 3685 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3686 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3687 | __ j(less, &arguments_loop, Label::kNear); |
| 3688 | |
| 3689 | // Restore. |
| 3690 | __ pop(eax); // Address of arguments object. |
| 3691 | __ pop(ebx); // Parameter count. |
| 3692 | |
| 3693 | // Return and remove the on-stack parameters. |
| 3694 | __ ret(3 * kPointerSize); |
| 3695 | |
| 3696 | // Do the runtime call to allocate the arguments object. |
| 3697 | __ bind(&runtime); |
| 3698 | __ pop(eax); // Remove saved parameter count. |
| 3699 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3700 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | |
| 3704 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3705 | // esp[0] : return address |
| 3706 | // esp[4] : number of parameters |
| 3707 | // esp[8] : receiver displacement |
| 3708 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3709 | |
| 3710 | // Check if the calling frame is an arguments adaptor frame. |
| 3711 | Label adaptor_frame, try_allocate, runtime; |
| 3712 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3713 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3714 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3715 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3716 | |
| 3717 | // Get the length from the frame. |
| 3718 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3719 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3720 | |
| 3721 | // Patch the arguments.length and the parameters pointer. |
| 3722 | __ bind(&adaptor_frame); |
| 3723 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3724 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3725 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3726 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3727 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3728 | |
| 3729 | // Try the new space allocation. Start out with computing the size of |
| 3730 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3731 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3732 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3733 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3734 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3735 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3736 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3737 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3738 | |
| 3739 | // Do the allocation of both objects in one go. |
| 3740 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3741 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3742 | // Get the arguments boilerplate from the current native context. |
| 3743 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3744 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3745 | const int offset = |
| 3746 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3747 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3748 | |
| 3749 | // Copy the JS object part. |
| 3750 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3751 | __ mov(ebx, FieldOperand(edi, i)); |
| 3752 | __ mov(FieldOperand(eax, i), ebx); |
| 3753 | } |
| 3754 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3755 | // 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] | 3756 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3757 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3758 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3759 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3760 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3761 | |
| 3762 | // If there are no actual arguments, we're done. |
| 3763 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3764 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3765 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3766 | |
| 3767 | // Get the parameters pointer from the stack. |
| 3768 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3769 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3770 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3771 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3772 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3773 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3774 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3775 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3776 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3777 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3778 | // Untag the length for the loop below. |
| 3779 | __ SmiUntag(ecx); |
| 3780 | |
| 3781 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3782 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3783 | __ bind(&loop); |
| 3784 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3785 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3786 | __ add(edi, Immediate(kPointerSize)); |
| 3787 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3788 | __ dec(ecx); |
| 3789 | __ j(not_zero, &loop); |
| 3790 | |
| 3791 | // Return and remove the on-stack parameters. |
| 3792 | __ bind(&done); |
| 3793 | __ ret(3 * kPointerSize); |
| 3794 | |
| 3795 | // Do the runtime call to allocate the arguments object. |
| 3796 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3797 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | |
| 3801 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3802 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3803 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3804 | // at compilation. |
| 3805 | #ifdef V8_INTERPRETED_REGEXP |
| 3806 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3807 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3808 | |
| 3809 | // Stack frame on entry. |
| 3810 | // esp[0]: return address |
| 3811 | // esp[4]: last_match_info (expected JSArray) |
| 3812 | // esp[8]: previous index |
| 3813 | // esp[12]: subject string |
| 3814 | // esp[16]: JSRegExp object |
| 3815 | |
| 3816 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3817 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3818 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3819 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3820 | |
| 3821 | Label runtime, invoke_regexp; |
| 3822 | |
| 3823 | // Ensure that a RegExp stack is allocated. |
| 3824 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3825 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3826 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3827 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3828 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3829 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3830 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3831 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | |
| 3833 | // Check that the first argument is a JSRegExp object. |
| 3834 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3835 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3836 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3837 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3838 | __ j(not_equal, &runtime); |
| 3839 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3840 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3841 | if (FLAG_debug_code) { |
| 3842 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3843 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3844 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3845 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3846 | } |
| 3847 | |
| 3848 | // ecx: RegExp data (FixedArray) |
| 3849 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3850 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3851 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3852 | __ j(not_equal, &runtime); |
| 3853 | |
| 3854 | // ecx: RegExp data (FixedArray) |
| 3855 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3856 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3857 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3858 | // uses the asumption that smis are 2 * their untagged value. |
| 3859 | STATIC_ASSERT(kSmiTag == 0); |
| 3860 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3861 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3862 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3863 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3864 | __ j(above, &runtime); |
| 3865 | |
| 3866 | // ecx: RegExp data (FixedArray) |
| 3867 | // edx: Number of capture registers |
| 3868 | // Check that the second argument is a string. |
| 3869 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3870 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3871 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3872 | __ j(NegateCondition(is_string), &runtime); |
| 3873 | // Get the length of the string to ebx. |
| 3874 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3875 | |
| 3876 | // ebx: Length of subject string as a smi |
| 3877 | // ecx: RegExp data (FixedArray) |
| 3878 | // edx: Number of capture registers |
| 3879 | // Check that the third argument is a positive smi less than the subject |
| 3880 | // string length. A negative value will be greater (unsigned comparison). |
| 3881 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3882 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3883 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3884 | __ j(above_equal, &runtime); |
| 3885 | |
| 3886 | // ecx: RegExp data (FixedArray) |
| 3887 | // edx: Number of capture registers |
| 3888 | // Check that the fourth object is a JSArray object. |
| 3889 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3890 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3891 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3892 | __ j(not_equal, &runtime); |
| 3893 | // Check that the JSArray is in fast case. |
| 3894 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3895 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3896 | Factory* factory = masm->isolate()->factory(); |
| 3897 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3898 | __ j(not_equal, &runtime); |
| 3899 | // Check that the last match info has space for the capture registers and the |
| 3900 | // additional information. |
| 3901 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3902 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3903 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3904 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3905 | __ j(greater, &runtime); |
| 3906 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3907 | // Reset offset for possibly sliced string. |
| 3908 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3909 | // ecx: RegExp data (FixedArray) |
| 3910 | // Check the representation and encoding of the subject string. |
| 3911 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3912 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3913 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3914 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3915 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3916 | __ and_(ebx, kIsNotStringMask | |
| 3917 | kStringRepresentationMask | |
| 3918 | kStringEncodingMask | |
| 3919 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3920 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3921 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3922 | // 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] | 3923 | // string type tests will succeed if subject is not a string or a short |
| 3924 | // external string. |
| 3925 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3926 | kStringRepresentationMask | |
| 3927 | kShortExternalStringMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3928 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3929 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3930 | // 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] | 3931 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3932 | // A flat cons string is a cons string where the second part is the empty |
| 3933 | // string. In that case the subject string is just the first part of the cons |
| 3934 | // string. Also in this case the first part of the cons string is known to be |
| 3935 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3936 | // 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] | 3937 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3938 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3939 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3940 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3941 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3942 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3943 | __ j(less, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3944 | __ j(equal, &external_string); |
| 3945 | |
| 3946 | // Catch non-string subject or short external string. |
| 3947 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3948 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3949 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3950 | |
| 3951 | // String is sliced. |
| 3952 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3953 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3954 | // edi: offset of sliced string, smi-tagged. |
| 3955 | // eax: parent string. |
| 3956 | __ jmp(&check_encoding, Label::kNear); |
| 3957 | // String is a cons string, check whether it is flat. |
| 3958 | __ bind(&cons_string); |
| 3959 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3960 | __ j(not_equal, &runtime); |
| 3961 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3962 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3963 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3964 | // eax: first part of cons string or parent of sliced string. |
| 3965 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3966 | // 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] | 3967 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3968 | kStringRepresentationMask | kStringEncodingMask); |
| 3969 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3970 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3971 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3972 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3973 | kStringRepresentationMask); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3974 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3975 | |
| 3976 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3977 | // eax: subject string (flat ASCII) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3978 | // ecx: RegExp data (FixedArray) |
| 3979 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3980 | __ Set(ecx, Immediate(1)); // Type is ASCII. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3981 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3982 | |
| 3983 | __ bind(&seq_two_byte_string); |
| 3984 | // eax: subject string (flat two byte) |
| 3985 | // ecx: RegExp data (FixedArray) |
| 3986 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3987 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3988 | |
| 3989 | __ bind(&check_code); |
| 3990 | // Check that the irregexp code has been generated for the actual string |
| 3991 | // 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] | 3992 | // a smi (code flushing support). |
| 3993 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3994 | |
| 3995 | // eax: subject string |
| 3996 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3997 | // 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] | 3998 | // Load used arguments before starting to push arguments for call to native |
| 3999 | // RegExp code to avoid handling changing stack height. |
| 4000 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4001 | __ SmiUntag(ebx); // Previous index from smi. |
| 4002 | |
| 4003 | // eax: subject string |
| 4004 | // ebx: previous index |
| 4005 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4006 | // 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] | 4007 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4008 | Counters* counters = masm->isolate()->counters(); |
| 4009 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4010 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4011 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4012 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4013 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4014 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4015 | // Argument 9: Pass current isolate address. |
| 4016 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4017 | Immediate(ExternalReference::isolate_address())); |
| 4018 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4019 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 4020 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4021 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4022 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4023 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 4024 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4025 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 4026 | |
| 4027 | // Argument 6: Set the number of capture registers to zero to force global |
| 4028 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 4029 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4030 | |
| 4031 | // Argument 5: static offsets vector buffer. |
| 4032 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4033 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 4034 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4035 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4036 | // Argument 2: Previous index. |
| 4037 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 4038 | |
| 4039 | // Argument 1: Original subject string. |
| 4040 | // The original subject is in the previous stack frame. Therefore we have to |
| 4041 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 4042 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 4043 | // and thereby moves up esp by one kPointerSize.) |
| 4044 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 4045 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 4046 | |
| 4047 | // esi: original subject string |
| 4048 | // eax: underlying subject string |
| 4049 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4050 | // 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] | 4051 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4052 | // Argument 4: End of string data |
| 4053 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4054 | // Prepare start and end index of the input. |
| 4055 | // Load the length from the original sliced string if that is the case. |
| 4056 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4057 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4058 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4059 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4060 | |
| 4061 | // ebx: start index of the input string |
| 4062 | // esi: end index of the input string |
| 4063 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4064 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4065 | __ j(zero, &setup_two_byte, Label::kNear); |
| 4066 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4067 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4068 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4069 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4070 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4071 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4072 | |
| 4073 | __ bind(&setup_two_byte); |
| 4074 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4075 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 4076 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4077 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 4078 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 4079 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 4080 | |
| 4081 | __ bind(&setup_rest); |
| 4082 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4083 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4084 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 4085 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4086 | |
| 4087 | // Drop arguments and come back to JS mode. |
| 4088 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4089 | |
| 4090 | // Check the result. |
| 4091 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4092 | __ cmp(eax, 1); |
| 4093 | // We expect exactly one result since we force the called regexp to behave |
| 4094 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4095 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4096 | Label failure; |
| 4097 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4098 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4099 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 4100 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4101 | __ j(not_equal, &runtime); |
| 4102 | // Result must now be exception. If there is no pending exception already a |
| 4103 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4104 | // haven't created the exception yet. Handle that in the runtime system. |
| 4105 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4106 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4107 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4108 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4109 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4110 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4111 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4112 | // For exception, throw the exception again. |
| 4113 | |
| 4114 | // Clear the pending exception variable. |
| 4115 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4116 | |
| 4117 | // Special handling of termination exceptions which are uncatchable |
| 4118 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4119 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4120 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4121 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4122 | |
| 4123 | // Handle normal exception by following handler chain. |
| 4124 | __ Throw(eax); |
| 4125 | |
| 4126 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4127 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4128 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4129 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4130 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4131 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4132 | __ ret(4 * kPointerSize); |
| 4133 | |
| 4134 | // Load RegExp data. |
| 4135 | __ bind(&success); |
| 4136 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4137 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4138 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4139 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4140 | STATIC_ASSERT(kSmiTag == 0); |
| 4141 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4142 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4143 | |
| 4144 | // edx: Number of capture registers |
| 4145 | // Load last_match_info which is still known to be a fast case JSArray. |
| 4146 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4147 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 4148 | |
| 4149 | // ebx: last_match_info backing store (FixedArray) |
| 4150 | // edx: number of capture registers |
| 4151 | // Store the capture count. |
| 4152 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4153 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4154 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4155 | // Store last subject and last input. |
| 4156 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4157 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4158 | __ RecordWriteField(ebx, |
| 4159 | RegExpImpl::kLastSubjectOffset, |
| 4160 | eax, |
| 4161 | edi, |
| 4162 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4163 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4164 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4165 | __ RecordWriteField(ebx, |
| 4166 | RegExpImpl::kLastInputOffset, |
| 4167 | eax, |
| 4168 | edi, |
| 4169 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4170 | |
| 4171 | // Get the static offsets vector filled by the native regexp code. |
| 4172 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4173 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4174 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4175 | |
| 4176 | // ebx: last_match_info backing store (FixedArray) |
| 4177 | // ecx: offsets vector |
| 4178 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4179 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | // Capture register counter starts from number of capture registers and |
| 4181 | // counts down until wraping after zero. |
| 4182 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4183 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4184 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4185 | // Read the value from the static offsets vector buffer. |
| 4186 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4187 | __ SmiTag(edi); |
| 4188 | // Store the smi value in the last match info. |
| 4189 | __ mov(FieldOperand(ebx, |
| 4190 | edx, |
| 4191 | times_pointer_size, |
| 4192 | RegExpImpl::kFirstCaptureOffset), |
| 4193 | edi); |
| 4194 | __ jmp(&next_capture); |
| 4195 | __ bind(&done); |
| 4196 | |
| 4197 | // Return last match info. |
| 4198 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4199 | __ ret(4 * kPointerSize); |
| 4200 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4201 | // External string. Short external strings have already been ruled out. |
| 4202 | // eax: subject string (expected to be external) |
| 4203 | // ebx: scratch |
| 4204 | __ bind(&external_string); |
| 4205 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4206 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4207 | if (FLAG_debug_code) { |
| 4208 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4209 | // Sequential strings have already been ruled out. |
| 4210 | __ test_b(ebx, kIsIndirectStringMask); |
| 4211 | __ Assert(zero, "external string expected, but not found"); |
| 4212 | } |
| 4213 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4214 | // 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] | 4215 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4216 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4217 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4218 | __ test_b(ebx, kStringEncodingMask); |
| 4219 | __ j(not_zero, &seq_ascii_string); |
| 4220 | __ jmp(&seq_two_byte_string); |
| 4221 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4222 | // Do the runtime call to execute the regexp. |
| 4223 | __ bind(&runtime); |
| 4224 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4225 | #endif // V8_INTERPRETED_REGEXP |
| 4226 | } |
| 4227 | |
| 4228 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4229 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4230 | const int kMaxInlineLength = 100; |
| 4231 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4232 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4233 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4234 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4235 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4236 | __ j(above, &slowcase); |
| 4237 | // Smi-tagging is equivalent to multiplying by 2. |
| 4238 | STATIC_ASSERT(kSmiTag == 0); |
| 4239 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4240 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4241 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4242 | // Elements: [Map][Length][..elements..] |
| 4243 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4244 | times_pointer_size, |
| 4245 | ebx, // In: Number of elements as a smi |
| 4246 | REGISTER_VALUE_IS_SMI, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4247 | eax, // Out: Start of allocation (tagged). |
| 4248 | ecx, // Out: End of allocation. |
| 4249 | edx, // Scratch register |
| 4250 | &slowcase, |
| 4251 | TAG_OBJECT); |
| 4252 | // eax: Start of allocated area, object-tagged. |
| 4253 | |
| 4254 | // Set JSArray map to global.regexp_result_map(). |
| 4255 | // Set empty properties FixedArray. |
| 4256 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4257 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4258 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4259 | Factory* factory = masm->isolate()->factory(); |
| 4260 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4261 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4262 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4263 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4264 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4265 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4266 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4267 | |
| 4268 | // Set input, index and length fields from arguments. |
| 4269 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4270 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4271 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4272 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4273 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4274 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4275 | |
| 4276 | // Fill out the elements FixedArray. |
| 4277 | // eax: JSArray. |
| 4278 | // ebx: FixedArray. |
| 4279 | // ecx: Number of elements in array, as smi. |
| 4280 | |
| 4281 | // Set map. |
| 4282 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4283 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4284 | // Set length. |
| 4285 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4286 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4287 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4288 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4289 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4290 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4291 | // eax: JSArray. |
| 4292 | // ecx: Number of elements to fill. |
| 4293 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4294 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4295 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4296 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4297 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4298 | __ 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] | 4299 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4300 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4301 | __ jmp(&loop); |
| 4302 | |
| 4303 | __ bind(&done); |
| 4304 | __ ret(3 * kPointerSize); |
| 4305 | |
| 4306 | __ bind(&slowcase); |
| 4307 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4308 | } |
| 4309 | |
| 4310 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4311 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4312 | Register object, |
| 4313 | Register result, |
| 4314 | Register scratch1, |
| 4315 | Register scratch2, |
| 4316 | bool object_is_smi, |
| 4317 | Label* not_found) { |
| 4318 | // Use of registers. Register result is used as a temporary. |
| 4319 | Register number_string_cache = result; |
| 4320 | Register mask = scratch1; |
| 4321 | Register scratch = scratch2; |
| 4322 | |
| 4323 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4324 | ExternalReference roots_array_start = |
| 4325 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4326 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4327 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4328 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4329 | // Make the hash mask from the length of the number string cache. It |
| 4330 | // contains two elements (number and string) for each cache entry. |
| 4331 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4332 | __ 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] | 4333 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4334 | |
| 4335 | // Calculate the entry in the number string cache. The hash value in the |
| 4336 | // number string cache for smis is just the smi value, and the hash for |
| 4337 | // doubles is the xor of the upper and lower words. See |
| 4338 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4339 | Label smi_hash_calculated; |
| 4340 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4341 | if (object_is_smi) { |
| 4342 | __ mov(scratch, object); |
| 4343 | __ SmiUntag(scratch); |
| 4344 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4345 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4346 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4347 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4348 | __ mov(scratch, object); |
| 4349 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4350 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4351 | __ bind(¬_smi); |
| 4352 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4353 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4354 | __ j(not_equal, not_found); |
| 4355 | STATIC_ASSERT(8 == kDoubleSize); |
| 4356 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4357 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4358 | // 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] | 4359 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4360 | Register index = scratch; |
| 4361 | Register probe = mask; |
| 4362 | __ mov(probe, |
| 4363 | FieldOperand(number_string_cache, |
| 4364 | index, |
| 4365 | times_twice_pointer_size, |
| 4366 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4367 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4368 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4369 | CpuFeatures::Scope fscope(SSE2); |
| 4370 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4371 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4372 | __ ucomisd(xmm0, xmm1); |
| 4373 | } else { |
| 4374 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4375 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4376 | __ FCmp(); |
| 4377 | } |
| 4378 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4379 | __ 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] | 4380 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | __ bind(&smi_hash_calculated); |
| 4384 | // 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] | 4385 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4386 | Register index = scratch; |
| 4387 | // Check if the entry is the smi we are looking for. |
| 4388 | __ cmp(object, |
| 4389 | FieldOperand(number_string_cache, |
| 4390 | index, |
| 4391 | times_twice_pointer_size, |
| 4392 | FixedArray::kHeaderSize)); |
| 4393 | __ j(not_equal, not_found); |
| 4394 | |
| 4395 | // Get the result from the cache. |
| 4396 | __ bind(&load_result_from_cache); |
| 4397 | __ mov(result, |
| 4398 | FieldOperand(number_string_cache, |
| 4399 | index, |
| 4400 | times_twice_pointer_size, |
| 4401 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4402 | Counters* counters = masm->isolate()->counters(); |
| 4403 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | |
| 4407 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4408 | Label runtime; |
| 4409 | |
| 4410 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4411 | |
| 4412 | // Generate code to lookup number in the number string cache. |
| 4413 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4414 | __ ret(1 * kPointerSize); |
| 4415 | |
| 4416 | __ bind(&runtime); |
| 4417 | // Handle number to string in the runtime system if not found in the cache. |
| 4418 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4419 | } |
| 4420 | |
| 4421 | |
| 4422 | static int NegativeComparisonResult(Condition cc) { |
| 4423 | ASSERT(cc != equal); |
| 4424 | ASSERT((cc == less) || (cc == less_equal) |
| 4425 | || (cc == greater) || (cc == greater_equal)); |
| 4426 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4427 | } |
| 4428 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4429 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4430 | static void CheckInputType(MacroAssembler* masm, |
| 4431 | Register input, |
| 4432 | CompareIC::State expected, |
| 4433 | Label* fail) { |
| 4434 | Label ok; |
| 4435 | if (expected == CompareIC::SMI) { |
| 4436 | __ JumpIfNotSmi(input, fail); |
| 4437 | } else if (expected == CompareIC::HEAP_NUMBER) { |
| 4438 | __ JumpIfSmi(input, &ok); |
| 4439 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4440 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4441 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4442 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4443 | // We could be strict about symbol/string here, but as long as |
| 4444 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4445 | __ bind(&ok); |
| 4446 | } |
| 4447 | |
| 4448 | |
| 4449 | static void BranchIfNonSymbol(MacroAssembler* masm, |
| 4450 | Label* label, |
| 4451 | Register object, |
| 4452 | Register scratch) { |
| 4453 | __ JumpIfSmi(object, label); |
| 4454 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4455 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4456 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4457 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4458 | __ j(not_equal, label); |
| 4459 | } |
| 4460 | |
| 4461 | |
| 4462 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4463 | Label check_unequal_objects; |
| 4464 | Condition cc = GetCondition(); |
| 4465 | |
| 4466 | Label miss; |
| 4467 | CheckInputType(masm, edx, left_, &miss); |
| 4468 | CheckInputType(masm, eax, right_, &miss); |
| 4469 | |
| 4470 | // Compare two smis. |
| 4471 | Label non_smi, smi_done; |
| 4472 | __ mov(ecx, edx); |
| 4473 | __ or_(ecx, eax); |
| 4474 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4475 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4476 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4477 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4478 | __ bind(&smi_done); |
| 4479 | __ mov(eax, edx); |
| 4480 | __ ret(0); |
| 4481 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4482 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4483 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4484 | // it is certain that at least one operand isn't a smi. |
| 4485 | |
| 4486 | // Identical objects can be compared fast, but there are some tricky cases |
| 4487 | // for NaN and undefined. |
| 4488 | { |
| 4489 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4490 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4491 | __ j(not_equal, ¬_identical); |
| 4492 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4493 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4494 | // Check for undefined. undefined OP undefined is false even though |
| 4495 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4496 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4497 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4498 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4499 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4500 | __ ret(0); |
| 4501 | __ bind(&check_for_nan); |
| 4502 | } |
| 4503 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4504 | // 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] | 4505 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4506 | Label heap_number; |
| 4507 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4508 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4509 | __ j(equal, &heap_number, Label::kNear); |
| 4510 | if (cc != equal) { |
| 4511 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4512 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4513 | __ j(above_equal, ¬_identical); |
| 4514 | } |
| 4515 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4516 | __ ret(0); |
| 4517 | |
| 4518 | __ bind(&heap_number); |
| 4519 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4520 | // it's not NaN. |
| 4521 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4522 | // and not all mantissa bits (0..51) clear. |
| 4523 | // We only accept QNaNs, which have bit 51 set. |
| 4524 | // Read top bits of double representation (second word of value). |
| 4525 | |
| 4526 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4527 | // all bits in the mask are set. We only need to check the word |
| 4528 | // that contains the exponent and high bit of the mantissa. |
| 4529 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4530 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 4531 | __ Set(eax, Immediate(0)); |
| 4532 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4533 | // bits. |
| 4534 | __ add(edx, edx); |
| 4535 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4536 | if (cc == equal) { |
| 4537 | STATIC_ASSERT(EQUAL != 1); |
| 4538 | __ setcc(above_equal, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4539 | __ ret(0); |
| 4540 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4541 | Label nan; |
| 4542 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4543 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4544 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4545 | __ bind(&nan); |
| 4546 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 4547 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | __ bind(¬_identical); |
| 4551 | } |
| 4552 | |
| 4553 | // Strict equality can quickly decide whether objects are equal. |
| 4554 | // 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] | 4555 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4556 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4557 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4558 | // If we're doing a strict equality comparison, we don't have to do |
| 4559 | // type conversion, so we generate code to do fast comparison for objects |
| 4560 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4561 | // slow-case code. |
| 4562 | // If either is a Smi (we know that not both are), then they can only |
| 4563 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4564 | STATIC_ASSERT(kSmiTag == 0); |
| 4565 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4566 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4567 | __ and_(ecx, eax); |
| 4568 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4569 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4570 | // One operand is a smi. |
| 4571 | |
| 4572 | // Check whether the non-smi is a heap number. |
| 4573 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4574 | // 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] | 4575 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4576 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4577 | __ xor_(ebx, eax); |
| 4578 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4579 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4580 | // if eax was smi, ebx is now edx, else eax. |
| 4581 | |
| 4582 | // Check if the non-smi operand is a heap number. |
| 4583 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4584 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4586 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4587 | // Return non-equal (ebx is not zero) |
| 4588 | __ mov(eax, ebx); |
| 4589 | __ ret(0); |
| 4590 | |
| 4591 | __ bind(¬_smis); |
| 4592 | // If either operand is a JSObject or an oddball value, then they are not |
| 4593 | // equal since their pointers are different |
| 4594 | // There is no test for undetectability in strict equality. |
| 4595 | |
| 4596 | // Get the type of the first operand. |
| 4597 | // 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] | 4598 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4599 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4600 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4601 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4602 | |
| 4603 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4604 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4605 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4606 | __ bind(&return_not_equal); |
| 4607 | __ ret(0); |
| 4608 | |
| 4609 | __ bind(&first_non_object); |
| 4610 | // Check for oddballs: true, false, null, undefined. |
| 4611 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4612 | __ j(equal, &return_not_equal); |
| 4613 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4614 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4615 | __ j(above_equal, &return_not_equal); |
| 4616 | |
| 4617 | // Check for oddballs: true, false, null, undefined. |
| 4618 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4619 | __ j(equal, &return_not_equal); |
| 4620 | |
| 4621 | // Fall through to the general case. |
| 4622 | __ bind(&slow); |
| 4623 | } |
| 4624 | |
| 4625 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4626 | Label non_number_comparison; |
| 4627 | Label unordered; |
| 4628 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4629 | CpuFeatures::Scope use_sse2(SSE2); |
| 4630 | CpuFeatures::Scope use_cmov(CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4631 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4632 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4633 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4634 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4635 | // Don't base result on EFLAGS when a NaN is involved. |
| 4636 | __ j(parity_even, &unordered, Label::kNear); |
| 4637 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4638 | __ mov(eax, 0); // equal |
| 4639 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4640 | __ cmov(above, eax, ecx); |
| 4641 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4642 | __ cmov(below, eax, ecx); |
| 4643 | __ ret(0); |
| 4644 | } else { |
| 4645 | FloatingPointHelper::CheckFloatOperands( |
| 4646 | masm, &non_number_comparison, ebx); |
| 4647 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4648 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4649 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4650 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4651 | // Don't base result on EFLAGS when a NaN is involved. |
| 4652 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4653 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4654 | Label below_label, above_label; |
| 4655 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4656 | __ j(below, &below_label, Label::kNear); |
| 4657 | __ j(above, &above_label, Label::kNear); |
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 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4660 | __ ret(0); |
| 4661 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4662 | __ bind(&below_label); |
| 4663 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4664 | __ ret(0); |
| 4665 | |
| 4666 | __ bind(&above_label); |
| 4667 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4668 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4671 | // If one of the numbers was NaN, then the result is always false. |
| 4672 | // The cc is never not-equal. |
| 4673 | __ bind(&unordered); |
| 4674 | ASSERT(cc != not_equal); |
| 4675 | if (cc == less || cc == less_equal) { |
| 4676 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4677 | } else { |
| 4678 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4679 | } |
| 4680 | __ ret(0); |
| 4681 | |
| 4682 | // The number comparison code did not provide a valid result. |
| 4683 | __ bind(&non_number_comparison); |
| 4684 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4685 | // Fast negative check for symbol-to-symbol equality. |
| 4686 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4687 | if (cc == equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4688 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4689 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4690 | |
| 4691 | // We've already checked for object identity, so if both operands |
| 4692 | // are symbols they aren't equal. Register eax already holds a |
| 4693 | // non-zero value, which indicates not equal, so just return. |
| 4694 | __ ret(0); |
| 4695 | } |
| 4696 | |
| 4697 | __ bind(&check_for_strings); |
| 4698 | |
| 4699 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4700 | &check_unequal_objects); |
| 4701 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4702 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4703 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4704 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4705 | edx, |
| 4706 | eax, |
| 4707 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4708 | ebx); |
| 4709 | } else { |
| 4710 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4711 | edx, |
| 4712 | eax, |
| 4713 | ecx, |
| 4714 | ebx, |
| 4715 | edi); |
| 4716 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4717 | #ifdef DEBUG |
| 4718 | __ Abort("Unexpected fall-through from string comparison"); |
| 4719 | #endif |
| 4720 | |
| 4721 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4722 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4723 | // Non-strict equality. Objects are unequal if |
| 4724 | // they are both JSObjects and not undetectable, |
| 4725 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4726 | Label not_both_objects; |
| 4727 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4728 | // At most one is a smi, so we can test for smi by adding the two. |
| 4729 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4730 | // a heap object has the low bit clear. |
| 4731 | STATIC_ASSERT(kSmiTag == 0); |
| 4732 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4733 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4734 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4735 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4736 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4737 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4738 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4739 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4740 | // We do not bail out after this point. Both are JSObjects, and |
| 4741 | // they are equal if and only if both are undetectable. |
| 4742 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4743 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4744 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4745 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4746 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4747 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4748 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4749 | // The objects are both undetectable, so they both compare as the value |
| 4750 | // undefined, and are equal. |
| 4751 | __ Set(eax, Immediate(EQUAL)); |
| 4752 | __ bind(&return_unequal); |
| 4753 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4754 | // or return equal if we fell through to here. |
| 4755 | __ ret(0); // rax, rdx were pushed |
| 4756 | __ bind(¬_both_objects); |
| 4757 | } |
| 4758 | |
| 4759 | // Push arguments below the return address. |
| 4760 | __ pop(ecx); |
| 4761 | __ push(edx); |
| 4762 | __ push(eax); |
| 4763 | |
| 4764 | // Figure out which native to call and setup the arguments. |
| 4765 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4766 | if (cc == equal) { |
| 4767 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4768 | } else { |
| 4769 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4770 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | // Restore return address on the stack. |
| 4774 | __ push(ecx); |
| 4775 | |
| 4776 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4777 | // tagged as a small integer. |
| 4778 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4779 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4780 | __ bind(&miss); |
| 4781 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | |
| 4785 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4786 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4790 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4791 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4792 | } |
| 4793 | |
| 4794 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4795 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4796 | // Cache the called function in a global property cell. Cache states |
| 4797 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4798 | // megamorphic. |
| 4799 | // ebx : cache cell for call target |
| 4800 | // edi : the function to call |
| 4801 | Isolate* isolate = masm->isolate(); |
| 4802 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4803 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4804 | // Load the cache state into ecx. |
| 4805 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4806 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4807 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4808 | // function without changing the state. |
| 4809 | __ cmp(ecx, edi); |
| 4810 | __ j(equal, &done, Label::kNear); |
| 4811 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4812 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4813 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4814 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4815 | // megamorphic. |
| 4816 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4817 | __ j(equal, &initialize, Label::kNear); |
| 4818 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4819 | // write-barrier is needed. |
| 4820 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4821 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4822 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4823 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4824 | // An uninitialized cache is patched with the function. |
| 4825 | __ bind(&initialize); |
| 4826 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4827 | // No need for a write barrier here - cells are rescanned. |
| 4828 | |
| 4829 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4833 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4834 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4835 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4836 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4837 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4838 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4839 | // The receiver might implicitly be the global object. This is |
| 4840 | // indicated by passing the hole as the receiver to the call |
| 4841 | // function stub. |
| 4842 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4843 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4844 | // Get the receiver from the stack. |
| 4845 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4846 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4847 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4848 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4849 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4850 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4851 | __ mov(ecx, GlobalObjectOperand()); |
| 4852 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4853 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4854 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4857 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4858 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4859 | // Goto slow case if we do not have a function. |
| 4860 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4861 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4862 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4863 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4864 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4865 | } |
| 4866 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4867 | // Fast-case: Just invoke the function. |
| 4868 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4869 | |
| 4870 | if (ReceiverMightBeImplicit()) { |
| 4871 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4872 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4873 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4874 | __ InvokeFunction(edi, |
| 4875 | actual, |
| 4876 | JUMP_FUNCTION, |
| 4877 | NullCallWrapper(), |
| 4878 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4879 | __ bind(&call_as_function); |
| 4880 | } |
| 4881 | __ InvokeFunction(edi, |
| 4882 | actual, |
| 4883 | JUMP_FUNCTION, |
| 4884 | NullCallWrapper(), |
| 4885 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4886 | |
| 4887 | // Slow-case: Non-function called. |
| 4888 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4889 | if (RecordCallTarget()) { |
| 4890 | // 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] | 4891 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4892 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4893 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4894 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4895 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4896 | // Check for function proxy. |
| 4897 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4898 | __ j(not_equal, &non_function); |
| 4899 | __ pop(ecx); |
| 4900 | __ push(edi); // put proxy as additional argument under return address |
| 4901 | __ push(ecx); |
| 4902 | __ Set(eax, Immediate(argc_ + 1)); |
| 4903 | __ Set(ebx, Immediate(0)); |
| 4904 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4905 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4906 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4907 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4908 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4909 | } |
| 4910 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4911 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4912 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4913 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4914 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4915 | __ Set(eax, Immediate(argc_)); |
| 4916 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4917 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4918 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4919 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4921 | } |
| 4922 | |
| 4923 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4924 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4925 | // eax : number of arguments |
| 4926 | // ebx : cache cell for call target |
| 4927 | // edi : constructor function |
| 4928 | Label slow, non_function_call; |
| 4929 | |
| 4930 | // Check that function is not a smi. |
| 4931 | __ JumpIfSmi(edi, &non_function_call); |
| 4932 | // Check that function is a JSFunction. |
| 4933 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4934 | __ j(not_equal, &slow); |
| 4935 | |
| 4936 | if (RecordCallTarget()) { |
| 4937 | GenerateRecordCallTarget(masm); |
| 4938 | } |
| 4939 | |
| 4940 | // Jump to the function-specific construct stub. |
| 4941 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4942 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4943 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4944 | __ jmp(ebx); |
| 4945 | |
| 4946 | // edi: called object |
| 4947 | // eax: number of arguments |
| 4948 | // ecx: object map |
| 4949 | Label do_call; |
| 4950 | __ bind(&slow); |
| 4951 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4952 | __ j(not_equal, &non_function_call); |
| 4953 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4954 | __ jmp(&do_call); |
| 4955 | |
| 4956 | __ bind(&non_function_call); |
| 4957 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4958 | __ bind(&do_call); |
| 4959 | // Set expected number of arguments to zero (not changing eax). |
| 4960 | __ Set(ebx, Immediate(0)); |
| 4961 | Handle<Code> arguments_adaptor = |
| 4962 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4963 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4964 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4965 | } |
| 4966 | |
| 4967 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4968 | bool CEntryStub::NeedsImmovableCode() { |
| 4969 | return false; |
| 4970 | } |
| 4971 | |
| 4972 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4973 | bool CEntryStub::IsPregenerated() { |
| 4974 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4975 | result_size_ == 1; |
| 4976 | } |
| 4977 | |
| 4978 | |
| 4979 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4980 | CEntryStub::GenerateAheadOfTime(); |
| 4981 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4982 | // It is important that the store buffer overflow stubs are generated first. |
| 4983 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4984 | } |
| 4985 | |
| 4986 | |
| 4987 | void CodeStub::GenerateFPStubs() { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4988 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4989 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4990 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4991 | // which would lead to code stub initialization state being messed up. |
| 4992 | Code* save_doubles_code; |
| 4993 | if (!save_doubles.FindCodeInCache(&save_doubles_code, ISOLATE)) { |
| 4994 | save_doubles_code = *(save_doubles.GetCode()); |
| 4995 | } |
| 4996 | save_doubles_code->set_is_pregenerated(true); |
| 4997 | save_doubles_code->GetIsolate()->set_fp_stubs_generated(true); |
| 4998 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | |
| 5002 | void CEntryStub::GenerateAheadOfTime() { |
| 5003 | CEntryStub stub(1, kDontSaveFPRegs); |
| 5004 | Handle<Code> code = stub.GetCode(); |
| 5005 | code->set_is_pregenerated(true); |
| 5006 | } |
| 5007 | |
| 5008 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5009 | static void JumpIfOOM(MacroAssembler* masm, |
| 5010 | Register value, |
| 5011 | Register scratch, |
| 5012 | Label* oom_label) { |
| 5013 | __ mov(scratch, value); |
| 5014 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 5015 | STATIC_ASSERT(kFailureTag == 3); |
| 5016 | __ and_(scratch, 0xf); |
| 5017 | __ cmp(scratch, 0xf); |
| 5018 | __ j(equal, oom_label); |
| 5019 | } |
| 5020 | |
| 5021 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5022 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5023 | Label* throw_normal_exception, |
| 5024 | Label* throw_termination_exception, |
| 5025 | Label* throw_out_of_memory_exception, |
| 5026 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5027 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5028 | // eax: result parameter for PerformGC, if any |
| 5029 | // ebx: pointer to C function (C callee-saved) |
| 5030 | // ebp: frame pointer (restored after C call) |
| 5031 | // esp: stack pointer (restored after C call) |
| 5032 | // edi: number of arguments including receiver (C callee-saved) |
| 5033 | // esi: pointer to the first argument (C callee-saved) |
| 5034 | |
| 5035 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5036 | |
| 5037 | // Check stack alignment. |
| 5038 | if (FLAG_debug_code) { |
| 5039 | __ CheckStackAlignment(); |
| 5040 | } |
| 5041 | |
| 5042 | if (do_gc) { |
| 5043 | // Pass failure code returned from last attempt as first argument to |
| 5044 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5045 | // stack alignment is known to be correct. This function takes one argument |
| 5046 | // which is passed on the stack, and we know that the stack has been |
| 5047 | // prepared to pass at least one argument. |
| 5048 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5049 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5050 | } |
| 5051 | |
| 5052 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5053 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5054 | if (always_allocate_scope) { |
| 5055 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5056 | } |
| 5057 | |
| 5058 | // Call C function. |
| 5059 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5060 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5061 | __ mov(Operand(esp, 2 * kPointerSize), |
| 5062 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5063 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5064 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5065 | |
| 5066 | if (always_allocate_scope) { |
| 5067 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5068 | } |
| 5069 | |
| 5070 | // Make sure we're not trying to return 'the hole' from the runtime |
| 5071 | // call as this may lead to crashes in the IC code later. |
| 5072 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5073 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5074 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5075 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5076 | __ int3(); |
| 5077 | __ bind(&okay); |
| 5078 | } |
| 5079 | |
| 5080 | // Check for failure result. |
| 5081 | Label failure_returned; |
| 5082 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5083 | __ lea(ecx, Operand(eax, 1)); |
| 5084 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5085 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5086 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5087 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5088 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5089 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5090 | |
| 5091 | // Check that there is no pending exception, otherwise we |
| 5092 | // should have returned some failure value. |
| 5093 | if (FLAG_debug_code) { |
| 5094 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5095 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5096 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5097 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5098 | // 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] | 5099 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5100 | __ int3(); |
| 5101 | __ bind(&okay); |
| 5102 | __ pop(edx); |
| 5103 | } |
| 5104 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5105 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5106 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5107 | __ ret(0); |
| 5108 | |
| 5109 | // Handling of failure. |
| 5110 | __ bind(&failure_returned); |
| 5111 | |
| 5112 | Label retry; |
| 5113 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5114 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5115 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5116 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5117 | |
| 5118 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5119 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5120 | |
| 5121 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5122 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5123 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5124 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5125 | |
| 5126 | // Special handling of termination exceptions which are uncatchable |
| 5127 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5128 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5129 | __ j(equal, throw_termination_exception); |
| 5130 | |
| 5131 | // Handle normal exception. |
| 5132 | __ jmp(throw_normal_exception); |
| 5133 | |
| 5134 | // Retry. |
| 5135 | __ bind(&retry); |
| 5136 | } |
| 5137 | |
| 5138 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5139 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5140 | // eax: number of arguments including receiver |
| 5141 | // ebx: pointer to C function (C callee-saved) |
| 5142 | // ebp: frame pointer (restored after C call) |
| 5143 | // esp: stack pointer (restored after C call) |
| 5144 | // esi: current context (C callee-saved) |
| 5145 | // edi: JS function of the caller (C callee-saved) |
| 5146 | |
| 5147 | // NOTE: Invocations of builtins may return failure objects instead |
| 5148 | // of a proper result. The builtin entry handles this by performing |
| 5149 | // a garbage collection and retrying the builtin (twice). |
| 5150 | |
| 5151 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5152 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5153 | |
| 5154 | // eax: result parameter for PerformGC, if any (setup below) |
| 5155 | // ebx: pointer to builtin function (C callee-saved) |
| 5156 | // ebp: frame pointer (restored after C call) |
| 5157 | // esp: stack pointer (restored after C call) |
| 5158 | // edi: number of arguments including receiver (C callee-saved) |
| 5159 | // esi: argv pointer (C callee-saved) |
| 5160 | |
| 5161 | Label throw_normal_exception; |
| 5162 | Label throw_termination_exception; |
| 5163 | Label throw_out_of_memory_exception; |
| 5164 | |
| 5165 | // Call into the runtime system. |
| 5166 | GenerateCore(masm, |
| 5167 | &throw_normal_exception, |
| 5168 | &throw_termination_exception, |
| 5169 | &throw_out_of_memory_exception, |
| 5170 | false, |
| 5171 | false); |
| 5172 | |
| 5173 | // Do space-specific GC and retry runtime call. |
| 5174 | GenerateCore(masm, |
| 5175 | &throw_normal_exception, |
| 5176 | &throw_termination_exception, |
| 5177 | &throw_out_of_memory_exception, |
| 5178 | true, |
| 5179 | false); |
| 5180 | |
| 5181 | // Do full GC and retry runtime call one final time. |
| 5182 | Failure* failure = Failure::InternalError(); |
| 5183 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5184 | GenerateCore(masm, |
| 5185 | &throw_normal_exception, |
| 5186 | &throw_termination_exception, |
| 5187 | &throw_out_of_memory_exception, |
| 5188 | true, |
| 5189 | true); |
| 5190 | |
| 5191 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5192 | // Set external caught exception to false. |
| 5193 | Isolate* isolate = masm->isolate(); |
| 5194 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5195 | isolate); |
| 5196 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5197 | |
| 5198 | // Set pending exception and eax to out of memory exception. |
| 5199 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5200 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5201 | Label already_have_failure; |
| 5202 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5203 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5204 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5205 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5206 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5207 | |
| 5208 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5209 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5210 | |
| 5211 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5212 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | |
| 5216 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5217 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5218 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5219 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5220 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5222 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5223 | |
| 5224 | // Push marker in two places. |
| 5225 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5226 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5227 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5228 | // Save callee-saved registers (C calling conventions). |
| 5229 | __ push(edi); |
| 5230 | __ push(esi); |
| 5231 | __ push(ebx); |
| 5232 | |
| 5233 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5234 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5235 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5236 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5237 | // 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] | 5238 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5239 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5240 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5241 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5242 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5243 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5244 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5245 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5246 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5247 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5248 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5249 | // block that sets the pending exception. |
| 5250 | __ jmp(&invoke); |
| 5251 | __ bind(&handler_entry); |
| 5252 | handler_offset_ = handler_entry.pos(); |
| 5253 | // Caught exception: Store result (exception) in the pending exception |
| 5254 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5255 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5256 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5257 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5258 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5259 | __ jmp(&exit); |
| 5260 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5261 | // Invoke: Link this frame into the handler chain. There's only one |
| 5262 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5264 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5265 | |
| 5266 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5267 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5268 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5269 | |
| 5270 | // Fake a receiver (NULL). |
| 5271 | __ push(Immediate(0)); // receiver |
| 5272 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5273 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5274 | // pop the faked function when we return. Notice that we cannot store a |
| 5275 | // reference to the trampoline code directly in this stub, because the |
| 5276 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5277 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5278 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5279 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5280 | __ mov(edx, Immediate(construct_entry)); |
| 5281 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5282 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5283 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5284 | __ mov(edx, Immediate(entry)); |
| 5285 | } |
| 5286 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5287 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5288 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5289 | |
| 5290 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5291 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5292 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5293 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5294 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5295 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5296 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | __ j(not_equal, ¬_outermost_js_2); |
| 5298 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5299 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | |
| 5301 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5302 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5303 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5304 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5305 | |
| 5306 | // Restore callee-saved registers (C calling conventions). |
| 5307 | __ pop(ebx); |
| 5308 | __ pop(esi); |
| 5309 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5310 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5311 | |
| 5312 | // Restore frame pointer and return. |
| 5313 | __ pop(ebp); |
| 5314 | __ ret(0); |
| 5315 | } |
| 5316 | |
| 5317 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5318 | // Generate stub code for instanceof. |
| 5319 | // This code can patch a call site inlined cache of the instance of check, |
| 5320 | // which looks like this. |
| 5321 | // |
| 5322 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5323 | // 75 0a jne <some near label> |
| 5324 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5325 | // |
| 5326 | // If call site patching is requested the stack will have the delta from the |
| 5327 | // return address to the cmp instruction just below the return address. This |
| 5328 | // also means that call site patching can only take place with arguments in |
| 5329 | // registers. TOS looks like this when call site patching is requested |
| 5330 | // |
| 5331 | // esp[0] : return address |
| 5332 | // esp[4] : delta from return address to cmp instruction |
| 5333 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5334 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5335 | // Call site inlining and patching implies arguments in registers. |
| 5336 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5337 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5338 | // Fixed register usage throughout the stub. |
| 5339 | Register object = eax; // Object (lhs). |
| 5340 | Register map = ebx; // Map of the object. |
| 5341 | Register function = edx; // Function (rhs). |
| 5342 | Register prototype = edi; // Prototype of the function. |
| 5343 | Register scratch = ecx; |
| 5344 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5345 | // Constants describing the call site code to patch. |
| 5346 | static const int kDeltaToCmpImmediate = 2; |
| 5347 | static const int kDeltaToMov = 8; |
| 5348 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5349 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5350 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5351 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5352 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5353 | ExternalReference roots_array_start = |
| 5354 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5355 | |
| 5356 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5357 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5358 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5359 | // Get the object and function - they are always both needed. |
| 5360 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5361 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5362 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5363 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5364 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5365 | |
| 5366 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5367 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5368 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5369 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5370 | // If there is a call site cache don't look in the global cache, but do the |
| 5371 | // real lookup and update the call site cache. |
| 5372 | if (!HasCallSiteInlineCheck()) { |
| 5373 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5374 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5375 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5376 | __ cmp(function, Operand::StaticArray(scratch, |
| 5377 | times_pointer_size, |
| 5378 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5379 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5380 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5381 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5382 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5383 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5384 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5385 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5386 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5387 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5388 | __ bind(&miss); |
| 5389 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5390 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5391 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5392 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5393 | |
| 5394 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5395 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5396 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5397 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5398 | // Update the global instanceof or call site inlined cache with the current |
| 5399 | // map and function. The cached answer will be set when it is known below. |
| 5400 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5401 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5402 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5403 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5404 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5405 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5406 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5407 | } else { |
| 5408 | // The constants for the code patching are based on no push instructions |
| 5409 | // at the call site. |
| 5410 | ASSERT(HasArgsInRegisters()); |
| 5411 | // Get return address and delta to inlined map check. |
| 5412 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5413 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5414 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5415 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5416 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5417 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5418 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5419 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5420 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5421 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5422 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5423 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5424 | // Loop through the prototype chain of the object looking for the function |
| 5425 | // prototype. |
| 5426 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5427 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5428 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5429 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5430 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5431 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5432 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5433 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5434 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5435 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5436 | __ jmp(&loop); |
| 5437 | |
| 5438 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5439 | if (!HasCallSiteInlineCheck()) { |
| 5440 | __ Set(eax, Immediate(0)); |
| 5441 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5442 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5443 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5444 | } else { |
| 5445 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5446 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5447 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5448 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5449 | if (FLAG_debug_code) { |
| 5450 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5451 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5452 | } |
| 5453 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5454 | if (!ReturnTrueFalseObject()) { |
| 5455 | __ Set(eax, Immediate(0)); |
| 5456 | } |
| 5457 | } |
| 5458 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5459 | |
| 5460 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5461 | if (!HasCallSiteInlineCheck()) { |
| 5462 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5463 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5464 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5465 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5466 | } else { |
| 5467 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5468 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5469 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5470 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5471 | if (FLAG_debug_code) { |
| 5472 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5473 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5474 | } |
| 5475 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5476 | if (!ReturnTrueFalseObject()) { |
| 5477 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5478 | } |
| 5479 | } |
| 5480 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5481 | |
| 5482 | Label object_not_null, object_not_null_or_smi; |
| 5483 | __ bind(¬_js_object); |
| 5484 | // Before null, smi and string value checks, check that the rhs is a function |
| 5485 | // 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] | 5486 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5487 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5488 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5489 | |
| 5490 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5491 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5492 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5493 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5494 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5495 | |
| 5496 | __ bind(&object_not_null); |
| 5497 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5498 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5499 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5500 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5501 | |
| 5502 | __ bind(&object_not_null_or_smi); |
| 5503 | // String values is not instance of anything. |
| 5504 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5505 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5506 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5507 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5508 | |
| 5509 | // Slow-case: Go through the JavaScript implementation. |
| 5510 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5511 | if (!ReturnTrueFalseObject()) { |
| 5512 | // Tail call the builtin which returns 0 or 1. |
| 5513 | if (HasArgsInRegisters()) { |
| 5514 | // Push arguments below return address. |
| 5515 | __ pop(scratch); |
| 5516 | __ push(object); |
| 5517 | __ push(function); |
| 5518 | __ push(scratch); |
| 5519 | } |
| 5520 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5521 | } else { |
| 5522 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5523 | { |
| 5524 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5525 | __ push(object); |
| 5526 | __ push(function); |
| 5527 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5528 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5529 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5530 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5531 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5532 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5533 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5534 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5535 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5536 | __ bind(&done); |
| 5537 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5538 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5542 | Register InstanceofStub::left() { return eax; } |
| 5543 | |
| 5544 | |
| 5545 | Register InstanceofStub::right() { return edx; } |
| 5546 | |
| 5547 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5548 | // ------------------------------------------------------------------------- |
| 5549 | // StringCharCodeAtGenerator |
| 5550 | |
| 5551 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5552 | // If the receiver is a smi trigger the non-string case. |
| 5553 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5554 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5555 | |
| 5556 | // Fetch the instance type of the receiver into result register. |
| 5557 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5558 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5559 | // If the receiver is not a string trigger the non-string case. |
| 5560 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5561 | __ j(not_zero, receiver_not_string_); |
| 5562 | |
| 5563 | // If the index is non-smi trigger the non-smi case. |
| 5564 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5565 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5566 | __ bind(&got_smi_index_); |
| 5567 | |
| 5568 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5569 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5570 | __ j(above_equal, index_out_of_range_); |
| 5571 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5572 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5573 | |
| 5574 | Factory* factory = masm->isolate()->factory(); |
| 5575 | StringCharLoadGenerator::Generate( |
| 5576 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5577 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5578 | __ SmiTag(result_); |
| 5579 | __ bind(&exit_); |
| 5580 | } |
| 5581 | |
| 5582 | |
| 5583 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5584 | MacroAssembler* masm, |
| 5585 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5586 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5587 | |
| 5588 | // Index is not a smi. |
| 5589 | __ bind(&index_not_smi_); |
| 5590 | // 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] | 5591 | __ CheckMap(index_, |
| 5592 | masm->isolate()->factory()->heap_number_map(), |
| 5593 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5594 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5595 | call_helper.BeforeCall(masm); |
| 5596 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5597 | __ push(index_); // Consumed by runtime conversion function. |
| 5598 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5599 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5600 | } else { |
| 5601 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5602 | // NumberToSmi discards numbers that are not exact integers. |
| 5603 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5604 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5605 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5606 | // Save the conversion result before the pop instructions below |
| 5607 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5608 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5609 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5610 | __ pop(object_); |
| 5611 | // Reload the instance type. |
| 5612 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5613 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5614 | call_helper.AfterCall(masm); |
| 5615 | // If index is still not a smi, it must be out of range. |
| 5616 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5617 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5618 | // Otherwise, return to the fast path. |
| 5619 | __ jmp(&got_smi_index_); |
| 5620 | |
| 5621 | // Call runtime. We get here when the receiver is a string and the |
| 5622 | // index is a number, but the code of getting the actual character |
| 5623 | // is too complex (e.g., when the string needs to be flattened). |
| 5624 | __ bind(&call_runtime_); |
| 5625 | call_helper.BeforeCall(masm); |
| 5626 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5627 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5628 | __ push(index_); |
| 5629 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5630 | if (!result_.is(eax)) { |
| 5631 | __ mov(result_, eax); |
| 5632 | } |
| 5633 | call_helper.AfterCall(masm); |
| 5634 | __ jmp(&exit_); |
| 5635 | |
| 5636 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5637 | } |
| 5638 | |
| 5639 | |
| 5640 | // ------------------------------------------------------------------------- |
| 5641 | // StringCharFromCodeGenerator |
| 5642 | |
| 5643 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5644 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5645 | STATIC_ASSERT(kSmiTag == 0); |
| 5646 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5647 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5648 | __ test(code_, |
| 5649 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5650 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5651 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5652 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5653 | Factory* factory = masm->isolate()->factory(); |
| 5654 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5655 | STATIC_ASSERT(kSmiTag == 0); |
| 5656 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5657 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5658 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5659 | __ mov(result_, FieldOperand(result_, |
| 5660 | code_, times_half_pointer_size, |
| 5661 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5662 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5663 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5664 | __ bind(&exit_); |
| 5665 | } |
| 5666 | |
| 5667 | |
| 5668 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5669 | MacroAssembler* masm, |
| 5670 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5671 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5672 | |
| 5673 | __ bind(&slow_case_); |
| 5674 | call_helper.BeforeCall(masm); |
| 5675 | __ push(code_); |
| 5676 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5677 | if (!result_.is(eax)) { |
| 5678 | __ mov(result_, eax); |
| 5679 | } |
| 5680 | call_helper.AfterCall(masm); |
| 5681 | __ jmp(&exit_); |
| 5682 | |
| 5683 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5684 | } |
| 5685 | |
| 5686 | |
| 5687 | // ------------------------------------------------------------------------- |
| 5688 | // StringCharAtGenerator |
| 5689 | |
| 5690 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5691 | char_code_at_generator_.GenerateFast(masm); |
| 5692 | char_from_code_generator_.GenerateFast(masm); |
| 5693 | } |
| 5694 | |
| 5695 | |
| 5696 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5697 | MacroAssembler* masm, |
| 5698 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5699 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5700 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5701 | } |
| 5702 | |
| 5703 | |
| 5704 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5705 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5706 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5707 | |
| 5708 | // Load the two arguments. |
| 5709 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5710 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5711 | |
| 5712 | // 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] | 5713 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5714 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5715 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5716 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5717 | |
| 5718 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5719 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5720 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5721 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5722 | } else { |
| 5723 | // Here at least one of the arguments is definitely a string. |
| 5724 | // We convert the one that is not known to be a string. |
| 5725 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5726 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5727 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5728 | &call_builtin); |
| 5729 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5730 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5731 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5732 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5733 | &call_builtin); |
| 5734 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5735 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | // Both arguments are strings. |
| 5739 | // eax: first string |
| 5740 | // edx: second string |
| 5741 | // 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] | 5742 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5743 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5744 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5745 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5746 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5747 | // 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] | 5748 | Counters* counters = masm->isolate()->counters(); |
| 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 | __ bind(&second_not_zero_length); |
| 5752 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5753 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5754 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5755 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5756 | // First string is empty, result is second string which is in edx. |
| 5757 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5758 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5759 | __ ret(2 * kPointerSize); |
| 5760 | |
| 5761 | // Both strings are non-empty. |
| 5762 | // eax: first string |
| 5763 | // ebx: length of first string as a smi |
| 5764 | // ecx: length of second string as a smi |
| 5765 | // edx: second string |
| 5766 | // Look at the length of the result of adding the two strings. |
| 5767 | Label string_add_flat_result, longer_than_two; |
| 5768 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5769 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5770 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5771 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5772 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5773 | // Use the symbol table when adding two one character strings, as it |
| 5774 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5775 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5776 | __ j(not_equal, &longer_than_two); |
| 5777 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5778 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5779 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5780 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5781 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5782 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5783 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5784 | |
| 5785 | // Try to lookup two character string in symbol table. If it is not found |
| 5786 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5787 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5788 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5789 | masm, ebx, ecx, eax, edx, edi, |
| 5790 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5791 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5792 | __ ret(2 * kPointerSize); |
| 5793 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5794 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5795 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5796 | // Reload the arguments. |
| 5797 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5798 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5799 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5800 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5801 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5802 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5803 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5804 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5805 | // Pack both characters in ebx. |
| 5806 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5807 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5808 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5809 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5810 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5811 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5812 | |
| 5813 | __ bind(&longer_than_two); |
| 5814 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5815 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5816 | __ j(below, &string_add_flat_result); |
| 5817 | |
| 5818 | // 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] | 5819 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5820 | Label non_ascii, allocated, ascii_data; |
| 5821 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5822 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5823 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5824 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5825 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5826 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5827 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5828 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5829 | __ j(zero, &non_ascii); |
| 5830 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5831 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5832 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5833 | __ bind(&allocated); |
| 5834 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5835 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5837 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5838 | Immediate(String::kEmptyHashField)); |
| 5839 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5840 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5841 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5842 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5843 | __ ret(2 * kPointerSize); |
| 5844 | __ bind(&non_ascii); |
| 5845 | // 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] | 5846 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5847 | // ecx: first instance type AND second instance type. |
| 5848 | // edi: second instance type. |
| 5849 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5850 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5851 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5852 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5853 | __ xor_(edi, ecx); |
| 5854 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 5855 | __ and_(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5856 | __ cmp(edi, kOneByteStringTag | kAsciiDataHintTag); |
| 5857 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5858 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5859 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5860 | __ jmp(&allocated); |
| 5861 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5862 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5863 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5864 | // Handle creating a flat result from either external or sequential strings. |
| 5865 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5866 | // eax: first string |
| 5867 | // ebx: length of resulting flat string as a smi |
| 5868 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5869 | Label first_prepared, second_prepared; |
| 5870 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5871 | __ bind(&string_add_flat_result); |
| 5872 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5873 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5874 | // ecx: instance type of first string |
| 5875 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5876 | __ test_b(ecx, kStringRepresentationMask); |
| 5877 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5878 | // Rule out short external string and load string resource. |
| 5879 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5880 | __ test_b(ecx, kShortExternalStringMask); |
| 5881 | __ j(not_zero, &call_runtime); |
| 5882 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5883 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5884 | __ jmp(&first_prepared, Label::kNear); |
| 5885 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5886 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5887 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5888 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5889 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5890 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5891 | // Check whether both strings have same encoding. |
| 5892 | // edi: instance type of second string |
| 5893 | __ xor_(ecx, edi); |
| 5894 | __ test_b(ecx, kStringEncodingMask); |
| 5895 | __ j(not_zero, &call_runtime); |
| 5896 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5897 | __ test_b(edi, kStringRepresentationMask); |
| 5898 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5899 | // Rule out short external string and load string resource. |
| 5900 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5901 | __ test_b(edi, kShortExternalStringMask); |
| 5902 | __ j(not_zero, &call_runtime); |
| 5903 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5904 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5905 | __ jmp(&second_prepared, Label::kNear); |
| 5906 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5907 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5908 | __ bind(&second_prepared); |
| 5909 | |
| 5910 | // Push the addresses of both strings' first characters onto the stack. |
| 5911 | __ push(edx); |
| 5912 | __ push(eax); |
| 5913 | |
| 5914 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5915 | // edi: instance type of second string |
| 5916 | // First string and second string have the same encoding. |
| 5917 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5918 | __ test_b(edi, kStringEncodingMask); |
| 5919 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5920 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5921 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5922 | // ebx: length of resulting flat string as a smi |
| 5923 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5924 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5925 | // eax: result string |
| 5926 | __ mov(ecx, eax); |
| 5927 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5928 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5929 | // Load first argument's length and first character location. Account for |
| 5930 | // values currently on the stack when fetching arguments from it. |
| 5931 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5932 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5933 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5934 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5935 | // eax: result string |
| 5936 | // ecx: first character of result |
| 5937 | // edx: first char of first argument |
| 5938 | // edi: length of first argument |
| 5939 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5940 | // Load second argument's length and first character location. Account for |
| 5941 | // values currently on the stack when fetching arguments from it. |
| 5942 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5943 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5944 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5945 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5946 | // eax: result string |
| 5947 | // ecx: next character of result |
| 5948 | // edx: first char of second argument |
| 5949 | // edi: length of second argument |
| 5950 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5951 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5952 | __ ret(2 * kPointerSize); |
| 5953 | |
| 5954 | // Handle creating a flat two byte result. |
| 5955 | // eax: first string - known to be two byte |
| 5956 | // ebx: length of resulting flat string as a smi |
| 5957 | // edx: second string |
| 5958 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5959 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5960 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5961 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5962 | // eax: result string |
| 5963 | __ mov(ecx, eax); |
| 5964 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5965 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5966 | // Load second argument's length and first character location. Account for |
| 5967 | // values currently on the stack when fetching arguments from it. |
| 5968 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5969 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5970 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5971 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5972 | // eax: result string |
| 5973 | // ecx: first character of result |
| 5974 | // edx: first char of first argument |
| 5975 | // edi: length of first argument |
| 5976 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5977 | // Load second argument's length and first character location. Account for |
| 5978 | // values currently on the stack when fetching arguments from it. |
| 5979 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5980 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5981 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5982 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5983 | // eax: result string |
| 5984 | // ecx: next character of result |
| 5985 | // edx: first char of second argument |
| 5986 | // edi: length of second argument |
| 5987 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5988 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5989 | __ ret(2 * kPointerSize); |
| 5990 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5991 | // Recover stack pointer before jumping to runtime. |
| 5992 | __ bind(&call_runtime_drop_two); |
| 5993 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5994 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5995 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5996 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5997 | |
| 5998 | if (call_builtin.is_linked()) { |
| 5999 | __ bind(&call_builtin); |
| 6000 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | |
| 6005 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6006 | int stack_offset, |
| 6007 | Register arg, |
| 6008 | Register scratch1, |
| 6009 | Register scratch2, |
| 6010 | Register scratch3, |
| 6011 | Label* slow) { |
| 6012 | // First check if the argument is already a string. |
| 6013 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6014 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6015 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6016 | __ j(below, &done); |
| 6017 | |
| 6018 | // Check the number to string cache. |
| 6019 | Label not_cached; |
| 6020 | __ bind(¬_string); |
| 6021 | // Puts the cached result into scratch1. |
| 6022 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6023 | arg, |
| 6024 | scratch1, |
| 6025 | scratch2, |
| 6026 | scratch3, |
| 6027 | false, |
| 6028 | ¬_cached); |
| 6029 | __ mov(arg, scratch1); |
| 6030 | __ mov(Operand(esp, stack_offset), arg); |
| 6031 | __ jmp(&done); |
| 6032 | |
| 6033 | // Check if the argument is a safe string wrapper. |
| 6034 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6035 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6036 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6037 | __ j(not_equal, slow); |
| 6038 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6039 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6040 | __ j(zero, slow); |
| 6041 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6042 | __ mov(Operand(esp, stack_offset), arg); |
| 6043 | |
| 6044 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | |
| 6048 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6049 | Register dest, |
| 6050 | Register src, |
| 6051 | Register count, |
| 6052 | Register scratch, |
| 6053 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6054 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6055 | __ bind(&loop); |
| 6056 | // This loop just copies one character at a time, as it is only used for very |
| 6057 | // short strings. |
| 6058 | if (ascii) { |
| 6059 | __ mov_b(scratch, Operand(src, 0)); |
| 6060 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6061 | __ add(src, Immediate(1)); |
| 6062 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | } else { |
| 6064 | __ mov_w(scratch, Operand(src, 0)); |
| 6065 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6066 | __ add(src, Immediate(2)); |
| 6067 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6068 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6069 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6070 | __ j(not_zero, &loop); |
| 6071 | } |
| 6072 | |
| 6073 | |
| 6074 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6075 | Register dest, |
| 6076 | Register src, |
| 6077 | Register count, |
| 6078 | Register scratch, |
| 6079 | bool ascii) { |
| 6080 | // Copy characters using rep movs of doublewords. |
| 6081 | // The destination is aligned on a 4 byte boundary because we are |
| 6082 | // copying to the beginning of a newly allocated string. |
| 6083 | ASSERT(dest.is(edi)); // rep movs destination |
| 6084 | ASSERT(src.is(esi)); // rep movs source |
| 6085 | ASSERT(count.is(ecx)); // rep movs count |
| 6086 | ASSERT(!scratch.is(dest)); |
| 6087 | ASSERT(!scratch.is(src)); |
| 6088 | ASSERT(!scratch.is(count)); |
| 6089 | |
| 6090 | // Nothing to do for zero characters. |
| 6091 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6092 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6093 | __ j(zero, &done); |
| 6094 | |
| 6095 | // Make count the number of bytes to copy. |
| 6096 | if (!ascii) { |
| 6097 | __ shl(count, 1); |
| 6098 | } |
| 6099 | |
| 6100 | // 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] | 6101 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6102 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6103 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6104 | |
| 6105 | // Copy from edi to esi using rep movs instruction. |
| 6106 | __ mov(scratch, count); |
| 6107 | __ sar(count, 2); // Number of doublewords to copy. |
| 6108 | __ cld(); |
| 6109 | __ rep_movs(); |
| 6110 | |
| 6111 | // Find number of bytes left. |
| 6112 | __ mov(count, scratch); |
| 6113 | __ and_(count, 3); |
| 6114 | |
| 6115 | // Check if there are more bytes to copy. |
| 6116 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6117 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6118 | __ j(zero, &done); |
| 6119 | |
| 6120 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6121 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6122 | __ bind(&loop); |
| 6123 | __ mov_b(scratch, Operand(src, 0)); |
| 6124 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6125 | __ add(src, Immediate(1)); |
| 6126 | __ add(dest, Immediate(1)); |
| 6127 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6128 | __ j(not_zero, &loop); |
| 6129 | |
| 6130 | __ bind(&done); |
| 6131 | } |
| 6132 | |
| 6133 | |
| 6134 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 6135 | Register c1, |
| 6136 | Register c2, |
| 6137 | Register scratch1, |
| 6138 | Register scratch2, |
| 6139 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6140 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6141 | Label* not_found) { |
| 6142 | // Register scratch3 is the general scratch register in this function. |
| 6143 | Register scratch = scratch3; |
| 6144 | |
| 6145 | // Make sure that both characters are not digits as such strings has a |
| 6146 | // 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] | 6147 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6148 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6149 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6150 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6151 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6152 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6153 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6154 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6155 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6156 | |
| 6157 | __ bind(¬_array_index); |
| 6158 | // Calculate the two character string hash. |
| 6159 | Register hash = scratch1; |
| 6160 | GenerateHashInit(masm, hash, c1, scratch); |
| 6161 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6162 | GenerateHashGetHash(masm, hash, scratch); |
| 6163 | |
| 6164 | // Collect the two characters in a register. |
| 6165 | Register chars = c1; |
| 6166 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6167 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6168 | |
| 6169 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6170 | // hash: hash of two character string. |
| 6171 | |
| 6172 | // Load the symbol table. |
| 6173 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6174 | ExternalReference roots_array_start = |
| 6175 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6176 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 6177 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6178 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6179 | |
| 6180 | // Calculate capacity mask from the symbol table capacity. |
| 6181 | Register mask = scratch2; |
| 6182 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 6183 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6184 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6185 | |
| 6186 | // Registers |
| 6187 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6188 | // hash: hash of two character string |
| 6189 | // symbol_table: symbol table |
| 6190 | // mask: capacity mask |
| 6191 | // scratch: - |
| 6192 | |
| 6193 | // Perform a number of probes in the symbol table. |
| 6194 | static const int kProbes = 4; |
| 6195 | Label found_in_symbol_table; |
| 6196 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6197 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6198 | for (int i = 0; i < kProbes; i++) { |
| 6199 | // Calculate entry in symbol table. |
| 6200 | __ mov(scratch, hash); |
| 6201 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6202 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6203 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6204 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6205 | |
| 6206 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6207 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6208 | __ mov(candidate, |
| 6209 | FieldOperand(symbol_table, |
| 6210 | scratch, |
| 6211 | times_pointer_size, |
| 6212 | SymbolTable::kElementsStartOffset)); |
| 6213 | |
| 6214 | // 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] | 6215 | Factory* factory = masm->isolate()->factory(); |
| 6216 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6217 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6218 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6219 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6220 | |
| 6221 | // If length is not 2 the string is not a candidate. |
| 6222 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6223 | Immediate(Smi::FromInt(2))); |
| 6224 | __ j(not_equal, &next_probe[i]); |
| 6225 | |
| 6226 | // As we are out of registers save the mask on the stack and use that |
| 6227 | // register as a temporary. |
| 6228 | __ push(mask); |
| 6229 | Register temp = mask; |
| 6230 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6231 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6232 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6233 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6234 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6235 | temp, temp, &next_probe_pop_mask[i]); |
| 6236 | |
| 6237 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6238 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6239 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6240 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6241 | __ j(equal, &found_in_symbol_table); |
| 6242 | __ bind(&next_probe_pop_mask[i]); |
| 6243 | __ pop(mask); |
| 6244 | __ bind(&next_probe[i]); |
| 6245 | } |
| 6246 | |
| 6247 | // No matching 2 character string found by probing. |
| 6248 | __ jmp(not_found); |
| 6249 | |
| 6250 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6251 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6252 | __ bind(&found_in_symbol_table); |
| 6253 | __ pop(mask); // Pop saved mask from the stack. |
| 6254 | if (!result.is(eax)) { |
| 6255 | __ mov(eax, result); |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | |
| 6260 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6261 | Register hash, |
| 6262 | Register character, |
| 6263 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6264 | // hash = (seed + character) + ((seed + character) << 10); |
| 6265 | if (Serializer::enabled()) { |
| 6266 | ExternalReference roots_array_start = |
| 6267 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6268 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6269 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6270 | times_pointer_size, |
| 6271 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6272 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6273 | __ add(scratch, character); |
| 6274 | __ mov(hash, scratch); |
| 6275 | __ shl(scratch, 10); |
| 6276 | __ add(hash, scratch); |
| 6277 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6278 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6279 | __ lea(scratch, Operand(character, seed)); |
| 6280 | __ shl(scratch, 10); |
| 6281 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6282 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6283 | // hash ^= hash >> 6; |
| 6284 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6285 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6286 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | |
| 6290 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6291 | Register hash, |
| 6292 | Register character, |
| 6293 | Register scratch) { |
| 6294 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6295 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6296 | // hash += hash << 10; |
| 6297 | __ mov(scratch, hash); |
| 6298 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6299 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | // hash ^= hash >> 6; |
| 6301 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6302 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6303 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | |
| 6307 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6308 | Register hash, |
| 6309 | Register scratch) { |
| 6310 | // hash += hash << 3; |
| 6311 | __ mov(scratch, hash); |
| 6312 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6313 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6314 | // hash ^= hash >> 11; |
| 6315 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6316 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6317 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6318 | // hash += hash << 15; |
| 6319 | __ mov(scratch, hash); |
| 6320 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6321 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6322 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6323 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6324 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6325 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6326 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6327 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6328 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6329 | __ bind(&hash_not_zero); |
| 6330 | } |
| 6331 | |
| 6332 | |
| 6333 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6334 | Label runtime; |
| 6335 | |
| 6336 | // Stack frame on entry. |
| 6337 | // esp[0]: return address |
| 6338 | // esp[4]: to |
| 6339 | // esp[8]: from |
| 6340 | // esp[12]: string |
| 6341 | |
| 6342 | // Make sure first argument is a string. |
| 6343 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6344 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6345 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6346 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6347 | __ j(NegateCondition(is_string), &runtime); |
| 6348 | |
| 6349 | // eax: string |
| 6350 | // ebx: instance type |
| 6351 | |
| 6352 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6353 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6354 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6355 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6356 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6357 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6358 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6359 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6360 | // Shorter than original string's length: an actual substring. |
| 6361 | __ j(below, ¬_original_string, Label::kNear); |
| 6362 | // Longer than original string's length or negative: unsafe arguments. |
| 6363 | __ j(above, &runtime); |
| 6364 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6365 | Counters* counters = masm->isolate()->counters(); |
| 6366 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6367 | __ ret(3 * kPointerSize); |
| 6368 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6369 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6370 | // eax: string |
| 6371 | // ebx: instance type |
| 6372 | // ecx: sub string length (smi) |
| 6373 | // edx: from index (smi) |
| 6374 | // Deal with different string types: update the index if necessary |
| 6375 | // and put the underlying string into edi. |
| 6376 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6377 | // If the string is not indirect, it can only be sequential or external. |
| 6378 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6379 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6380 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6381 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6382 | |
| 6383 | Factory* factory = masm->isolate()->factory(); |
| 6384 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6385 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6386 | // Cons string. Check whether it is flat, then fetch first part. |
| 6387 | // Flat cons strings have an empty second part. |
| 6388 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6389 | factory->empty_string()); |
| 6390 | __ j(not_equal, &runtime); |
| 6391 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6392 | // Update instance type. |
| 6393 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6394 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6395 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6396 | |
| 6397 | __ bind(&sliced_string); |
| 6398 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6399 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6400 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6401 | // Update instance type. |
| 6402 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6403 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6404 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6405 | |
| 6406 | __ bind(&seq_or_external_string); |
| 6407 | // Sequential or external string. Just move string to the expected register. |
| 6408 | __ mov(edi, eax); |
| 6409 | |
| 6410 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6411 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6412 | if (FLAG_string_slices) { |
| 6413 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6414 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6415 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6416 | // edx: adjusted start index (smi) |
| 6417 | // ecx: length (smi) |
| 6418 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6419 | // Short slice. Copy instead of slicing. |
| 6420 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6421 | // Allocate new sliced string. At this point we do not reload the instance |
| 6422 | // type including the string encoding because we simply rely on the info |
| 6423 | // provided by the original string. It does not matter if the original |
| 6424 | // string's encoding is wrong because we always have to recheck encoding of |
| 6425 | // the newly created string's parent anyways due to externalized strings. |
| 6426 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6427 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6428 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6429 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6430 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6431 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6432 | __ jmp(&set_slice_header, Label::kNear); |
| 6433 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6434 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6435 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6436 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6437 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6438 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6439 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6440 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6441 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6442 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6443 | |
| 6444 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6447 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6448 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6449 | // edx: adjusted start index (smi) |
| 6450 | // ecx: length (smi) |
| 6451 | // The subject string can only be external or sequential string of either |
| 6452 | // encoding at this point. |
| 6453 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6454 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6455 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6456 | __ test_b(ebx, kExternalStringTag); |
| 6457 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6458 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6459 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6460 | // Rule out short external strings. |
| 6461 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6462 | __ test_b(ebx, kShortExternalStringMask); |
| 6463 | __ j(not_zero, &runtime); |
| 6464 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6465 | // 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] | 6466 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6467 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6468 | |
| 6469 | __ bind(&sequential_string); |
| 6470 | // Stash away (adjusted) index and (underlying) string. |
| 6471 | __ push(edx); |
| 6472 | __ push(edi); |
| 6473 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6474 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6475 | __ test_b(ebx, kStringEncodingMask); |
| 6476 | __ j(zero, &two_byte_sequential); |
| 6477 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6478 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6479 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6480 | |
| 6481 | // eax: result string |
| 6482 | // ecx: result string length |
| 6483 | __ mov(edx, esi); // esi used by following code. |
| 6484 | // Locate first character of result. |
| 6485 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6486 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6487 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6488 | __ pop(esi); |
| 6489 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6490 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6491 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6492 | |
| 6493 | // eax: result string |
| 6494 | // ecx: result length |
| 6495 | // edx: original value of esi |
| 6496 | // edi: first character of result |
| 6497 | // esi: character of sub string start |
| 6498 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6499 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6500 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6501 | __ ret(3 * kPointerSize); |
| 6502 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6503 | __ bind(&two_byte_sequential); |
| 6504 | // Sequential two-byte string. Allocate the result. |
| 6505 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6506 | |
| 6507 | // eax: result string |
| 6508 | // ecx: result string length |
| 6509 | __ mov(edx, esi); // esi used by following code. |
| 6510 | // Locate first character of result. |
| 6511 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6512 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6513 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6514 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6515 | __ pop(esi); |
| 6516 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6517 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6518 | // byte character. |
| 6519 | STATIC_ASSERT(kSmiTag == 0); |
| 6520 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6521 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6522 | |
| 6523 | // eax: result string |
| 6524 | // ecx: result length |
| 6525 | // edx: original value of esi |
| 6526 | // edi: first character of result |
| 6527 | // esi: character of sub string start |
| 6528 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6529 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6530 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6531 | __ ret(3 * kPointerSize); |
| 6532 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6533 | // Drop pushed values on the stack before tail call. |
| 6534 | __ bind(&runtime_drop_two); |
| 6535 | __ Drop(2); |
| 6536 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6537 | // Just jump to runtime to create the sub string. |
| 6538 | __ bind(&runtime); |
| 6539 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6540 | } |
| 6541 | |
| 6542 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6543 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6544 | Register left, |
| 6545 | Register right, |
| 6546 | Register scratch1, |
| 6547 | Register scratch2) { |
| 6548 | Register length = scratch1; |
| 6549 | |
| 6550 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6551 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6552 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6553 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6554 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6555 | __ bind(&strings_not_equal); |
| 6556 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6557 | __ ret(0); |
| 6558 | |
| 6559 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6560 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6561 | __ bind(&check_zero_length); |
| 6562 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6563 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6564 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6565 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6566 | __ ret(0); |
| 6567 | |
| 6568 | // Compare characters. |
| 6569 | __ bind(&compare_chars); |
| 6570 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6571 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6572 | |
| 6573 | // Characters are equal. |
| 6574 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6575 | __ ret(0); |
| 6576 | } |
| 6577 | |
| 6578 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6579 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6580 | Register left, |
| 6581 | Register right, |
| 6582 | Register scratch1, |
| 6583 | Register scratch2, |
| 6584 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6585 | Counters* counters = masm->isolate()->counters(); |
| 6586 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6587 | |
| 6588 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6589 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6590 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6591 | __ mov(scratch3, scratch1); |
| 6592 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6593 | |
| 6594 | Register length_delta = scratch3; |
| 6595 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6596 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6597 | // 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] | 6598 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6599 | __ bind(&left_shorter); |
| 6600 | |
| 6601 | Register min_length = scratch1; |
| 6602 | |
| 6603 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6604 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6605 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6606 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6607 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6608 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6609 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6610 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6611 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6612 | |
| 6613 | // Compare lengths - strings up to min-length are equal. |
| 6614 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6615 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6616 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6617 | __ j(not_zero, &result_not_equal, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6618 | #else |
| 6619 | Label length_not_equal; |
| 6620 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 6621 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6622 | |
| 6623 | // Result is EQUAL. |
| 6624 | STATIC_ASSERT(EQUAL == 0); |
| 6625 | STATIC_ASSERT(kSmiTag == 0); |
| 6626 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6627 | __ ret(0); |
| 6628 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6629 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6630 | #ifdef ENABLE_LATIN_1 |
| 6631 | Label result_less; |
| 6632 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6633 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6634 | __ jmp(&result_less, Label::kNear); |
| 6635 | #endif |
| 6636 | __ bind(&result_not_equal); |
| 6637 | #ifndef ENABLE_LATIN_1 |
| 6638 | __ j(greater, &result_greater, Label::kNear); |
| 6639 | #else |
| 6640 | __ j(above, &result_greater, Label::kNear); |
| 6641 | __ bind(&result_less); |
| 6642 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6643 | |
| 6644 | // Result is LESS. |
| 6645 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6646 | __ ret(0); |
| 6647 | |
| 6648 | // Result is GREATER. |
| 6649 | __ bind(&result_greater); |
| 6650 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6651 | __ ret(0); |
| 6652 | } |
| 6653 | |
| 6654 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6655 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6656 | MacroAssembler* masm, |
| 6657 | Register left, |
| 6658 | Register right, |
| 6659 | Register length, |
| 6660 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6661 | Label* chars_not_equal, |
| 6662 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6663 | // Change index to run from -length to -1 by adding length to string |
| 6664 | // start. This means that loop ends when index reaches zero, which |
| 6665 | // doesn't need an additional compare. |
| 6666 | __ SmiUntag(length); |
| 6667 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6668 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6669 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6670 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6671 | __ neg(length); |
| 6672 | Register index = length; // index = -length; |
| 6673 | |
| 6674 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6675 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6676 | __ bind(&loop); |
| 6677 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6678 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6679 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6680 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6681 | __ j(not_zero, &loop); |
| 6682 | } |
| 6683 | |
| 6684 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6685 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6686 | Label runtime; |
| 6687 | |
| 6688 | // Stack frame on entry. |
| 6689 | // esp[0]: return address |
| 6690 | // esp[4]: right string |
| 6691 | // esp[8]: left string |
| 6692 | |
| 6693 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6694 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6695 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6696 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6697 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6698 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6699 | STATIC_ASSERT(EQUAL == 0); |
| 6700 | STATIC_ASSERT(kSmiTag == 0); |
| 6701 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6702 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6703 | __ ret(2 * kPointerSize); |
| 6704 | |
| 6705 | __ bind(¬_same); |
| 6706 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6707 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6708 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6709 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6710 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6711 | // Drop arguments from the stack. |
| 6712 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6713 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6714 | __ push(ecx); |
| 6715 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6716 | |
| 6717 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6718 | // tagged as a small integer. |
| 6719 | __ bind(&runtime); |
| 6720 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6721 | } |
| 6722 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6723 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6724 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6725 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6726 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6727 | __ mov(ecx, edx); |
| 6728 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6729 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6730 | |
| 6731 | if (GetCondition() == equal) { |
| 6732 | // 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] | 6733 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6734 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6735 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6736 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6737 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6738 | // Correct sign of result in case of overflow. |
| 6739 | __ not_(edx); |
| 6740 | __ bind(&done); |
| 6741 | __ mov(eax, edx); |
| 6742 | } |
| 6743 | __ ret(0); |
| 6744 | |
| 6745 | __ bind(&miss); |
| 6746 | GenerateMiss(masm); |
| 6747 | } |
| 6748 | |
| 6749 | |
| 6750 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6751 | ASSERT(state_ == CompareIC::HEAP_NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6752 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6753 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6754 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6755 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6756 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6757 | if (left_ == CompareIC::SMI) { |
| 6758 | __ JumpIfNotSmi(edx, &miss); |
| 6759 | } |
| 6760 | if (right_ == CompareIC::SMI) { |
| 6761 | __ JumpIfNotSmi(eax, &miss); |
| 6762 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6763 | |
| 6764 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6765 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6766 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6767 | CpuFeatures::Scope scope1(SSE2); |
| 6768 | CpuFeatures::Scope scope2(CMOV); |
| 6769 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6770 | // Load left and right operand. |
| 6771 | Label done, left, left_smi, right_smi; |
| 6772 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6773 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6774 | masm->isolate()->factory()->heap_number_map()); |
| 6775 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6776 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6777 | __ jmp(&left, Label::kNear); |
| 6778 | __ bind(&right_smi); |
| 6779 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6780 | __ SmiUntag(ecx); |
| 6781 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6782 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6783 | __ bind(&left); |
| 6784 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6785 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6786 | masm->isolate()->factory()->heap_number_map()); |
| 6787 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6788 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6789 | __ jmp(&done); |
| 6790 | __ bind(&left_smi); |
| 6791 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6792 | __ SmiUntag(ecx); |
| 6793 | __ cvtsi2sd(xmm0, ecx); |
| 6794 | |
| 6795 | __ bind(&done); |
| 6796 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6797 | __ ucomisd(xmm0, xmm1); |
| 6798 | |
| 6799 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6800 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6801 | |
| 6802 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6803 | // Performing mov, because xor would destroy the flag register. |
| 6804 | __ mov(eax, 0); // equal |
| 6805 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6806 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6807 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6808 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6809 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6810 | } else { |
| 6811 | __ mov(ecx, edx); |
| 6812 | __ and_(ecx, eax); |
| 6813 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6814 | |
| 6815 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6816 | masm->isolate()->factory()->heap_number_map()); |
| 6817 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6818 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6819 | masm->isolate()->factory()->heap_number_map()); |
| 6820 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6821 | } |
| 6822 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6823 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6824 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6825 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6826 | CompareIC::GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6827 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6828 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6829 | __ bind(&maybe_undefined1); |
| 6830 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6831 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6832 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6833 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6834 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6835 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6836 | __ jmp(&unordered); |
| 6837 | } |
| 6838 | |
| 6839 | __ bind(&maybe_undefined2); |
| 6840 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6841 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6842 | __ j(equal, &unordered); |
| 6843 | } |
| 6844 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6845 | __ bind(&miss); |
| 6846 | GenerateMiss(masm); |
| 6847 | } |
| 6848 | |
| 6849 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6850 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6851 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6852 | ASSERT(GetCondition() == equal); |
| 6853 | |
| 6854 | // Registers containing left and right operands respectively. |
| 6855 | Register left = edx; |
| 6856 | Register right = eax; |
| 6857 | Register tmp1 = ecx; |
| 6858 | Register tmp2 = ebx; |
| 6859 | |
| 6860 | // Check that both operands are heap objects. |
| 6861 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6862 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6863 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6864 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6865 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6866 | |
| 6867 | // Check that both operands are symbols. |
| 6868 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6869 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6870 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6871 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6872 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6873 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6874 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6875 | __ j(zero, &miss, Label::kNear); |
| 6876 | |
| 6877 | // Symbols are compared by identity. |
| 6878 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6879 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6880 | // Make sure eax is non-zero. At this point input operands are |
| 6881 | // guaranteed to be non-zero. |
| 6882 | ASSERT(right.is(eax)); |
| 6883 | __ j(not_equal, &done, Label::kNear); |
| 6884 | STATIC_ASSERT(EQUAL == 0); |
| 6885 | STATIC_ASSERT(kSmiTag == 0); |
| 6886 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6887 | __ bind(&done); |
| 6888 | __ ret(0); |
| 6889 | |
| 6890 | __ bind(&miss); |
| 6891 | GenerateMiss(masm); |
| 6892 | } |
| 6893 | |
| 6894 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6895 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6896 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6897 | Label miss; |
| 6898 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6899 | bool equality = Token::IsEqualityOp(op_); |
| 6900 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6901 | // Registers containing left and right operands respectively. |
| 6902 | Register left = edx; |
| 6903 | Register right = eax; |
| 6904 | Register tmp1 = ecx; |
| 6905 | Register tmp2 = ebx; |
| 6906 | Register tmp3 = edi; |
| 6907 | |
| 6908 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6909 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6910 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6911 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6912 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6913 | |
| 6914 | // Check that both operands are strings. This leaves the instance |
| 6915 | // types loaded in tmp1 and tmp2. |
| 6916 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6917 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6918 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6919 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6920 | __ mov(tmp3, tmp1); |
| 6921 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6922 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6923 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6924 | __ j(not_zero, &miss); |
| 6925 | |
| 6926 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6927 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6928 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6929 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6930 | STATIC_ASSERT(EQUAL == 0); |
| 6931 | STATIC_ASSERT(kSmiTag == 0); |
| 6932 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6933 | __ ret(0); |
| 6934 | |
| 6935 | // Handle not identical strings. |
| 6936 | __ bind(¬_same); |
| 6937 | |
| 6938 | // 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] | 6939 | // because we already know they are not identical. But in the case of |
| 6940 | // non-equality compare, we still need to determine the order. |
| 6941 | if (equality) { |
| 6942 | Label do_compare; |
| 6943 | STATIC_ASSERT(kSymbolTag != 0); |
| 6944 | __ and_(tmp1, tmp2); |
| 6945 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6946 | __ j(zero, &do_compare, Label::kNear); |
| 6947 | // Make sure eax is non-zero. At this point input operands are |
| 6948 | // guaranteed to be non-zero. |
| 6949 | ASSERT(right.is(eax)); |
| 6950 | __ ret(0); |
| 6951 | __ bind(&do_compare); |
| 6952 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6953 | |
| 6954 | // Check that both strings are sequential ASCII. |
| 6955 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6956 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6957 | |
| 6958 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6959 | if (equality) { |
| 6960 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6961 | masm, left, right, tmp1, tmp2); |
| 6962 | } else { |
| 6963 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6964 | masm, left, right, tmp1, tmp2, tmp3); |
| 6965 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6966 | |
| 6967 | // Handle more complex cases in runtime. |
| 6968 | __ bind(&runtime); |
| 6969 | __ pop(tmp1); // Return address. |
| 6970 | __ push(left); |
| 6971 | __ push(right); |
| 6972 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6973 | if (equality) { |
| 6974 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6975 | } else { |
| 6976 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6977 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6978 | |
| 6979 | __ bind(&miss); |
| 6980 | GenerateMiss(masm); |
| 6981 | } |
| 6982 | |
| 6983 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6984 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6985 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6986 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6987 | __ mov(ecx, edx); |
| 6988 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6989 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6990 | |
| 6991 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6992 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6993 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6994 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6995 | |
| 6996 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6997 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6998 | __ ret(0); |
| 6999 | |
| 7000 | __ bind(&miss); |
| 7001 | GenerateMiss(masm); |
| 7002 | } |
| 7003 | |
| 7004 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7005 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7006 | Label miss; |
| 7007 | __ mov(ecx, edx); |
| 7008 | __ and_(ecx, eax); |
| 7009 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7010 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7011 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7012 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7013 | __ cmp(ecx, known_map_); |
| 7014 | __ j(not_equal, &miss, Label::kNear); |
| 7015 | __ cmp(ebx, known_map_); |
| 7016 | __ j(not_equal, &miss, Label::kNear); |
| 7017 | |
| 7018 | __ sub(eax, edx); |
| 7019 | __ ret(0); |
| 7020 | |
| 7021 | __ bind(&miss); |
| 7022 | GenerateMiss(masm); |
| 7023 | } |
| 7024 | |
| 7025 | |
| 7026 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7027 | { |
| 7028 | // Call the runtime system in a fresh internal frame. |
| 7029 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7030 | masm->isolate()); |
| 7031 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7032 | __ push(edx); // Preserve edx and eax. |
| 7033 | __ push(eax); |
| 7034 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7035 | __ push(eax); |
| 7036 | __ push(Immediate(Smi::FromInt(op_))); |
| 7037 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7038 | // Compute the entry point of the rewritten stub. |
| 7039 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7040 | __ pop(eax); |
| 7041 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7042 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7043 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7044 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7045 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7049 | // Helper function used to check that the dictionary doesn't contain |
| 7050 | // the property. This function may return false negatives, so miss_label |
| 7051 | // must always call a backup property check that is complete. |
| 7052 | // This function is safe to call if the receiver has fast properties. |
| 7053 | // 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] | 7054 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7055 | Label* miss, |
| 7056 | Label* done, |
| 7057 | Register properties, |
| 7058 | Handle<String> name, |
| 7059 | Register r0) { |
| 7060 | ASSERT(name->IsSymbol()); |
| 7061 | |
| 7062 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7063 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7064 | // undefined value), it guarantees the hash table doesn't contain the |
| 7065 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7066 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7067 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7068 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7069 | Register index = r0; |
| 7070 | // Capacity is smi 2^n. |
| 7071 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7072 | __ dec(index); |
| 7073 | __ and_(index, |
| 7074 | Immediate(Smi::FromInt(name->Hash() + |
| 7075 | StringDictionary::GetProbeOffset(i)))); |
| 7076 | |
| 7077 | // Scale the index by multiplying by the entry size. |
| 7078 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7079 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7080 | Register entity_name = r0; |
| 7081 | // Having undefined at this place means the name is not contained. |
| 7082 | ASSERT_EQ(kSmiTagSize, 1); |
| 7083 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7084 | kElementsStartOffset - kHeapObjectTag)); |
| 7085 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7086 | __ j(equal, done); |
| 7087 | |
| 7088 | // Stop if found the property. |
| 7089 | __ cmp(entity_name, Handle<String>(name)); |
| 7090 | __ j(equal, miss); |
| 7091 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7092 | Label the_hole; |
| 7093 | // Check for the hole and skip. |
| 7094 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 7095 | __ j(equal, &the_hole, Label::kNear); |
| 7096 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7097 | // Check if the entry name is not a symbol. |
| 7098 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7099 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7100 | kIsSymbolMask); |
| 7101 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7102 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | StringDictionaryLookupStub stub(properties, |
| 7106 | r0, |
| 7107 | r0, |
| 7108 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 7109 | __ push(Immediate(Handle<Object>(name))); |
| 7110 | __ push(Immediate(name->Hash())); |
| 7111 | __ CallStub(&stub); |
| 7112 | __ test(r0, r0); |
| 7113 | __ j(not_zero, miss); |
| 7114 | __ jmp(done); |
| 7115 | } |
| 7116 | |
| 7117 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7118 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7119 | // |done| label if a property with the given name is found leaving the |
| 7120 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7121 | // otherwise. |
| 7122 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7123 | Label* miss, |
| 7124 | Label* done, |
| 7125 | Register elements, |
| 7126 | Register name, |
| 7127 | Register r0, |
| 7128 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7129 | ASSERT(!elements.is(r0)); |
| 7130 | ASSERT(!elements.is(r1)); |
| 7131 | ASSERT(!name.is(r0)); |
| 7132 | ASSERT(!name.is(r1)); |
| 7133 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7134 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7135 | |
| 7136 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7137 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7138 | __ dec(r1); |
| 7139 | |
| 7140 | // Generate an unrolled loop that performs a few probes before |
| 7141 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7142 | // cover ~93% of loads from dictionaries. |
| 7143 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7144 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7145 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7146 | __ shr(r0, String::kHashShift); |
| 7147 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7148 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7149 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7150 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7151 | |
| 7152 | // Scale the index by multiplying by the entry size. |
| 7153 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7154 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7155 | |
| 7156 | // Check if the key is identical to the name. |
| 7157 | __ cmp(name, Operand(elements, |
| 7158 | r0, |
| 7159 | times_4, |
| 7160 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7161 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | StringDictionaryLookupStub stub(elements, |
| 7165 | r1, |
| 7166 | r0, |
| 7167 | POSITIVE_LOOKUP); |
| 7168 | __ push(name); |
| 7169 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7170 | __ shr(r0, String::kHashShift); |
| 7171 | __ push(r0); |
| 7172 | __ CallStub(&stub); |
| 7173 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7174 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7175 | __ j(zero, miss); |
| 7176 | __ jmp(done); |
| 7177 | } |
| 7178 | |
| 7179 | |
| 7180 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7181 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7182 | // 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] | 7183 | // Stack frame on entry: |
| 7184 | // esp[0 * kPointerSize]: return address. |
| 7185 | // esp[1 * kPointerSize]: key's hash. |
| 7186 | // esp[2 * kPointerSize]: key. |
| 7187 | // Registers: |
| 7188 | // dictionary_: StringDictionary to probe. |
| 7189 | // result_: used as scratch. |
| 7190 | // index_: will hold an index of entry if lookup is successful. |
| 7191 | // might alias with result_. |
| 7192 | // Returns: |
| 7193 | // result_ is zero if lookup failed, non zero otherwise. |
| 7194 | |
| 7195 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7196 | |
| 7197 | Register scratch = result_; |
| 7198 | |
| 7199 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7200 | __ dec(scratch); |
| 7201 | __ SmiUntag(scratch); |
| 7202 | __ push(scratch); |
| 7203 | |
| 7204 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7205 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7206 | // undefined value), it guarantees the hash table doesn't contain the |
| 7207 | // property. It's true even if some slots represent deleted properties |
| 7208 | // (their names are the null value). |
| 7209 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7210 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7211 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7212 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7213 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7214 | } |
| 7215 | __ and_(scratch, Operand(esp, 0)); |
| 7216 | |
| 7217 | // Scale the index by multiplying by the entry size. |
| 7218 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7219 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7220 | |
| 7221 | // Having undefined at this place means the name is not contained. |
| 7222 | ASSERT_EQ(kSmiTagSize, 1); |
| 7223 | __ mov(scratch, Operand(dictionary_, |
| 7224 | index_, |
| 7225 | times_pointer_size, |
| 7226 | kElementsStartOffset - kHeapObjectTag)); |
| 7227 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7228 | __ j(equal, ¬_in_dictionary); |
| 7229 | |
| 7230 | // Stop if found the property. |
| 7231 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7232 | __ j(equal, &in_dictionary); |
| 7233 | |
| 7234 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7235 | // If we hit a non symbol key during negative lookup |
| 7236 | // we have to bailout as this key might be equal to the |
| 7237 | // key we are looking for. |
| 7238 | |
| 7239 | // Check if the entry name is not a symbol. |
| 7240 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7241 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7242 | kIsSymbolMask); |
| 7243 | __ j(zero, &maybe_in_dictionary); |
| 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | __ bind(&maybe_in_dictionary); |
| 7248 | // If we are doing negative lookup then probing failure should be |
| 7249 | // treated as a lookup success. For positive lookup probing failure |
| 7250 | // should be treated as lookup failure. |
| 7251 | if (mode_ == POSITIVE_LOOKUP) { |
| 7252 | __ mov(result_, Immediate(0)); |
| 7253 | __ Drop(1); |
| 7254 | __ ret(2 * kPointerSize); |
| 7255 | } |
| 7256 | |
| 7257 | __ bind(&in_dictionary); |
| 7258 | __ mov(result_, Immediate(1)); |
| 7259 | __ Drop(1); |
| 7260 | __ ret(2 * kPointerSize); |
| 7261 | |
| 7262 | __ bind(¬_in_dictionary); |
| 7263 | __ mov(result_, Immediate(0)); |
| 7264 | __ Drop(1); |
| 7265 | __ ret(2 * kPointerSize); |
| 7266 | } |
| 7267 | |
| 7268 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7269 | struct AheadOfTimeWriteBarrierStubList { |
| 7270 | Register object, value, address; |
| 7271 | RememberedSetAction action; |
| 7272 | }; |
| 7273 | |
| 7274 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7275 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7276 | |
| 7277 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7278 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7279 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7280 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7281 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7282 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7283 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7284 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7285 | // Used in StoreStubCompiler::CompileStoreField and |
| 7286 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7287 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7288 | // GenerateStoreField calls the stub with two different permutations of |
| 7289 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7290 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7291 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7292 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7293 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7294 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7295 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7296 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7297 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7298 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7299 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7300 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7301 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7302 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7303 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7304 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7305 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7306 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7307 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7308 | // FastNewClosureStub |
| 7309 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7310 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7311 | { 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] | 7312 | }; |
| 7313 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7314 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7315 | |
| 7316 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7317 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7318 | !entry->object.is(no_reg); |
| 7319 | entry++) { |
| 7320 | if (object_.is(entry->object) && |
| 7321 | value_.is(entry->value) && |
| 7322 | address_.is(entry->address) && |
| 7323 | remembered_set_action_ == entry->action && |
| 7324 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7325 | return true; |
| 7326 | } |
| 7327 | } |
| 7328 | return false; |
| 7329 | } |
| 7330 | |
| 7331 | |
| 7332 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7333 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7334 | stub1.GetCode()->set_is_pregenerated(true); |
| 7335 | |
| 7336 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7337 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7338 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7339 | stub2.GetCode()->set_is_pregenerated(true); |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | |
| 7344 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7345 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7346 | !entry->object.is(no_reg); |
| 7347 | entry++) { |
| 7348 | RecordWriteStub stub(entry->object, |
| 7349 | entry->value, |
| 7350 | entry->address, |
| 7351 | entry->action, |
| 7352 | kDontSaveFPRegs); |
| 7353 | stub.GetCode()->set_is_pregenerated(true); |
| 7354 | } |
| 7355 | } |
| 7356 | |
| 7357 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7358 | bool CodeStub::CanUseFPRegisters() { |
| 7359 | return CpuFeatures::IsSupported(SSE2); |
| 7360 | } |
| 7361 | |
| 7362 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7363 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7364 | // the value has just been written into the object, now this stub makes sure |
| 7365 | // we keep the GC informed. The word in the object where the value has been |
| 7366 | // written is in the address register. |
| 7367 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7368 | Label skip_to_incremental_noncompacting; |
| 7369 | Label skip_to_incremental_compacting; |
| 7370 | |
| 7371 | // The first two instructions are generated with labels so as to get the |
| 7372 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7373 | // forth between a compare instructions (a nop in this position) and the |
| 7374 | // real branch when we start and stop incremental heap marking. |
| 7375 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7376 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7377 | |
| 7378 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7379 | __ RememberedSetHelper(object_, |
| 7380 | address_, |
| 7381 | value_, |
| 7382 | save_fp_regs_mode_, |
| 7383 | MacroAssembler::kReturnAtEnd); |
| 7384 | } else { |
| 7385 | __ ret(0); |
| 7386 | } |
| 7387 | |
| 7388 | __ bind(&skip_to_incremental_noncompacting); |
| 7389 | GenerateIncremental(masm, INCREMENTAL); |
| 7390 | |
| 7391 | __ bind(&skip_to_incremental_compacting); |
| 7392 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7393 | |
| 7394 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7395 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7396 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7397 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7398 | } |
| 7399 | |
| 7400 | |
| 7401 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7402 | regs_.Save(masm); |
| 7403 | |
| 7404 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7405 | Label dont_need_remembered_set; |
| 7406 | |
| 7407 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7408 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7409 | regs_.scratch0(), |
| 7410 | &dont_need_remembered_set); |
| 7411 | |
| 7412 | __ CheckPageFlag(regs_.object(), |
| 7413 | regs_.scratch0(), |
| 7414 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7415 | not_zero, |
| 7416 | &dont_need_remembered_set); |
| 7417 | |
| 7418 | // First notify the incremental marker if necessary, then update the |
| 7419 | // remembered set. |
| 7420 | CheckNeedsToInformIncrementalMarker( |
| 7421 | masm, |
| 7422 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7423 | mode); |
| 7424 | InformIncrementalMarker(masm, mode); |
| 7425 | regs_.Restore(masm); |
| 7426 | __ RememberedSetHelper(object_, |
| 7427 | address_, |
| 7428 | value_, |
| 7429 | save_fp_regs_mode_, |
| 7430 | MacroAssembler::kReturnAtEnd); |
| 7431 | |
| 7432 | __ bind(&dont_need_remembered_set); |
| 7433 | } |
| 7434 | |
| 7435 | CheckNeedsToInformIncrementalMarker( |
| 7436 | masm, |
| 7437 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7438 | mode); |
| 7439 | InformIncrementalMarker(masm, mode); |
| 7440 | regs_.Restore(masm); |
| 7441 | __ ret(0); |
| 7442 | } |
| 7443 | |
| 7444 | |
| 7445 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7446 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7447 | int argument_count = 3; |
| 7448 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7449 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7450 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7451 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7452 | Immediate(ExternalReference::isolate_address())); |
| 7453 | |
| 7454 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7455 | if (mode == INCREMENTAL_COMPACTION) { |
| 7456 | __ CallCFunction( |
| 7457 | ExternalReference::incremental_evacuation_record_write_function( |
| 7458 | masm->isolate()), |
| 7459 | argument_count); |
| 7460 | } else { |
| 7461 | ASSERT(mode == INCREMENTAL); |
| 7462 | __ CallCFunction( |
| 7463 | ExternalReference::incremental_marking_record_write_function( |
| 7464 | masm->isolate()), |
| 7465 | argument_count); |
| 7466 | } |
| 7467 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7468 | } |
| 7469 | |
| 7470 | |
| 7471 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7472 | MacroAssembler* masm, |
| 7473 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7474 | Mode mode) { |
| 7475 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7476 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7477 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7478 | __ and_(regs_.scratch0(), regs_.object()); |
| 7479 | __ mov(regs_.scratch1(), |
| 7480 | Operand(regs_.scratch0(), |
| 7481 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7482 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7483 | __ mov(Operand(regs_.scratch0(), |
| 7484 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7485 | regs_.scratch1()); |
| 7486 | __ j(negative, &need_incremental); |
| 7487 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7488 | // Let's look at the color of the object: If it is not black we don't have |
| 7489 | // to inform the incremental marker. |
| 7490 | __ JumpIfBlack(regs_.object(), |
| 7491 | regs_.scratch0(), |
| 7492 | regs_.scratch1(), |
| 7493 | &object_is_black, |
| 7494 | Label::kNear); |
| 7495 | |
| 7496 | regs_.Restore(masm); |
| 7497 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7498 | __ RememberedSetHelper(object_, |
| 7499 | address_, |
| 7500 | value_, |
| 7501 | save_fp_regs_mode_, |
| 7502 | MacroAssembler::kReturnAtEnd); |
| 7503 | } else { |
| 7504 | __ ret(0); |
| 7505 | } |
| 7506 | |
| 7507 | __ bind(&object_is_black); |
| 7508 | |
| 7509 | // Get the value from the slot. |
| 7510 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7511 | |
| 7512 | if (mode == INCREMENTAL_COMPACTION) { |
| 7513 | Label ensure_not_white; |
| 7514 | |
| 7515 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7516 | regs_.scratch1(), // Scratch. |
| 7517 | MemoryChunk::kEvacuationCandidateMask, |
| 7518 | zero, |
| 7519 | &ensure_not_white, |
| 7520 | Label::kNear); |
| 7521 | |
| 7522 | __ CheckPageFlag(regs_.object(), |
| 7523 | regs_.scratch1(), // Scratch. |
| 7524 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7525 | not_zero, |
| 7526 | &ensure_not_white, |
| 7527 | Label::kNear); |
| 7528 | |
| 7529 | __ jmp(&need_incremental); |
| 7530 | |
| 7531 | __ bind(&ensure_not_white); |
| 7532 | } |
| 7533 | |
| 7534 | // We need an extra register for this, so we push the object register |
| 7535 | // temporarily. |
| 7536 | __ push(regs_.object()); |
| 7537 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7538 | regs_.scratch1(), // Scratch. |
| 7539 | regs_.object(), // Scratch. |
| 7540 | &need_incremental_pop_object, |
| 7541 | Label::kNear); |
| 7542 | __ pop(regs_.object()); |
| 7543 | |
| 7544 | regs_.Restore(masm); |
| 7545 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7546 | __ RememberedSetHelper(object_, |
| 7547 | address_, |
| 7548 | value_, |
| 7549 | save_fp_regs_mode_, |
| 7550 | MacroAssembler::kReturnAtEnd); |
| 7551 | } else { |
| 7552 | __ ret(0); |
| 7553 | } |
| 7554 | |
| 7555 | __ bind(&need_incremental_pop_object); |
| 7556 | __ pop(regs_.object()); |
| 7557 | |
| 7558 | __ bind(&need_incremental); |
| 7559 | |
| 7560 | // Fall through when we need to inform the incremental marker. |
| 7561 | } |
| 7562 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7563 | |
| 7564 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7565 | // ----------- S t a t e ------------- |
| 7566 | // -- eax : element value to store |
| 7567 | // -- ebx : array literal |
| 7568 | // -- edi : map of array literal |
| 7569 | // -- ecx : element index as smi |
| 7570 | // -- edx : array literal index in function |
| 7571 | // -- esp[0] : return address |
| 7572 | // ----------------------------------- |
| 7573 | |
| 7574 | Label element_done; |
| 7575 | Label double_elements; |
| 7576 | Label smi_element; |
| 7577 | Label slow_elements; |
| 7578 | Label slow_elements_from_double; |
| 7579 | Label fast_elements; |
| 7580 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7581 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7582 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7583 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7584 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7585 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7586 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7587 | // Store into the array literal requires a elements transition. Call into |
| 7588 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7589 | |
| 7590 | __ bind(&slow_elements); |
| 7591 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7592 | // call. |
| 7593 | __ push(ebx); |
| 7594 | __ push(ecx); |
| 7595 | __ push(eax); |
| 7596 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7597 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7598 | __ push(edx); |
| 7599 | __ push(edi); // Return return address so that tail call returns to right |
| 7600 | // place. |
| 7601 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7602 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7603 | __ bind(&slow_elements_from_double); |
| 7604 | __ pop(edx); |
| 7605 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7606 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7607 | // 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] | 7608 | __ bind(&fast_elements); |
| 7609 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7610 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7611 | FixedArrayBase::kHeaderSize)); |
| 7612 | __ mov(Operand(ecx, 0), eax); |
| 7613 | // Update the write barrier for the array store. |
| 7614 | __ RecordWrite(ebx, ecx, eax, |
| 7615 | kDontSaveFPRegs, |
| 7616 | EMIT_REMEMBERED_SET, |
| 7617 | OMIT_SMI_CHECK); |
| 7618 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7619 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7620 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7621 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7622 | __ bind(&smi_element); |
| 7623 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7624 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7625 | FixedArrayBase::kHeaderSize), eax); |
| 7626 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7627 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7628 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7629 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7630 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7631 | __ push(edx); |
| 7632 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7633 | __ StoreNumberToDoubleElements(eax, |
| 7634 | edx, |
| 7635 | ecx, |
| 7636 | edi, |
| 7637 | xmm0, |
| 7638 | &slow_elements_from_double, |
| 7639 | false); |
| 7640 | __ pop(edx); |
| 7641 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7642 | } |
| 7643 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7644 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7645 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7646 | ASSERT(!Serializer::enabled()); |
| 7647 | bool save_fp_regs = CpuFeatures::IsSupported(SSE2); |
| 7648 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
| 7649 | __ call(ces.GetCode(), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame^] | 7650 | int parameter_count_offset = |
| 7651 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7652 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7653 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame^] | 7654 | __ pop(ecx); |
| 7655 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, |
| 7656 | extra_expression_stack_count_ * kPointerSize)); |
| 7657 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7661 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7662 | if (entry_hook_ != NULL) { |
| 7663 | ProfileEntryHookStub stub; |
| 7664 | masm->CallStub(&stub); |
| 7665 | } |
| 7666 | } |
| 7667 | |
| 7668 | |
| 7669 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7670 | // Ecx is the only volatile register we must save. |
| 7671 | __ push(ecx); |
| 7672 | |
| 7673 | // Calculate and push the original stack pointer. |
| 7674 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7675 | __ push(eax); |
| 7676 | |
| 7677 | // Calculate and push the function address. |
| 7678 | __ mov(eax, Operand(eax, 0)); |
| 7679 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7680 | __ push(eax); |
| 7681 | |
| 7682 | // Call the entry hook. |
| 7683 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7684 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7685 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7686 | |
| 7687 | // Restore ecx. |
| 7688 | __ pop(ecx); |
| 7689 | __ ret(0); |
| 7690 | } |
| 7691 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7692 | #undef __ |
| 7693 | |
| 7694 | } } // namespace v8::internal |
| 7695 | |
| 7696 | #endif // V8_TARGET_ARCH_IA32 |