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" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 37 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 38 | #include "codegen.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 44 | |
| 45 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 46 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 47 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 48 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 49 | __ ret(0); |
| 50 | |
| 51 | __ bind(&check_heap_number); |
| 52 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 53 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 54 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 55 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 56 | __ ret(0); |
| 57 | |
| 58 | __ bind(&call_builtin); |
| 59 | __ pop(ecx); // Pop return address. |
| 60 | __ push(eax); |
| 61 | __ push(ecx); // Push return address. |
| 62 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 63 | } |
| 64 | |
| 65 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 66 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 67 | // Create a new closure from the given function info in new |
| 68 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 69 | Counters* counters = masm->isolate()->counters(); |
| 70 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 71 | Label gc; |
| 72 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 73 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 74 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 75 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 76 | // Get the function info from the stack. |
| 77 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 78 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 79 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 80 | ? Context::FUNCTION_MAP_INDEX |
| 81 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 83 | // 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] | 84 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 85 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 86 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 87 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 88 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 89 | |
| 90 | // Initialize the rest of the function. We don't have to update the |
| 91 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 92 | Factory* factory = masm->isolate()->factory(); |
| 93 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 94 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 95 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 96 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 97 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 98 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 99 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 100 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 101 | |
| 102 | // Initialize the code pointer in the function to be the one |
| 103 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 104 | // But first check if there is an optimized version for our context. |
| 105 | Label check_optimized; |
| 106 | Label install_unoptimized; |
| 107 | if (FLAG_cache_optimized_code) { |
| 108 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 109 | __ test(ebx, ebx); |
| 110 | __ j(not_zero, &check_optimized, Label::kNear); |
| 111 | } |
| 112 | __ bind(&install_unoptimized); |
| 113 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 114 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 115 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 116 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 117 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 118 | |
| 119 | // Return and remove the on-stack parameter. |
| 120 | __ ret(1 * kPointerSize); |
| 121 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 122 | __ bind(&check_optimized); |
| 123 | |
| 124 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 125 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 126 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 127 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 128 | // Map must never be empty, so check the first elements. |
| 129 | Label install_optimized; |
| 130 | // Speculatively move code object into edx. |
| 131 | __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); |
| 132 | __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 133 | __ j(equal, &install_optimized); |
| 134 | |
| 135 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 136 | Label loop; |
| 137 | Label restore; |
| 138 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 139 | __ bind(&loop); |
| 140 | // Do not double check first entry. |
| 141 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 142 | __ j(equal, &restore); |
| 143 | __ sub(edx, Immediate(Smi::FromInt( |
| 144 | SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 145 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 146 | __ j(not_equal, &loop, Label::kNear); |
| 147 | // Hit: fetch the optimized code. |
| 148 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 149 | |
| 150 | __ bind(&install_optimized); |
| 151 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 152 | |
| 153 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 154 | // map and either unmangle them on marking or do nothing as the whole map is |
| 155 | // discarded on major GC anyway. |
| 156 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 157 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 158 | |
| 159 | // Now link a function into a list of optimized functions. |
| 160 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 161 | |
| 162 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 163 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 164 | |
| 165 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 166 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 167 | // it clobbers all the registers passed. |
| 168 | __ mov(edx, eax); |
| 169 | __ RecordWriteContextSlot( |
| 170 | ecx, |
| 171 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 172 | edx, |
| 173 | ebx, |
| 174 | kDontSaveFPRegs); |
| 175 | |
| 176 | // Return and remove the on-stack parameter. |
| 177 | __ ret(1 * kPointerSize); |
| 178 | |
| 179 | __ bind(&restore); |
| 180 | // Restore SharedFunctionInfo into edx. |
| 181 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 182 | __ jmp(&install_unoptimized); |
| 183 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 184 | // Create a new closure through the slower runtime call. |
| 185 | __ bind(&gc); |
| 186 | __ pop(ecx); // Temporarily remove return address. |
| 187 | __ pop(edx); |
| 188 | __ push(esi); |
| 189 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 190 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 191 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 192 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 197 | // Try to allocate the context in new space. |
| 198 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 199 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 200 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 201 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 202 | |
| 203 | // Get the function from the stack. |
| 204 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 205 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 206 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 207 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 208 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 209 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 210 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 211 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 212 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 213 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 214 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 215 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 216 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 217 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 218 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 219 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 220 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 221 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 222 | |
| 223 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 224 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 225 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 226 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 227 | } |
| 228 | |
| 229 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 230 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 231 | __ ret(1 * kPointerSize); |
| 232 | |
| 233 | // Need to collect. Call into runtime system. |
| 234 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 235 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 239 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 240 | // Stack layout on entry: |
| 241 | // |
| 242 | // [esp + (1 * kPointerSize)]: function |
| 243 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 244 | |
| 245 | // Try to allocate the context in new space. |
| 246 | Label gc; |
| 247 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 248 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 249 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 250 | |
| 251 | // Get the function or sentinel from the stack. |
| 252 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 253 | |
| 254 | // Get the serialized scope info from the stack. |
| 255 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 256 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 257 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 258 | Factory* factory = masm->isolate()->factory(); |
| 259 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 260 | factory->block_context_map()); |
| 261 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 262 | Immediate(Smi::FromInt(length))); |
| 263 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 264 | // 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] | 265 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 266 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 267 | // we still have to look up. |
| 268 | Label after_sentinel; |
| 269 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 270 | if (FLAG_debug_code) { |
| 271 | const char* message = "Expected 0 as a Smi sentinel"; |
| 272 | __ cmp(ecx, 0); |
| 273 | __ Assert(equal, message); |
| 274 | } |
| 275 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 276 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 277 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 278 | __ bind(&after_sentinel); |
| 279 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 280 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 281 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 282 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 283 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 284 | |
| 285 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 286 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 287 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 288 | |
| 289 | // Initialize the rest of the slots to the hole value. |
| 290 | if (slots_ == 1) { |
| 291 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 292 | factory->the_hole_value()); |
| 293 | } else { |
| 294 | __ mov(ebx, factory->the_hole_value()); |
| 295 | for (int i = 0; i < slots_; i++) { |
| 296 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // Return and remove the on-stack parameters. |
| 301 | __ mov(esi, eax); |
| 302 | __ ret(2 * kPointerSize); |
| 303 | |
| 304 | // Need to collect. Call into runtime system. |
| 305 | __ bind(&gc); |
| 306 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 307 | } |
| 308 | |
| 309 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 310 | static void GenerateFastCloneShallowArrayCommon( |
| 311 | MacroAssembler* masm, |
| 312 | int length, |
| 313 | FastCloneShallowArrayStub::Mode mode, |
| 314 | Label* fail) { |
| 315 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 316 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 317 | // ecx: boilerplate literal array. |
| 318 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 319 | |
| 320 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 321 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 322 | if (length > 0) { |
| 323 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 324 | ? FixedDoubleArray::SizeFor(length) |
| 325 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 326 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 327 | int size = JSArray::kSize + elements_size; |
| 328 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 329 | // Allocate both the JS array and the elements array in one big |
| 330 | // allocation. This avoids multiple limit checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 331 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 332 | |
| 333 | // Copy the JS array part. |
| 334 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 335 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 336 | __ mov(ebx, FieldOperand(ecx, i)); |
| 337 | __ mov(FieldOperand(eax, i), ebx); |
| 338 | } |
| 339 | } |
| 340 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 341 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 342 | // Get hold of the elements array of the boilerplate and setup the |
| 343 | // elements pointer in the resulting object. |
| 344 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 345 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 346 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 347 | |
| 348 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 349 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 350 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 351 | __ mov(ebx, FieldOperand(ecx, i)); |
| 352 | __ mov(FieldOperand(edx, i), ebx); |
| 353 | } |
| 354 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 355 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 356 | int i; |
| 357 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 358 | __ mov(ebx, FieldOperand(ecx, i)); |
| 359 | __ mov(FieldOperand(edx, i), ebx); |
| 360 | } |
| 361 | while (i < elements_size) { |
| 362 | __ fld_d(FieldOperand(ecx, i)); |
| 363 | __ fstp_d(FieldOperand(edx, i)); |
| 364 | i += kDoubleSize; |
| 365 | } |
| 366 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 369 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 370 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 371 | |
| 372 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 373 | // Stack layout on entry: |
| 374 | // |
| 375 | // [esp + kPointerSize]: constant elements. |
| 376 | // [esp + (2 * kPointerSize)]: literal index. |
| 377 | // [esp + (3 * kPointerSize)]: literals array. |
| 378 | |
| 379 | // Load boilerplate object into ecx and check if we need to create a |
| 380 | // boilerplate. |
| 381 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 382 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 383 | STATIC_ASSERT(kPointerSize == 4); |
| 384 | STATIC_ASSERT(kSmiTagSize == 1); |
| 385 | STATIC_ASSERT(kSmiTag == 0); |
| 386 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 387 | FixedArray::kHeaderSize)); |
| 388 | Factory* factory = masm->isolate()->factory(); |
| 389 | __ cmp(ecx, factory->undefined_value()); |
| 390 | Label slow_case; |
| 391 | __ j(equal, &slow_case); |
| 392 | |
| 393 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 394 | // ecx is boilerplate object. |
| 395 | if (mode == CLONE_ANY_ELEMENTS) { |
| 396 | Label double_elements, check_fast_elements; |
| 397 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 398 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 399 | &check_fast_elements, DONT_DO_SMI_CHECK); |
| 400 | GenerateFastCloneShallowArrayCommon(masm, 0, |
| 401 | COPY_ON_WRITE_ELEMENTS, &slow_case); |
| 402 | __ ret(3 * kPointerSize); |
| 403 | |
| 404 | __ bind(&check_fast_elements); |
| 405 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 406 | &double_elements, DONT_DO_SMI_CHECK); |
| 407 | GenerateFastCloneShallowArrayCommon(masm, length_, |
| 408 | CLONE_ELEMENTS, &slow_case); |
| 409 | __ ret(3 * kPointerSize); |
| 410 | |
| 411 | __ bind(&double_elements); |
| 412 | mode = CLONE_DOUBLE_ELEMENTS; |
| 413 | // Fall through to generate the code to handle double elements. |
| 414 | } |
| 415 | |
| 416 | if (FLAG_debug_code) { |
| 417 | const char* message; |
| 418 | Handle<Map> expected_map; |
| 419 | if (mode == CLONE_ELEMENTS) { |
| 420 | message = "Expected (writable) fixed array"; |
| 421 | expected_map = factory->fixed_array_map(); |
| 422 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 423 | message = "Expected (writable) fixed double array"; |
| 424 | expected_map = factory->fixed_double_array_map(); |
| 425 | } else { |
| 426 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 427 | message = "Expected copy-on-write fixed array"; |
| 428 | expected_map = factory->fixed_cow_array_map(); |
| 429 | } |
| 430 | __ push(ecx); |
| 431 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 432 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 433 | __ Assert(equal, message); |
| 434 | __ pop(ecx); |
| 435 | } |
| 436 | |
| 437 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 438 | // Return and remove the on-stack parameters. |
| 439 | __ ret(3 * kPointerSize); |
| 440 | |
| 441 | __ bind(&slow_case); |
| 442 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 443 | } |
| 444 | |
| 445 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 446 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 447 | // Stack layout on entry: |
| 448 | // |
| 449 | // [esp + kPointerSize]: object literal flags. |
| 450 | // [esp + (2 * kPointerSize)]: constant properties. |
| 451 | // [esp + (3 * kPointerSize)]: literal index. |
| 452 | // [esp + (4 * kPointerSize)]: literals array. |
| 453 | |
| 454 | // Load boilerplate object into ecx and check if we need to create a |
| 455 | // boilerplate. |
| 456 | Label slow_case; |
| 457 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 458 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 459 | STATIC_ASSERT(kPointerSize == 4); |
| 460 | STATIC_ASSERT(kSmiTagSize == 1); |
| 461 | STATIC_ASSERT(kSmiTag == 0); |
| 462 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 463 | FixedArray::kHeaderSize)); |
| 464 | Factory* factory = masm->isolate()->factory(); |
| 465 | __ cmp(ecx, factory->undefined_value()); |
| 466 | __ j(equal, &slow_case); |
| 467 | |
| 468 | // Check that the boilerplate contains only fast properties and we can |
| 469 | // statically determine the instance size. |
| 470 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 471 | __ mov(eax, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 472 | __ movzx_b(eax, FieldOperand(eax, Map::kInstanceSizeOffset)); |
| 473 | __ cmp(eax, Immediate(size >> kPointerSizeLog2)); |
| 474 | __ j(not_equal, &slow_case); |
| 475 | |
| 476 | // Allocate the JS object and copy header together with all in-object |
| 477 | // properties from the boilerplate. |
| 478 | __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); |
| 479 | for (int i = 0; i < size; i += kPointerSize) { |
| 480 | __ mov(ebx, FieldOperand(ecx, i)); |
| 481 | __ mov(FieldOperand(eax, i), ebx); |
| 482 | } |
| 483 | |
| 484 | // Return and remove the on-stack parameters. |
| 485 | __ ret(4 * kPointerSize); |
| 486 | |
| 487 | __ bind(&slow_case); |
| 488 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 489 | } |
| 490 | |
| 491 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 492 | // The stub expects its argument on the stack and returns its result in tos_: |
| 493 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 494 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 495 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 496 | // 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] | 497 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 498 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 499 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 500 | const Register map = edx; |
| 501 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 502 | if (!types_.IsEmpty()) { |
| 503 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 504 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 505 | |
| 506 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 507 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 508 | |
| 509 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 510 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 511 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 512 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 513 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 514 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 515 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 516 | if (types_.Contains(SMI)) { |
| 517 | // Smis: 0 -> false, all other -> true |
| 518 | Label not_smi; |
| 519 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 520 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 521 | if (!tos_.is(argument)) { |
| 522 | __ mov(tos_, argument); |
| 523 | } |
| 524 | __ ret(1 * kPointerSize); |
| 525 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 526 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 527 | // If we need a map later and have a Smi -> patch. |
| 528 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 529 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 530 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 531 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 532 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 533 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 534 | if (types_.CanBeUndetectable()) { |
| 535 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 536 | 1 << Map::kIsUndetectable); |
| 537 | // Undetectable -> false. |
| 538 | Label not_undetectable; |
| 539 | __ j(zero, ¬_undetectable, Label::kNear); |
| 540 | __ Set(tos_, Immediate(0)); |
| 541 | __ ret(1 * kPointerSize); |
| 542 | __ bind(¬_undetectable); |
| 543 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 544 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 545 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 546 | if (types_.Contains(SPEC_OBJECT)) { |
| 547 | // spec object -> true. |
| 548 | Label not_js_object; |
| 549 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 550 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 551 | // argument contains the correct return value already. |
| 552 | if (!tos_.is(argument)) { |
| 553 | __ Set(tos_, Immediate(1)); |
| 554 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 555 | __ ret(1 * kPointerSize); |
| 556 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 557 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 558 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 559 | if (types_.Contains(STRING)) { |
| 560 | // String value -> false iff empty. |
| 561 | Label not_string; |
| 562 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 563 | __ j(above_equal, ¬_string, Label::kNear); |
| 564 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 565 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 566 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | if (types_.Contains(HEAP_NUMBER)) { |
| 570 | // heap number -> false iff +0, -0, or NaN. |
| 571 | Label not_heap_number, false_result; |
| 572 | __ cmp(map, factory->heap_number_map()); |
| 573 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 574 | __ fldz(); |
| 575 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 576 | __ FCmp(); |
| 577 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 578 | // argument contains the correct return value already. |
| 579 | if (!tos_.is(argument)) { |
| 580 | __ Set(tos_, Immediate(1)); |
| 581 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 582 | __ ret(1 * kPointerSize); |
| 583 | __ bind(&false_result); |
| 584 | __ Set(tos_, Immediate(0)); |
| 585 | __ ret(1 * kPointerSize); |
| 586 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 587 | } |
| 588 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 589 | __ bind(&patch); |
| 590 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 594 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 595 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 596 | // store the registers in any particular way, but we do have to store and |
| 597 | // restore them. |
| 598 | __ pushad(); |
| 599 | if (save_doubles_ == kSaveFPRegs) { |
| 600 | CpuFeatures::Scope scope(SSE2); |
| 601 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 602 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 603 | XMMRegister reg = XMMRegister::from_code(i); |
| 604 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 605 | } |
| 606 | } |
| 607 | const int argument_count = 1; |
| 608 | |
| 609 | AllowExternalCallThatCantCauseGC scope(masm); |
| 610 | __ PrepareCallCFunction(argument_count, ecx); |
| 611 | __ mov(Operand(esp, 0 * kPointerSize), |
| 612 | Immediate(ExternalReference::isolate_address())); |
| 613 | __ CallCFunction( |
| 614 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 615 | argument_count); |
| 616 | if (save_doubles_ == kSaveFPRegs) { |
| 617 | CpuFeatures::Scope scope(SSE2); |
| 618 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 619 | XMMRegister reg = XMMRegister::from_code(i); |
| 620 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 621 | } |
| 622 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 623 | } |
| 624 | __ popad(); |
| 625 | __ ret(0); |
| 626 | } |
| 627 | |
| 628 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 629 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 630 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 631 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 632 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 633 | const Register argument = eax; |
| 634 | if (types_.Contains(type)) { |
| 635 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 636 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 637 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 638 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 639 | if (!result) { |
| 640 | // If we have to return zero, there is no way around clearing tos_. |
| 641 | __ Set(tos_, Immediate(0)); |
| 642 | } else if (!tos_.is(argument)) { |
| 643 | // If we have to return non-zero, we can re-use the argument if it is the |
| 644 | // same register as the result, because we never see Smi-zero here. |
| 645 | __ Set(tos_, Immediate(1)); |
| 646 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 647 | __ ret(1 * kPointerSize); |
| 648 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | |
| 653 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 654 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 655 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 656 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 657 | __ push(ecx); // Push return address. |
| 658 | // Patch the caller to an appropriate specialized stub and return the |
| 659 | // operation result to the caller of the stub. |
| 660 | __ TailCallExternalReference( |
| 661 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 662 | 3, |
| 663 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 667 | class FloatingPointHelper : public AllStatic { |
| 668 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 669 | enum ArgLocation { |
| 670 | ARGS_ON_STACK, |
| 671 | ARGS_IN_REGISTERS |
| 672 | }; |
| 673 | |
| 674 | // Code pattern for loading a floating point value. Input value must |
| 675 | // be either a smi or a heap number object (fp value). Requirements: |
| 676 | // operand in register number. Returns operand as floating point number |
| 677 | // on FPU stack. |
| 678 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 679 | |
| 680 | // Code pattern for loading floating point values. Input values must |
| 681 | // be either smi or heap number objects (fp values). Requirements: |
| 682 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 683 | // Returns operands as floating point numbers on FPU stack. |
| 684 | static void LoadFloatOperands(MacroAssembler* masm, |
| 685 | Register scratch, |
| 686 | ArgLocation arg_location = ARGS_ON_STACK); |
| 687 | |
| 688 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 689 | // Expects operands in edx, eax. |
| 690 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 691 | |
| 692 | // Test if operands are smi or number objects (fp). Requirements: |
| 693 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 694 | // operands, jumps to the non_float label otherwise. |
| 695 | static void CheckFloatOperands(MacroAssembler* masm, |
| 696 | Label* non_float, |
| 697 | Register scratch); |
| 698 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 699 | // Checks that the two floating point numbers on top of the FPU stack |
| 700 | // have int32 values. |
| 701 | static void CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 702 | Label* non_int32); |
| 703 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 704 | // Takes the operands in edx and eax and loads them as integers in eax |
| 705 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 706 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 707 | bool use_sse3, |
| 708 | Label* operand_conversion_failure); |
| 709 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 710 | // Must only be called after LoadUnknownsAsIntegers. Assumes that the |
| 711 | // operands are pushed on the stack, and that their conversions to int32 |
| 712 | // are in eax and ecx. Checks that the original numbers were in the int32 |
| 713 | // range. |
| 714 | static void CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 715 | bool use_sse3, |
| 716 | Label* not_int32); |
| 717 | |
| 718 | // Assumes that operands are smis or heap numbers and loads them |
| 719 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 720 | // Leaves operands unchanged. |
| 721 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 722 | |
| 723 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 724 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 725 | // either operand is not a number. Operands are in edx and eax. |
| 726 | // Leaves operands unchanged. |
| 727 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 728 | |
| 729 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 730 | // Expects operands in edx, eax. |
| 731 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | |
| 733 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 734 | // have int32 values. |
| 735 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 736 | Label* non_int32, |
| 737 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 738 | |
| 739 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 740 | Label* non_int32, |
| 741 | XMMRegister operand, |
| 742 | Register scratch, |
| 743 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 747 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 748 | // is faster than using the built-in instructions on floating point registers. |
| 749 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 750 | // trashed registers. |
| 751 | static void IntegerConvert(MacroAssembler* masm, |
| 752 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 753 | bool use_sse3, |
| 754 | Label* conversion_failure) { |
| 755 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 756 | Label done, right_exponent, normal_exponent; |
| 757 | Register scratch = ebx; |
| 758 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 759 | // Get exponent word. |
| 760 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 761 | // Get exponent alone in scratch2. |
| 762 | __ mov(scratch2, scratch); |
| 763 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 764 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 765 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 766 | // Load ecx with zero. We use this either for the final shift or |
| 767 | // for the answer. |
| 768 | __ xor_(ecx, ecx); |
| 769 | // If the exponent is above 83, the number contains no significant |
| 770 | // bits in the range 0..2^31, so the result is zero. |
| 771 | static const uint32_t kResultIsZeroExponent = 83; |
| 772 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 773 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 774 | if (use_sse3) { |
| 775 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 776 | // 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] | 777 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 778 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 779 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 780 | // Load x87 register with heap number. |
| 781 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 782 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 783 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 784 | // Do conversion, which cannot fail because we checked the exponent. |
| 785 | __ fisttp_d(Operand(esp, 0)); |
| 786 | __ 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] | 787 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 788 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 789 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 790 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 791 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 792 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 793 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 794 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 795 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 796 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 797 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 798 | // If the exponent is higher than that then go to slow case. This catches |
| 799 | // 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] | 800 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 801 | |
| 802 | { |
| 803 | // Handle a big exponent. The only reason we have this code is that the |
| 804 | // >>> 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] | 805 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 806 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 807 | __ j(not_equal, conversion_failure); |
| 808 | // We have the big exponent, typically from >>>. This means the number is |
| 809 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 810 | __ mov(scratch2, scratch); |
| 811 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 812 | // Put back the implicit 1. |
| 813 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 814 | // Shift up the mantissa bits to take up the space the exponent used to |
| 815 | // take. We just orred in the implicit bit so that took care of one and |
| 816 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 817 | // shift distance. |
| 818 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 819 | __ shl(scratch2, big_shift_distance); |
| 820 | // Get the second half of the double. |
| 821 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 822 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 823 | // mantissa word. |
| 824 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 825 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 826 | // 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] | 827 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 828 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 829 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 830 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 834 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 835 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 836 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 837 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 838 | |
| 839 | __ bind(&right_exponent); |
| 840 | // Here ecx is the shift, scratch is the exponent word. |
| 841 | // Get the top bits of the mantissa. |
| 842 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 843 | // Put back the implicit 1. |
| 844 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 845 | // Shift up the mantissa bits to take up the space the exponent used to |
| 846 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 847 | // word. Shift them to the top bits. |
| 848 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 849 | __ shl(scratch, shift_distance); |
| 850 | // Get the second half of the double. For some exponents we don't |
| 851 | // actually need this because the bits get shifted out again, but |
| 852 | // it's probably slower to test than just to do it. |
| 853 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 854 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 855 | // mantissa word. |
| 856 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 857 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 858 | // Move down according to the exponent. |
| 859 | __ shr_cl(scratch2); |
| 860 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 861 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 862 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 863 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 864 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 865 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 866 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 867 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 868 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 869 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 870 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 871 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 875 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 876 | const char* op_name = Token::Name(op_); |
| 877 | const char* overwrite_name = NULL; // Make g++ happy. |
| 878 | switch (mode_) { |
| 879 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 880 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 881 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 882 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 883 | op_name, |
| 884 | overwrite_name, |
| 885 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
| 889 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 890 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 891 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 892 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 893 | GenerateTypeTransition(masm); |
| 894 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 895 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 896 | GenerateSmiStub(masm); |
| 897 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 898 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 899 | GenerateHeapNumberStub(masm); |
| 900 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 901 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 902 | GenerateGenericStub(masm); |
| 903 | break; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 908 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 909 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 910 | |
| 911 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 912 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 913 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 914 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 915 | |
| 916 | __ push(ecx); // Push return address. |
| 917 | |
| 918 | // Patch the caller to an appropriate specialized stub and return the |
| 919 | // operation result to the caller of the stub. |
| 920 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 921 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | |
| 925 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 926 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 927 | switch (op_) { |
| 928 | case Token::SUB: |
| 929 | GenerateSmiStubSub(masm); |
| 930 | break; |
| 931 | case Token::BIT_NOT: |
| 932 | GenerateSmiStubBitNot(masm); |
| 933 | break; |
| 934 | default: |
| 935 | UNREACHABLE(); |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 940 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 941 | Label non_smi, undo, slow; |
| 942 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 943 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 944 | __ bind(&undo); |
| 945 | GenerateSmiCodeUndo(masm); |
| 946 | __ bind(&non_smi); |
| 947 | __ bind(&slow); |
| 948 | GenerateTypeTransition(masm); |
| 949 | } |
| 950 | |
| 951 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 952 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 953 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 954 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 955 | __ bind(&non_smi); |
| 956 | GenerateTypeTransition(masm); |
| 957 | } |
| 958 | |
| 959 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 960 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 961 | Label* non_smi, |
| 962 | Label* undo, |
| 963 | Label* slow, |
| 964 | Label::Distance non_smi_near, |
| 965 | Label::Distance undo_near, |
| 966 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 967 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 968 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 969 | |
| 970 | // 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] | 971 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 972 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 973 | |
| 974 | // 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] | 975 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 976 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 977 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 978 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 979 | __ ret(0); |
| 980 | } |
| 981 | |
| 982 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 983 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 984 | MacroAssembler* masm, |
| 985 | Label* non_smi, |
| 986 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 987 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 988 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 989 | |
| 990 | // Flip bits and revert inverted smi-tag. |
| 991 | __ not_(eax); |
| 992 | __ and_(eax, ~kSmiTagMask); |
| 993 | __ ret(0); |
| 994 | } |
| 995 | |
| 996 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 997 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 998 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | |
| 1002 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1003 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1004 | switch (op_) { |
| 1005 | case Token::SUB: |
| 1006 | GenerateHeapNumberStubSub(masm); |
| 1007 | break; |
| 1008 | case Token::BIT_NOT: |
| 1009 | GenerateHeapNumberStubBitNot(masm); |
| 1010 | break; |
| 1011 | default: |
| 1012 | UNREACHABLE(); |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1017 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1018 | Label non_smi, undo, slow, call_builtin; |
| 1019 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1020 | __ bind(&non_smi); |
| 1021 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1022 | __ bind(&undo); |
| 1023 | GenerateSmiCodeUndo(masm); |
| 1024 | __ bind(&slow); |
| 1025 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1026 | __ bind(&call_builtin); |
| 1027 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1031 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1032 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1033 | Label non_smi, slow; |
| 1034 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1035 | __ bind(&non_smi); |
| 1036 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1037 | __ bind(&slow); |
| 1038 | GenerateTypeTransition(masm); |
| 1039 | } |
| 1040 | |
| 1041 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1042 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1043 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1044 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1045 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1046 | __ j(not_equal, slow); |
| 1047 | |
| 1048 | if (mode_ == UNARY_OVERWRITE) { |
| 1049 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1050 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1051 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1052 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1053 | // edx: operand |
| 1054 | |
| 1055 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1056 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1057 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1058 | |
| 1059 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1060 | { |
| 1061 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1062 | __ push(edx); |
| 1063 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1064 | __ pop(edx); |
| 1065 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1066 | |
| 1067 | __ bind(&heapnumber_allocated); |
| 1068 | // eax: allocated 'empty' number |
| 1069 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1070 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1071 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1072 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1073 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1074 | } |
| 1075 | __ ret(0); |
| 1076 | } |
| 1077 | |
| 1078 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1079 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1080 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1081 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1082 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1083 | __ j(not_equal, slow); |
| 1084 | |
| 1085 | // 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] | 1086 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1087 | |
| 1088 | // 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] | 1089 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1090 | __ not_(ecx); |
| 1091 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1092 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1093 | |
| 1094 | // Tag the result as a smi and we're done. |
| 1095 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1096 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1097 | __ ret(0); |
| 1098 | |
| 1099 | // Try to store the result in a heap number. |
| 1100 | __ bind(&try_float); |
| 1101 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1102 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1103 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1104 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1105 | __ jmp(&heapnumber_allocated); |
| 1106 | |
| 1107 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1108 | { |
| 1109 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1110 | // Push the original HeapNumber on the stack. The integer value can't |
| 1111 | // be stored since it's untagged and not in the smi range (so we can't |
| 1112 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1113 | __ push(ebx); |
| 1114 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1115 | // New HeapNumber is in eax. |
| 1116 | __ pop(edx); |
| 1117 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1118 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1119 | // This conversion won't go slow-case. |
| 1120 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1121 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1122 | |
| 1123 | __ bind(&heapnumber_allocated); |
| 1124 | } |
| 1125 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1126 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1127 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1128 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1129 | } else { |
| 1130 | __ push(ecx); |
| 1131 | __ fild_s(Operand(esp, 0)); |
| 1132 | __ pop(ecx); |
| 1133 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1134 | } |
| 1135 | __ ret(0); |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1140 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1141 | switch (op_) { |
| 1142 | case Token::SUB: |
| 1143 | GenerateGenericStubSub(masm); |
| 1144 | break; |
| 1145 | case Token::BIT_NOT: |
| 1146 | GenerateGenericStubBitNot(masm); |
| 1147 | break; |
| 1148 | default: |
| 1149 | UNREACHABLE(); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1154 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1155 | Label non_smi, undo, slow; |
| 1156 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1157 | __ bind(&non_smi); |
| 1158 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1159 | __ bind(&undo); |
| 1160 | GenerateSmiCodeUndo(masm); |
| 1161 | __ bind(&slow); |
| 1162 | GenerateGenericCodeFallback(masm); |
| 1163 | } |
| 1164 | |
| 1165 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1166 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1167 | Label non_smi, slow; |
| 1168 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1169 | __ bind(&non_smi); |
| 1170 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1171 | __ bind(&slow); |
| 1172 | GenerateGenericCodeFallback(masm); |
| 1173 | } |
| 1174 | |
| 1175 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1176 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1177 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1178 | __ pop(ecx); // pop return address. |
| 1179 | __ push(eax); |
| 1180 | __ push(ecx); // push return address |
| 1181 | switch (op_) { |
| 1182 | case Token::SUB: |
| 1183 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1184 | break; |
| 1185 | case Token::BIT_NOT: |
| 1186 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1187 | break; |
| 1188 | default: |
| 1189 | UNREACHABLE(); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1194 | void BinaryOpStub::Initialize() { |
| 1195 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1196 | } |
| 1197 | |
| 1198 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1199 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1200 | __ pop(ecx); // Save return address. |
| 1201 | __ push(edx); |
| 1202 | __ push(eax); |
| 1203 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1204 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1205 | |
| 1206 | __ push(ecx); // Push return address. |
| 1207 | |
| 1208 | // Patch the caller to an appropriate specialized stub and return the |
| 1209 | // operation result to the caller of the stub. |
| 1210 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1211 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1212 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1213 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1214 | 1); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | // Prepare for a type transition runtime call when the args are already on |
| 1219 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1220 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1221 | __ pop(ecx); // Save return address. |
| 1222 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1224 | |
| 1225 | __ push(ecx); // Push return address. |
| 1226 | |
| 1227 | // Patch the caller to an appropriate specialized stub and return the |
| 1228 | // operation result to the caller of the stub. |
| 1229 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1230 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1231 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1232 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1233 | 1); |
| 1234 | } |
| 1235 | |
| 1236 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1237 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1238 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1239 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1240 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1241 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1242 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1243 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1244 | Comment load_comment(masm, "-- Load arguments"); |
| 1245 | Register left = edx; |
| 1246 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1247 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1248 | left = eax; |
| 1249 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1250 | __ mov(ebx, eax); |
| 1251 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | // 2. Prepare the smi check of both operands by oring them together. |
| 1256 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1257 | Label not_smis; |
| 1258 | Register combined = ecx; |
| 1259 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1260 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1261 | case Token::BIT_OR: |
| 1262 | // Perform the operation into eax and smi check the result. Preserve |
| 1263 | // eax in case the result is not a smi. |
| 1264 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1265 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1266 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1267 | combined = right; |
| 1268 | break; |
| 1269 | |
| 1270 | case Token::BIT_XOR: |
| 1271 | case Token::BIT_AND: |
| 1272 | case Token::ADD: |
| 1273 | case Token::SUB: |
| 1274 | case Token::MUL: |
| 1275 | case Token::DIV: |
| 1276 | case Token::MOD: |
| 1277 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1278 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1279 | break; |
| 1280 | |
| 1281 | case Token::SHL: |
| 1282 | case Token::SAR: |
| 1283 | case Token::SHR: |
| 1284 | // Move the right operand into ecx for the shift operation, use eax |
| 1285 | // for the smi check register. |
| 1286 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1287 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1288 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1289 | combined = right; |
| 1290 | break; |
| 1291 | |
| 1292 | default: |
| 1293 | break; |
| 1294 | } |
| 1295 | |
| 1296 | // 3. Perform the smi check of the operands. |
| 1297 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1298 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | |
| 1300 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1301 | // eax and check the result if necessary. |
| 1302 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1303 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1304 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1305 | case Token::BIT_OR: |
| 1306 | // Nothing to do. |
| 1307 | break; |
| 1308 | |
| 1309 | case Token::BIT_XOR: |
| 1310 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1311 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | case Token::BIT_AND: |
| 1315 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1316 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1317 | break; |
| 1318 | |
| 1319 | case Token::SHL: |
| 1320 | // Remove tags from operands (but keep sign). |
| 1321 | __ SmiUntag(left); |
| 1322 | __ SmiUntag(ecx); |
| 1323 | // Perform the operation. |
| 1324 | __ shl_cl(left); |
| 1325 | // Check that the *signed* result fits in a smi. |
| 1326 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1327 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1328 | // Tag the result and store it in register eax. |
| 1329 | __ SmiTag(left); |
| 1330 | __ mov(eax, left); |
| 1331 | break; |
| 1332 | |
| 1333 | case Token::SAR: |
| 1334 | // Remove tags from operands (but keep sign). |
| 1335 | __ SmiUntag(left); |
| 1336 | __ SmiUntag(ecx); |
| 1337 | // Perform the operation. |
| 1338 | __ sar_cl(left); |
| 1339 | // Tag the result and store it in register eax. |
| 1340 | __ SmiTag(left); |
| 1341 | __ mov(eax, left); |
| 1342 | break; |
| 1343 | |
| 1344 | case Token::SHR: |
| 1345 | // Remove tags from operands (but keep sign). |
| 1346 | __ SmiUntag(left); |
| 1347 | __ SmiUntag(ecx); |
| 1348 | // Perform the operation. |
| 1349 | __ shr_cl(left); |
| 1350 | // Check that the *unsigned* result fits in a smi. |
| 1351 | // Neither of the two high-order bits can be set: |
| 1352 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1353 | // - 0x40000000: this number would convert to negative when |
| 1354 | // Smi tagging these two cases can only happen with shifts |
| 1355 | // by 0 or 1 when handed a valid smi. |
| 1356 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1357 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1358 | // Tag the result and store it in register eax. |
| 1359 | __ SmiTag(left); |
| 1360 | __ mov(eax, left); |
| 1361 | break; |
| 1362 | |
| 1363 | case Token::ADD: |
| 1364 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1365 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1366 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | |
| 1369 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1370 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1371 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | __ mov(eax, left); |
| 1373 | break; |
| 1374 | |
| 1375 | case Token::MUL: |
| 1376 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1377 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1378 | // We can't revert the multiplication if the result is not a smi |
| 1379 | // so save the right operand. |
| 1380 | __ mov(ebx, right); |
| 1381 | // Remove tag from one of the operands (but keep sign). |
| 1382 | __ SmiUntag(right); |
| 1383 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1384 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1385 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1386 | // Check for negative zero result. Use combined = left | right. |
| 1387 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1388 | break; |
| 1389 | |
| 1390 | case Token::DIV: |
| 1391 | // We can't revert the division if the result is not a smi so |
| 1392 | // save the left operand. |
| 1393 | __ mov(edi, left); |
| 1394 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1395 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1396 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1397 | // Sign extend left into edx:eax. |
| 1398 | ASSERT(left.is(eax)); |
| 1399 | __ cdq(); |
| 1400 | // Divide edx:eax by right. |
| 1401 | __ idiv(right); |
| 1402 | // Check for the corner case of dividing the most negative smi by |
| 1403 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1404 | // instruction. |
| 1405 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1406 | __ cmp(eax, 0x40000000); |
| 1407 | __ j(equal, &use_fp_on_smis); |
| 1408 | // Check for negative zero result. Use combined = left | right. |
| 1409 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1410 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1411 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1412 | __ j(not_zero, &use_fp_on_smis); |
| 1413 | // Tag the result and store it in register eax. |
| 1414 | __ SmiTag(eax); |
| 1415 | break; |
| 1416 | |
| 1417 | case Token::MOD: |
| 1418 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1419 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1420 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1421 | |
| 1422 | // Sign extend left into edx:eax. |
| 1423 | ASSERT(left.is(eax)); |
| 1424 | __ cdq(); |
| 1425 | // Divide edx:eax by right. |
| 1426 | __ idiv(right); |
| 1427 | // Check for negative zero result. Use combined = left | right. |
| 1428 | __ NegativeZeroTest(edx, combined, slow); |
| 1429 | // Move remainder to register eax. |
| 1430 | __ mov(eax, edx); |
| 1431 | break; |
| 1432 | |
| 1433 | default: |
| 1434 | UNREACHABLE(); |
| 1435 | } |
| 1436 | |
| 1437 | // 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] | 1438 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1439 | case Token::ADD: |
| 1440 | case Token::SUB: |
| 1441 | case Token::MUL: |
| 1442 | case Token::DIV: |
| 1443 | __ ret(0); |
| 1444 | break; |
| 1445 | case Token::MOD: |
| 1446 | case Token::BIT_OR: |
| 1447 | case Token::BIT_AND: |
| 1448 | case Token::BIT_XOR: |
| 1449 | case Token::SAR: |
| 1450 | case Token::SHL: |
| 1451 | case Token::SHR: |
| 1452 | __ ret(2 * kPointerSize); |
| 1453 | break; |
| 1454 | default: |
| 1455 | UNREACHABLE(); |
| 1456 | } |
| 1457 | |
| 1458 | // 6. For some operations emit inline code to perform floating point |
| 1459 | // operations on known smis (e.g., if the result of the operation |
| 1460 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1461 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1462 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1463 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1464 | // Undo the effects of some operations, and some register moves. |
| 1465 | case Token::SHL: |
| 1466 | // The arguments are saved on the stack, and only used from there. |
| 1467 | break; |
| 1468 | case Token::ADD: |
| 1469 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1470 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1471 | break; |
| 1472 | case Token::SUB: |
| 1473 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1474 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | break; |
| 1476 | case Token::MUL: |
| 1477 | // Right was clobbered but a copy is in ebx. |
| 1478 | __ mov(right, ebx); |
| 1479 | break; |
| 1480 | case Token::DIV: |
| 1481 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1482 | // division. They should be in eax, ebx for jump to not_smi. |
| 1483 | __ mov(eax, edi); |
| 1484 | break; |
| 1485 | default: |
| 1486 | // No other operators jump to use_fp_on_smis. |
| 1487 | break; |
| 1488 | } |
| 1489 | __ jmp(¬_smis); |
| 1490 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1491 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1492 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1493 | case Token::SHL: |
| 1494 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1495 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1496 | __ bind(&use_fp_on_smis); |
| 1497 | // Result we want is in left == edx, so we can put the allocated heap |
| 1498 | // number in eax. |
| 1499 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1500 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1501 | // It's OK to overwrite the arguments on the stack because we |
| 1502 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1503 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1504 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1505 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1506 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1507 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1508 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1509 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1510 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1511 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1512 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1513 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1514 | } else { |
| 1515 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1516 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1517 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1518 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1519 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1520 | __ ret(2 * kPointerSize); |
| 1521 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | case Token::ADD: |
| 1525 | case Token::SUB: |
| 1526 | case Token::MUL: |
| 1527 | case Token::DIV: { |
| 1528 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1529 | __ bind(&use_fp_on_smis); |
| 1530 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1531 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1532 | case Token::ADD: |
| 1533 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1534 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1535 | break; |
| 1536 | case Token::SUB: |
| 1537 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1538 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | case Token::MUL: |
| 1541 | // Right was clobbered but a copy is in ebx. |
| 1542 | __ mov(right, ebx); |
| 1543 | break; |
| 1544 | case Token::DIV: |
| 1545 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1546 | // division. |
| 1547 | __ mov(edx, edi); |
| 1548 | __ mov(eax, right); |
| 1549 | break; |
| 1550 | default: UNREACHABLE(); |
| 1551 | break; |
| 1552 | } |
| 1553 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1554 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | CpuFeatures::Scope use_sse2(SSE2); |
| 1556 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1557 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1558 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1559 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1560 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1561 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1562 | default: UNREACHABLE(); |
| 1563 | } |
| 1564 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1565 | } else { // SSE2 not available, use FPU. |
| 1566 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1567 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1568 | case Token::ADD: __ faddp(1); break; |
| 1569 | case Token::SUB: __ fsubp(1); break; |
| 1570 | case Token::MUL: __ fmulp(1); break; |
| 1571 | case Token::DIV: __ fdivp(1); break; |
| 1572 | default: UNREACHABLE(); |
| 1573 | } |
| 1574 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1575 | } |
| 1576 | __ mov(eax, ecx); |
| 1577 | __ ret(0); |
| 1578 | break; |
| 1579 | } |
| 1580 | |
| 1581 | default: |
| 1582 | break; |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1587 | // edx and eax. |
| 1588 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1589 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1590 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1591 | case Token::BIT_OR: |
| 1592 | case Token::SHL: |
| 1593 | case Token::SAR: |
| 1594 | case Token::SHR: |
| 1595 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1596 | // check. |
| 1597 | __ mov(eax, ecx); |
| 1598 | break; |
| 1599 | |
| 1600 | case Token::DIV: |
| 1601 | case Token::MOD: |
| 1602 | // Operands are in eax, ebx at this point. |
| 1603 | __ mov(edx, eax); |
| 1604 | __ mov(eax, ebx); |
| 1605 | break; |
| 1606 | |
| 1607 | default: |
| 1608 | break; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1613 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1614 | Label call_runtime; |
| 1615 | |
| 1616 | switch (op_) { |
| 1617 | case Token::ADD: |
| 1618 | case Token::SUB: |
| 1619 | case Token::MUL: |
| 1620 | case Token::DIV: |
| 1621 | break; |
| 1622 | case Token::MOD: |
| 1623 | case Token::BIT_OR: |
| 1624 | case Token::BIT_AND: |
| 1625 | case Token::BIT_XOR: |
| 1626 | case Token::SAR: |
| 1627 | case Token::SHL: |
| 1628 | case Token::SHR: |
| 1629 | GenerateRegisterArgsPush(masm); |
| 1630 | break; |
| 1631 | default: |
| 1632 | UNREACHABLE(); |
| 1633 | } |
| 1634 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1635 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1636 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1637 | BinaryOpStub_GenerateSmiCode( |
| 1638 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1640 | BinaryOpStub_GenerateSmiCode( |
| 1641 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1642 | } |
| 1643 | __ bind(&call_runtime); |
| 1644 | switch (op_) { |
| 1645 | case Token::ADD: |
| 1646 | case Token::SUB: |
| 1647 | case Token::MUL: |
| 1648 | case Token::DIV: |
| 1649 | GenerateTypeTransition(masm); |
| 1650 | break; |
| 1651 | case Token::MOD: |
| 1652 | case Token::BIT_OR: |
| 1653 | case Token::BIT_AND: |
| 1654 | case Token::BIT_XOR: |
| 1655 | case Token::SAR: |
| 1656 | case Token::SHL: |
| 1657 | case Token::SHR: |
| 1658 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1659 | break; |
| 1660 | default: |
| 1661 | UNREACHABLE(); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1666 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1667 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1668 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1669 | ASSERT(op_ == Token::ADD); |
| 1670 | // If both arguments are strings, call the string add stub. |
| 1671 | // Otherwise, do a transition. |
| 1672 | |
| 1673 | // Registers containing left and right operands respectively. |
| 1674 | Register left = edx; |
| 1675 | Register right = eax; |
| 1676 | |
| 1677 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1678 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1679 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1680 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1681 | |
| 1682 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1683 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1684 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1685 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1686 | |
| 1687 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1688 | GenerateRegisterArgsPush(masm); |
| 1689 | __ TailCallStub(&string_add_stub); |
| 1690 | |
| 1691 | __ bind(&call_runtime); |
| 1692 | GenerateTypeTransition(masm); |
| 1693 | } |
| 1694 | |
| 1695 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1696 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1697 | Label* alloc_failure, |
| 1698 | OverwriteMode mode); |
| 1699 | |
| 1700 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1701 | // Input: |
| 1702 | // edx: left operand (tagged) |
| 1703 | // eax: right operand (tagged) |
| 1704 | // Output: |
| 1705 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1706 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1707 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1708 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1709 | |
| 1710 | // Floating point case. |
| 1711 | switch (op_) { |
| 1712 | case Token::ADD: |
| 1713 | case Token::SUB: |
| 1714 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1715 | case Token::DIV: |
| 1716 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | Label not_floats; |
| 1718 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1719 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1720 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1721 | // It could be that only SMIs have been seen at either the left |
| 1722 | // or the right operand. For precise type feedback, patch the IC |
| 1723 | // again if this changes. |
| 1724 | // In theory, we would need the same check in the non-SSE2 case, |
| 1725 | // but since we don't support Crankshaft on such hardware we can |
| 1726 | // afford not to care about precise type feedback. |
| 1727 | if (left_type_ == BinaryOpIC::SMI) { |
| 1728 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1729 | } |
| 1730 | if (right_type_ == BinaryOpIC::SMI) { |
| 1731 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1732 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1733 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1734 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1735 | if (op_ == Token::MOD) { |
| 1736 | GenerateRegisterArgsPush(masm); |
| 1737 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1738 | } else { |
| 1739 | switch (op_) { |
| 1740 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1741 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1742 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1743 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1744 | default: UNREACHABLE(); |
| 1745 | } |
| 1746 | // Check result type if it is currently Int32. |
| 1747 | if (result_type_ <= BinaryOpIC::INT32) { |
| 1748 | __ cvttsd2si(ecx, Operand(xmm0)); |
| 1749 | __ cvtsi2sd(xmm2, ecx); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1750 | __ pcmpeqd(xmm2, xmm0); |
| 1751 | __ movmskpd(ecx, xmm2); |
| 1752 | __ test(ecx, Immediate(1)); |
| 1753 | __ j(zero, ¬_int32); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1754 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1755 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1756 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1757 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1758 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1759 | } else { // SSE2 not available, use FPU. |
| 1760 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1761 | FloatingPointHelper::LoadFloatOperands( |
| 1762 | masm, |
| 1763 | ecx, |
| 1764 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1765 | FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1766 | if (op_ == Token::MOD) { |
| 1767 | // The operands are now on the FPU stack, but we don't need them. |
| 1768 | __ fstp(0); |
| 1769 | __ fstp(0); |
| 1770 | GenerateRegisterArgsPush(masm); |
| 1771 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1772 | } else { |
| 1773 | switch (op_) { |
| 1774 | case Token::ADD: __ faddp(1); break; |
| 1775 | case Token::SUB: __ fsubp(1); break; |
| 1776 | case Token::MUL: __ fmulp(1); break; |
| 1777 | case Token::DIV: __ fdivp(1); break; |
| 1778 | default: UNREACHABLE(); |
| 1779 | } |
| 1780 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1781 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1782 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1783 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1784 | __ ret(0); |
| 1785 | __ bind(&after_alloc_failure); |
| 1786 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1787 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1788 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | __ bind(¬_floats); |
| 1792 | __ bind(¬_int32); |
| 1793 | GenerateTypeTransition(masm); |
| 1794 | break; |
| 1795 | } |
| 1796 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1797 | case Token::BIT_OR: |
| 1798 | case Token::BIT_AND: |
| 1799 | case Token::BIT_XOR: |
| 1800 | case Token::SAR: |
| 1801 | case Token::SHL: |
| 1802 | case Token::SHR: { |
| 1803 | GenerateRegisterArgsPush(masm); |
| 1804 | Label not_floats; |
| 1805 | Label not_int32; |
| 1806 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1807 | // We do not check the input arguments here, as any value is |
| 1808 | // unconditionally truncated to an int32 anyway. To get the |
| 1809 | // right optimized code, int32 type feedback is just right. |
| 1810 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1811 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1812 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1814 | FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1815 | ¬_int32); |
| 1816 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1817 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1818 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1819 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1820 | case Token::SAR: __ sar_cl(eax); break; |
| 1821 | case Token::SHL: __ shl_cl(eax); break; |
| 1822 | case Token::SHR: __ shr_cl(eax); break; |
| 1823 | default: UNREACHABLE(); |
| 1824 | } |
| 1825 | if (op_ == Token::SHR) { |
| 1826 | // Check if result is non-negative and fits in a smi. |
| 1827 | __ test(eax, Immediate(0xc0000000)); |
| 1828 | __ j(not_zero, &call_runtime); |
| 1829 | } else { |
| 1830 | // Check if result fits in a smi. |
| 1831 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1832 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1833 | } |
| 1834 | // Tag smi result and return. |
| 1835 | __ SmiTag(eax); |
| 1836 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1837 | |
| 1838 | // All ops except SHR return a signed int32 that we load in |
| 1839 | // a HeapNumber. |
| 1840 | if (op_ != Token::SHR) { |
| 1841 | __ bind(&non_smi_result); |
| 1842 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1843 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1844 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1845 | switch (mode_) { |
| 1846 | case OVERWRITE_LEFT: |
| 1847 | case OVERWRITE_RIGHT: |
| 1848 | // If the operand was an object, we skip the |
| 1849 | // allocation of a heap number. |
| 1850 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1851 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1852 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1853 | // Fall through! |
| 1854 | case NO_OVERWRITE: |
| 1855 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1856 | __ bind(&skip_allocation); |
| 1857 | break; |
| 1858 | default: UNREACHABLE(); |
| 1859 | } |
| 1860 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1861 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1862 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1863 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1864 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1865 | } else { |
| 1866 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1867 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1868 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1869 | } |
| 1870 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1871 | } |
| 1872 | |
| 1873 | __ bind(¬_floats); |
| 1874 | __ bind(¬_int32); |
| 1875 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1876 | break; |
| 1877 | } |
| 1878 | default: UNREACHABLE(); break; |
| 1879 | } |
| 1880 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1881 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1882 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1883 | __ bind(&call_runtime); |
| 1884 | |
| 1885 | switch (op_) { |
| 1886 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1887 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1888 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1889 | case Token::DIV: |
| 1890 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1891 | break; |
| 1892 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1893 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1894 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1895 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1896 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1897 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1898 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1899 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | break; |
| 1901 | default: |
| 1902 | UNREACHABLE(); |
| 1903 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1904 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1908 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1909 | if (op_ == Token::ADD) { |
| 1910 | // Handle string addition here, because it is the only operation |
| 1911 | // that does not do a ToNumber conversion on the operands. |
| 1912 | GenerateAddStrings(masm); |
| 1913 | } |
| 1914 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1915 | Factory* factory = masm->isolate()->factory(); |
| 1916 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1917 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1918 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1919 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1920 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1921 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1922 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1923 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1924 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1925 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1926 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1927 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1928 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1929 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1930 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1931 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1932 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1933 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1934 | } |
| 1935 | __ bind(&done); |
| 1936 | |
| 1937 | GenerateHeapNumberStub(masm); |
| 1938 | } |
| 1939 | |
| 1940 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1941 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | |
| 1944 | // Floating point case. |
| 1945 | switch (op_) { |
| 1946 | case Token::ADD: |
| 1947 | case Token::SUB: |
| 1948 | case Token::MUL: |
| 1949 | case Token::DIV: { |
| 1950 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1951 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1952 | CpuFeatures::Scope use_sse2(SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1953 | |
| 1954 | // It could be that only SMIs have been seen at either the left |
| 1955 | // or the right operand. For precise type feedback, patch the IC |
| 1956 | // again if this changes. |
| 1957 | // In theory, we would need the same check in the non-SSE2 case, |
| 1958 | // but since we don't support Crankshaft on such hardware we can |
| 1959 | // afford not to care about precise type feedback. |
| 1960 | if (left_type_ == BinaryOpIC::SMI) { |
| 1961 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1962 | } |
| 1963 | if (right_type_ == BinaryOpIC::SMI) { |
| 1964 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1965 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1966 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1967 | if (left_type_ == BinaryOpIC::INT32) { |
| 1968 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1969 | masm, ¬_floats, xmm0, ecx, xmm2); |
| 1970 | } |
| 1971 | if (right_type_ == BinaryOpIC::INT32) { |
| 1972 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1973 | masm, ¬_floats, xmm1, ecx, xmm2); |
| 1974 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1975 | |
| 1976 | switch (op_) { |
| 1977 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1978 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1979 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1980 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1981 | default: UNREACHABLE(); |
| 1982 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1983 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1984 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1985 | __ ret(0); |
| 1986 | } else { // SSE2 not available, use FPU. |
| 1987 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1988 | FloatingPointHelper::LoadFloatOperands( |
| 1989 | masm, |
| 1990 | ecx, |
| 1991 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1992 | switch (op_) { |
| 1993 | case Token::ADD: __ faddp(1); break; |
| 1994 | case Token::SUB: __ fsubp(1); break; |
| 1995 | case Token::MUL: __ fmulp(1); break; |
| 1996 | case Token::DIV: __ fdivp(1); break; |
| 1997 | default: UNREACHABLE(); |
| 1998 | } |
| 1999 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2000 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2001 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2002 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2003 | __ ret(0); |
| 2004 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2005 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2006 | __ jmp(&call_runtime); |
| 2007 | } |
| 2008 | |
| 2009 | __ bind(¬_floats); |
| 2010 | GenerateTypeTransition(masm); |
| 2011 | break; |
| 2012 | } |
| 2013 | |
| 2014 | case Token::MOD: { |
| 2015 | // For MOD we go directly to runtime in the non-smi case. |
| 2016 | break; |
| 2017 | } |
| 2018 | case Token::BIT_OR: |
| 2019 | case Token::BIT_AND: |
| 2020 | case Token::BIT_XOR: |
| 2021 | case Token::SAR: |
| 2022 | case Token::SHL: |
| 2023 | case Token::SHR: { |
| 2024 | GenerateRegisterArgsPush(masm); |
| 2025 | Label not_floats; |
| 2026 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2027 | // We do not check the input arguments here, as any value is |
| 2028 | // unconditionally truncated to an int32 anyway. To get the |
| 2029 | // right optimized code, int32 type feedback is just right. |
| 2030 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2031 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2032 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | ¬_floats); |
| 2034 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2035 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2036 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2037 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2038 | case Token::SAR: __ sar_cl(eax); break; |
| 2039 | case Token::SHL: __ shl_cl(eax); break; |
| 2040 | case Token::SHR: __ shr_cl(eax); break; |
| 2041 | default: UNREACHABLE(); |
| 2042 | } |
| 2043 | if (op_ == Token::SHR) { |
| 2044 | // Check if result is non-negative and fits in a smi. |
| 2045 | __ test(eax, Immediate(0xc0000000)); |
| 2046 | __ j(not_zero, &call_runtime); |
| 2047 | } else { |
| 2048 | // Check if result fits in a smi. |
| 2049 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2050 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2051 | } |
| 2052 | // Tag smi result and return. |
| 2053 | __ SmiTag(eax); |
| 2054 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2055 | |
| 2056 | // All ops except SHR return a signed int32 that we load in |
| 2057 | // a HeapNumber. |
| 2058 | if (op_ != Token::SHR) { |
| 2059 | __ bind(&non_smi_result); |
| 2060 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2061 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2062 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2063 | switch (mode_) { |
| 2064 | case OVERWRITE_LEFT: |
| 2065 | case OVERWRITE_RIGHT: |
| 2066 | // If the operand was an object, we skip the |
| 2067 | // allocation of a heap number. |
| 2068 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2069 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2070 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2071 | // Fall through! |
| 2072 | case NO_OVERWRITE: |
| 2073 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2074 | __ bind(&skip_allocation); |
| 2075 | break; |
| 2076 | default: UNREACHABLE(); |
| 2077 | } |
| 2078 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2079 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2080 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2081 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2082 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2083 | } else { |
| 2084 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2085 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2086 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2087 | } |
| 2088 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2089 | } |
| 2090 | |
| 2091 | __ bind(¬_floats); |
| 2092 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2093 | break; |
| 2094 | } |
| 2095 | default: UNREACHABLE(); break; |
| 2096 | } |
| 2097 | |
| 2098 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2099 | // use the runtime system to get the correct result. |
| 2100 | __ bind(&call_runtime); |
| 2101 | |
| 2102 | switch (op_) { |
| 2103 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2104 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2106 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2107 | case Token::MOD: |
| 2108 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2109 | break; |
| 2110 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2111 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2112 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2115 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | default: |
| 2118 | UNREACHABLE(); |
| 2119 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2120 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2124 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2125 | Label call_runtime; |
| 2126 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2127 | Counters* counters = masm->isolate()->counters(); |
| 2128 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | |
| 2130 | switch (op_) { |
| 2131 | case Token::ADD: |
| 2132 | case Token::SUB: |
| 2133 | case Token::MUL: |
| 2134 | case Token::DIV: |
| 2135 | break; |
| 2136 | case Token::MOD: |
| 2137 | case Token::BIT_OR: |
| 2138 | case Token::BIT_AND: |
| 2139 | case Token::BIT_XOR: |
| 2140 | case Token::SAR: |
| 2141 | case Token::SHL: |
| 2142 | case Token::SHR: |
| 2143 | GenerateRegisterArgsPush(masm); |
| 2144 | break; |
| 2145 | default: |
| 2146 | UNREACHABLE(); |
| 2147 | } |
| 2148 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2149 | BinaryOpStub_GenerateSmiCode( |
| 2150 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2151 | |
| 2152 | // Floating point case. |
| 2153 | switch (op_) { |
| 2154 | case Token::ADD: |
| 2155 | case Token::SUB: |
| 2156 | case Token::MUL: |
| 2157 | case Token::DIV: { |
| 2158 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2159 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2160 | CpuFeatures::Scope use_sse2(SSE2); |
| 2161 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2162 | |
| 2163 | switch (op_) { |
| 2164 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2165 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2166 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2167 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2168 | default: UNREACHABLE(); |
| 2169 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2170 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2171 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2172 | __ ret(0); |
| 2173 | } else { // SSE2 not available, use FPU. |
| 2174 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2175 | FloatingPointHelper::LoadFloatOperands( |
| 2176 | masm, |
| 2177 | ecx, |
| 2178 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2179 | switch (op_) { |
| 2180 | case Token::ADD: __ faddp(1); break; |
| 2181 | case Token::SUB: __ fsubp(1); break; |
| 2182 | case Token::MUL: __ fmulp(1); break; |
| 2183 | case Token::DIV: __ fdivp(1); break; |
| 2184 | default: UNREACHABLE(); |
| 2185 | } |
| 2186 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2187 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2188 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2189 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2190 | __ ret(0); |
| 2191 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2192 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2193 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2194 | } |
| 2195 | __ bind(¬_floats); |
| 2196 | break; |
| 2197 | } |
| 2198 | case Token::MOD: { |
| 2199 | // For MOD we go directly to runtime in the non-smi case. |
| 2200 | break; |
| 2201 | } |
| 2202 | case Token::BIT_OR: |
| 2203 | case Token::BIT_AND: |
| 2204 | case Token::BIT_XOR: |
| 2205 | case Token::SAR: |
| 2206 | case Token::SHL: |
| 2207 | case Token::SHR: { |
| 2208 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2209 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2210 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2211 | use_sse3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2212 | &call_runtime); |
| 2213 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2214 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2215 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2216 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2217 | case Token::SAR: __ sar_cl(eax); break; |
| 2218 | case Token::SHL: __ shl_cl(eax); break; |
| 2219 | case Token::SHR: __ shr_cl(eax); break; |
| 2220 | default: UNREACHABLE(); |
| 2221 | } |
| 2222 | if (op_ == Token::SHR) { |
| 2223 | // Check if result is non-negative and fits in a smi. |
| 2224 | __ test(eax, Immediate(0xc0000000)); |
| 2225 | __ j(not_zero, &call_runtime); |
| 2226 | } else { |
| 2227 | // Check if result fits in a smi. |
| 2228 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2229 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2230 | } |
| 2231 | // Tag smi result and return. |
| 2232 | __ SmiTag(eax); |
| 2233 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2234 | |
| 2235 | // All ops except SHR return a signed int32 that we load in |
| 2236 | // a HeapNumber. |
| 2237 | if (op_ != Token::SHR) { |
| 2238 | __ bind(&non_smi_result); |
| 2239 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2240 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2241 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2242 | switch (mode_) { |
| 2243 | case OVERWRITE_LEFT: |
| 2244 | case OVERWRITE_RIGHT: |
| 2245 | // If the operand was an object, we skip the |
| 2246 | // allocation of a heap number. |
| 2247 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2248 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2249 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2250 | // Fall through! |
| 2251 | case NO_OVERWRITE: |
| 2252 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2253 | __ bind(&skip_allocation); |
| 2254 | break; |
| 2255 | default: UNREACHABLE(); |
| 2256 | } |
| 2257 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2258 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2260 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2261 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2262 | } else { |
| 2263 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2264 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2265 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2266 | } |
| 2267 | __ ret(2 * kPointerSize); |
| 2268 | } |
| 2269 | break; |
| 2270 | } |
| 2271 | default: UNREACHABLE(); break; |
| 2272 | } |
| 2273 | |
| 2274 | // If all else fails, use the runtime system to get the correct |
| 2275 | // result. |
| 2276 | __ bind(&call_runtime); |
| 2277 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2278 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2279 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2280 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2281 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2282 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2283 | case Token::DIV: |
| 2284 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2285 | break; |
| 2286 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2287 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2288 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2289 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2290 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2291 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | case Token::SHR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2293 | break; |
| 2294 | default: |
| 2295 | UNREACHABLE(); |
| 2296 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2297 | GenerateCallRuntime(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2301 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2302 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2303 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2304 | |
| 2305 | // Registers containing left and right operands respectively. |
| 2306 | Register left = edx; |
| 2307 | Register right = eax; |
| 2308 | |
| 2309 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2310 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2311 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2312 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2313 | |
| 2314 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2315 | GenerateRegisterArgsPush(masm); |
| 2316 | __ TailCallStub(&string_add_left_stub); |
| 2317 | |
| 2318 | // Left operand is not a string, test right. |
| 2319 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2320 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2321 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2322 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2323 | |
| 2324 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2325 | GenerateRegisterArgsPush(masm); |
| 2326 | __ TailCallStub(&string_add_right_stub); |
| 2327 | |
| 2328 | // Neither argument is a string. |
| 2329 | __ bind(&call_runtime); |
| 2330 | } |
| 2331 | |
| 2332 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2333 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2334 | Label* alloc_failure, |
| 2335 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2336 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2337 | switch (mode) { |
| 2338 | case OVERWRITE_LEFT: { |
| 2339 | // If the argument in edx is already an object, we skip the |
| 2340 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2341 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2342 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2343 | // for the possible runtime call. |
| 2344 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2345 | // Now edx can be overwritten losing one of the arguments as we are |
| 2346 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2347 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2348 | __ bind(&skip_allocation); |
| 2349 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2350 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | } |
| 2353 | case OVERWRITE_RIGHT: |
| 2354 | // If the argument in eax is already an object, we skip the |
| 2355 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2356 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2357 | // Fall through! |
| 2358 | case NO_OVERWRITE: |
| 2359 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2360 | // for the possible runtime call. |
| 2361 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2362 | // Now eax can be overwritten losing one of the arguments as we are |
| 2363 | // now done and will not need it any more. |
| 2364 | __ mov(eax, ebx); |
| 2365 | __ bind(&skip_allocation); |
| 2366 | break; |
| 2367 | default: UNREACHABLE(); |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2372 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2373 | __ pop(ecx); |
| 2374 | __ push(edx); |
| 2375 | __ push(eax); |
| 2376 | __ push(ecx); |
| 2377 | } |
| 2378 | |
| 2379 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2380 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2381 | // TAGGED case: |
| 2382 | // Input: |
| 2383 | // esp[4]: tagged number input argument (should be number). |
| 2384 | // esp[0]: return address. |
| 2385 | // Output: |
| 2386 | // eax: tagged double result. |
| 2387 | // UNTAGGED case: |
| 2388 | // Input:: |
| 2389 | // esp[0]: return address. |
| 2390 | // xmm1: untagged double input argument |
| 2391 | // Output: |
| 2392 | // xmm1: untagged double result. |
| 2393 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2394 | Label runtime_call; |
| 2395 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2396 | Label skip_cache; |
| 2397 | const bool tagged = (argument_type_ == TAGGED); |
| 2398 | if (tagged) { |
| 2399 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2400 | Label input_not_smi; |
| 2401 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2402 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2403 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2404 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2405 | // Then load the low and high words of the double into ebx, edx. |
| 2406 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2407 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2408 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2409 | __ mov(Operand(esp, 0), eax); |
| 2410 | __ fild_s(Operand(esp, 0)); |
| 2411 | __ fst_d(Operand(esp, 0)); |
| 2412 | __ pop(edx); |
| 2413 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2414 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2415 | __ bind(&input_not_smi); |
| 2416 | // Check if input is a HeapNumber. |
| 2417 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2418 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2419 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2420 | __ j(not_equal, &runtime_call); |
| 2421 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2422 | // low and high words into ebx, edx. |
| 2423 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2424 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2425 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2426 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2427 | __ bind(&loaded); |
| 2428 | } else { // UNTAGGED. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2429 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2430 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2431 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2432 | } else { |
| 2433 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2434 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2435 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2436 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2440 | // ebx = low 32 bits of double value |
| 2441 | // edx = high 32 bits of double value |
| 2442 | // Compute hash (the shifts are arithmetic): |
| 2443 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2444 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2445 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2446 | __ mov(eax, ecx); |
| 2447 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2448 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2449 | __ mov(eax, ecx); |
| 2450 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2451 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2452 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2453 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2454 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2455 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2456 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2457 | // ebx = low 32 bits of double value. |
| 2458 | // edx = high 32 bits of double value. |
| 2459 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2460 | ExternalReference cache_array = |
| 2461 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2462 | __ mov(eax, Immediate(cache_array)); |
| 2463 | int cache_array_index = |
| 2464 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2465 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2466 | // Eax points to the cache for the type type_. |
| 2467 | // 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] | 2468 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2469 | __ j(zero, &runtime_call_clear_stack); |
| 2470 | #ifdef DEBUG |
| 2471 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2472 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2473 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2474 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2475 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2476 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2477 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2478 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2479 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2480 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2481 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2482 | } |
| 2483 | #endif |
| 2484 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2485 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2486 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2487 | // 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] | 2488 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2489 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2490 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2491 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2492 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2493 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2494 | Counters* counters = masm->isolate()->counters(); |
| 2495 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2496 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2497 | if (tagged) { |
| 2498 | __ fstp(0); |
| 2499 | __ ret(kPointerSize); |
| 2500 | } else { // UNTAGGED. |
| 2501 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2502 | __ Ret(); |
| 2503 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2504 | |
| 2505 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2506 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2507 | // Update cache with new value. |
| 2508 | // We are short on registers, so use no_reg as scratch. |
| 2509 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2510 | if (tagged) { |
| 2511 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2512 | } else { // UNTAGGED. |
| 2513 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2514 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2515 | __ movdbl(Operand(esp, 0), xmm1); |
| 2516 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2517 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2518 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2519 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2520 | __ mov(Operand(ecx, 0), ebx); |
| 2521 | __ mov(Operand(ecx, kIntSize), edx); |
| 2522 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2523 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2524 | if (tagged) { |
| 2525 | __ ret(kPointerSize); |
| 2526 | } else { // UNTAGGED. |
| 2527 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2528 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2529 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2530 | // Skip cache and return answer directly, only in untagged case. |
| 2531 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2532 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2533 | __ movdbl(Operand(esp, 0), xmm1); |
| 2534 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2535 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2536 | __ fstp_d(Operand(esp, 0)); |
| 2537 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2538 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2539 | // We return the value in xmm1 without adding it to the cache, but |
| 2540 | // 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] | 2541 | { |
| 2542 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2543 | // Allocate an unused object bigger than a HeapNumber. |
| 2544 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2545 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2546 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2547 | __ Ret(); |
| 2548 | } |
| 2549 | |
| 2550 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2551 | if (tagged) { |
| 2552 | __ bind(&runtime_call_clear_stack); |
| 2553 | __ fstp(0); |
| 2554 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2555 | ExternalReference runtime = |
| 2556 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2557 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2558 | } else { // UNTAGGED. |
| 2559 | __ bind(&runtime_call_clear_stack); |
| 2560 | __ bind(&runtime_call); |
| 2561 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2562 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2563 | { |
| 2564 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2565 | __ push(eax); |
| 2566 | __ CallRuntime(RuntimeFunction(), 1); |
| 2567 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2568 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2569 | __ Ret(); |
| 2570 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | |
| 2574 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2575 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2576 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2577 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2578 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2579 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2580 | default: |
| 2581 | UNIMPLEMENTED(); |
| 2582 | return Runtime::kAbort; |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2587 | void TranscendentalCacheStub::GenerateOperation( |
| 2588 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2589 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2590 | // Input value is on FP stack, and also in ebx/edx. |
| 2591 | // Input value is possibly in xmm1. |
| 2592 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2593 | if (type == TranscendentalCache::SIN || |
| 2594 | type == TranscendentalCache::COS || |
| 2595 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2596 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2597 | // return NaN for infinities and NaN. They can share all code except |
| 2598 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2599 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2600 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2601 | // work. We must reduce it to the appropriate range. |
| 2602 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2603 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2604 | int supported_exponent_limit = |
| 2605 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2606 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2607 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2608 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2609 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2610 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2611 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2612 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2613 | __ fstp(0); |
| 2614 | // NaN is represented by 0x7ff8000000000000. |
| 2615 | __ push(Immediate(0x7ff80000)); |
| 2616 | __ push(Immediate(0)); |
| 2617 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2618 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2619 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2620 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2621 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2622 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2623 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2624 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2625 | __ fldpi(); |
| 2626 | __ fadd(0); |
| 2627 | __ fld(1); |
| 2628 | // FPU Stack: input, 2*pi, input. |
| 2629 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2630 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2631 | __ fwait(); |
| 2632 | __ fnstsw_ax(); |
| 2633 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2634 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2635 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2636 | __ fnclex(); |
| 2637 | __ bind(&no_exceptions); |
| 2638 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2639 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2640 | // Compute st(0) % st(1) |
| 2641 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2642 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2643 | __ bind(&partial_remainder_loop); |
| 2644 | __ fprem1(); |
| 2645 | __ fwait(); |
| 2646 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2647 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2648 | // If C2 is set, computation only has partial result. Loop to |
| 2649 | // continue computation. |
| 2650 | __ j(not_zero, &partial_remainder_loop); |
| 2651 | } |
| 2652 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2653 | __ fstp(2); |
| 2654 | __ fstp(0); |
| 2655 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2656 | |
| 2657 | // FPU Stack: input % 2*pi |
| 2658 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2659 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2660 | case TranscendentalCache::SIN: |
| 2661 | __ fsin(); |
| 2662 | break; |
| 2663 | case TranscendentalCache::COS: |
| 2664 | __ fcos(); |
| 2665 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2666 | case TranscendentalCache::TAN: |
| 2667 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2668 | // FP register stack. |
| 2669 | __ fptan(); |
| 2670 | __ fstp(0); // Pop FP register stack. |
| 2671 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2672 | default: |
| 2673 | UNREACHABLE(); |
| 2674 | } |
| 2675 | __ bind(&done); |
| 2676 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2677 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2678 | __ fldln2(); |
| 2679 | __ fxch(); |
| 2680 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2681 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2685 | // Input: edx, eax are the left and right objects of a bit op. |
| 2686 | // 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] | 2687 | void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 2688 | bool use_sse3, |
| 2689 | Label* conversion_failure) { |
| 2690 | // Check float operands. |
| 2691 | Label arg1_is_object, check_undefined_arg1; |
| 2692 | Label arg2_is_object, check_undefined_arg2; |
| 2693 | Label load_arg2, done; |
| 2694 | |
| 2695 | // Test if arg1 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2696 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2697 | |
| 2698 | __ SmiUntag(edx); |
| 2699 | __ jmp(&load_arg2); |
| 2700 | |
| 2701 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2702 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2703 | Factory* factory = masm->isolate()->factory(); |
| 2704 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2705 | __ j(not_equal, conversion_failure); |
| 2706 | __ mov(edx, Immediate(0)); |
| 2707 | __ jmp(&load_arg2); |
| 2708 | |
| 2709 | __ bind(&arg1_is_object); |
| 2710 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2711 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2712 | __ j(not_equal, &check_undefined_arg1); |
| 2713 | |
| 2714 | // 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] | 2715 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2716 | __ mov(edx, ecx); |
| 2717 | |
| 2718 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2719 | __ bind(&load_arg2); |
| 2720 | |
| 2721 | // Test if arg2 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2722 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2723 | |
| 2724 | __ SmiUntag(eax); |
| 2725 | __ mov(ecx, eax); |
| 2726 | __ jmp(&done); |
| 2727 | |
| 2728 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2729 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2730 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2731 | __ j(not_equal, conversion_failure); |
| 2732 | __ mov(ecx, Immediate(0)); |
| 2733 | __ jmp(&done); |
| 2734 | |
| 2735 | __ bind(&arg2_is_object); |
| 2736 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2737 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2738 | __ j(not_equal, &check_undefined_arg2); |
| 2739 | |
| 2740 | // 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] | 2741 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2742 | __ bind(&done); |
| 2743 | __ mov(eax, edx); |
| 2744 | } |
| 2745 | |
| 2746 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2747 | void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 2748 | bool use_sse3, |
| 2749 | Label* not_int32) { |
| 2750 | return; |
| 2751 | } |
| 2752 | |
| 2753 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2754 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2755 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2756 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2757 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2758 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2759 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2760 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2761 | |
| 2762 | __ bind(&load_smi); |
| 2763 | __ SmiUntag(number); |
| 2764 | __ push(number); |
| 2765 | __ fild_s(Operand(esp, 0)); |
| 2766 | __ pop(number); |
| 2767 | |
| 2768 | __ bind(&done); |
| 2769 | } |
| 2770 | |
| 2771 | |
| 2772 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2773 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2774 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2775 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2776 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2777 | |
| 2778 | __ bind(&load_eax); |
| 2779 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2780 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2781 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2782 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2783 | |
| 2784 | __ bind(&load_smi_edx); |
| 2785 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2786 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2787 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2788 | __ jmp(&load_eax); |
| 2789 | |
| 2790 | __ bind(&load_smi_eax); |
| 2791 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2792 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2793 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2794 | |
| 2795 | __ bind(&done); |
| 2796 | } |
| 2797 | |
| 2798 | |
| 2799 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2800 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2801 | 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] | 2802 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2803 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2804 | Factory* factory = masm->isolate()->factory(); |
| 2805 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2806 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2807 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2808 | __ bind(&load_eax); |
| 2809 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2810 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2811 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2812 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2813 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2814 | __ bind(&load_smi_edx); |
| 2815 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2816 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2817 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2818 | __ jmp(&load_eax); |
| 2819 | __ bind(&load_smi_eax); |
| 2820 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2821 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2822 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2823 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | __ bind(&load_float_eax); |
| 2825 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2826 | __ bind(&done); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2831 | Register scratch) { |
| 2832 | const Register left = edx; |
| 2833 | const Register right = eax; |
| 2834 | __ mov(scratch, left); |
| 2835 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2836 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2837 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2838 | |
| 2839 | __ mov(scratch, right); |
| 2840 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2841 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2845 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2846 | Label* non_int32, |
| 2847 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2848 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, xmm2); |
| 2849 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, xmm2); |
| 2850 | } |
| 2851 | |
| 2852 | |
| 2853 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2854 | Label* non_int32, |
| 2855 | XMMRegister operand, |
| 2856 | Register scratch, |
| 2857 | XMMRegister xmm_scratch) { |
| 2858 | __ cvttsd2si(scratch, Operand(operand)); |
| 2859 | __ cvtsi2sd(xmm_scratch, scratch); |
| 2860 | __ pcmpeqd(xmm_scratch, operand); |
| 2861 | __ movmskpd(scratch, xmm_scratch); |
| 2862 | __ test(scratch, Immediate(1)); |
| 2863 | __ j(zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2867 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2868 | Register scratch, |
| 2869 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2870 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2871 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2872 | __ mov(scratch, edx); |
| 2873 | } else { |
| 2874 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2875 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2876 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2877 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2878 | __ bind(&done_load_1); |
| 2879 | |
| 2880 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2881 | __ mov(scratch, eax); |
| 2882 | } else { |
| 2883 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2884 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2885 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2886 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2887 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2888 | |
| 2889 | __ bind(&load_smi_1); |
| 2890 | __ SmiUntag(scratch); |
| 2891 | __ push(scratch); |
| 2892 | __ fild_s(Operand(esp, 0)); |
| 2893 | __ pop(scratch); |
| 2894 | __ jmp(&done_load_1); |
| 2895 | |
| 2896 | __ bind(&load_smi_2); |
| 2897 | __ SmiUntag(scratch); |
| 2898 | __ push(scratch); |
| 2899 | __ fild_s(Operand(esp, 0)); |
| 2900 | __ pop(scratch); |
| 2901 | |
| 2902 | __ bind(&done); |
| 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2907 | Register scratch) { |
| 2908 | const Register left = edx; |
| 2909 | const Register right = eax; |
| 2910 | __ mov(scratch, left); |
| 2911 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2912 | __ SmiUntag(scratch); |
| 2913 | __ push(scratch); |
| 2914 | __ fild_s(Operand(esp, 0)); |
| 2915 | |
| 2916 | __ mov(scratch, right); |
| 2917 | __ SmiUntag(scratch); |
| 2918 | __ mov(Operand(esp, 0), scratch); |
| 2919 | __ fild_s(Operand(esp, 0)); |
| 2920 | __ pop(scratch); |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2925 | Label* non_float, |
| 2926 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2927 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2928 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2929 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2930 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2932 | Factory* factory = masm->isolate()->factory(); |
| 2933 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2935 | |
| 2936 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2937 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2938 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2939 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2940 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2941 | |
| 2942 | // Fall-through: Both operands are numbers. |
| 2943 | __ bind(&done); |
| 2944 | } |
| 2945 | |
| 2946 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2947 | void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 2948 | Label* non_int32) { |
| 2949 | return; |
| 2950 | } |
| 2951 | |
| 2952 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2953 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2954 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2955 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2956 | const Register exponent = eax; |
| 2957 | const Register base = edx; |
| 2958 | const Register scratch = ecx; |
| 2959 | const XMMRegister double_result = xmm3; |
| 2960 | const XMMRegister double_base = xmm2; |
| 2961 | const XMMRegister double_exponent = xmm1; |
| 2962 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2963 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2964 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2965 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2966 | // Save 1 in double_result - we need this several times later on. |
| 2967 | __ mov(scratch, Immediate(1)); |
| 2968 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2969 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2970 | if (exponent_type_ == ON_STACK) { |
| 2971 | Label base_is_smi, unpack_exponent; |
| 2972 | // The exponent and base are supplied as arguments on the stack. |
| 2973 | // This can only happen if the stub is called from non-optimized code. |
| 2974 | // Load input parameters from stack. |
| 2975 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2976 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2977 | |
| 2978 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2979 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2980 | factory->heap_number_map()); |
| 2981 | __ j(not_equal, &call_runtime); |
| 2982 | |
| 2983 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2984 | __ jmp(&unpack_exponent, Label::kNear); |
| 2985 | |
| 2986 | __ bind(&base_is_smi); |
| 2987 | __ SmiUntag(base); |
| 2988 | __ cvtsi2sd(double_base, base); |
| 2989 | |
| 2990 | __ bind(&unpack_exponent); |
| 2991 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2992 | __ SmiUntag(exponent); |
| 2993 | __ jmp(&int_exponent); |
| 2994 | |
| 2995 | __ bind(&exponent_not_smi); |
| 2996 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2997 | factory->heap_number_map()); |
| 2998 | __ j(not_equal, &call_runtime); |
| 2999 | __ movdbl(double_exponent, |
| 3000 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3001 | } else if (exponent_type_ == TAGGED) { |
| 3002 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3003 | __ SmiUntag(exponent); |
| 3004 | __ jmp(&int_exponent); |
| 3005 | |
| 3006 | __ bind(&exponent_not_smi); |
| 3007 | __ movdbl(double_exponent, |
| 3008 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3009 | } |
| 3010 | |
| 3011 | if (exponent_type_ != INTEGER) { |
| 3012 | Label fast_power; |
| 3013 | // Detect integer exponents stored as double. |
| 3014 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3015 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3016 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3017 | __ j(equal, &call_runtime); |
| 3018 | __ cvtsi2sd(double_scratch, exponent); |
| 3019 | // Already ruled out NaNs for exponent. |
| 3020 | __ ucomisd(double_exponent, double_scratch); |
| 3021 | __ j(equal, &int_exponent); |
| 3022 | |
| 3023 | if (exponent_type_ == ON_STACK) { |
| 3024 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3025 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3026 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3027 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3028 | // Test for 0.5. |
| 3029 | // Load double_scratch with 0.5. |
| 3030 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3031 | __ movd(double_scratch, scratch); |
| 3032 | __ cvtss2sd(double_scratch, double_scratch); |
| 3033 | // Already ruled out NaNs for exponent. |
| 3034 | __ ucomisd(double_scratch, double_exponent); |
| 3035 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3036 | |
| 3037 | // Calculates square root of base. Check for the special case of |
| 3038 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3039 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3040 | // 9 bits set and the lowest 23 bits cleared. |
| 3041 | __ mov(scratch, 0xFF800000u); |
| 3042 | __ movd(double_scratch, scratch); |
| 3043 | __ cvtss2sd(double_scratch, double_scratch); |
| 3044 | __ ucomisd(double_base, double_scratch); |
| 3045 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3046 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3047 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3048 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3049 | |
| 3050 | // Set result to Infinity in the special case. |
| 3051 | __ xorps(double_result, double_result); |
| 3052 | __ subsd(double_result, double_scratch); |
| 3053 | __ jmp(&done); |
| 3054 | |
| 3055 | __ bind(&continue_sqrt); |
| 3056 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3057 | __ xorps(double_scratch, double_scratch); |
| 3058 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3059 | __ sqrtsd(double_result, double_scratch); |
| 3060 | __ jmp(&done); |
| 3061 | |
| 3062 | // Test for -0.5. |
| 3063 | __ bind(¬_plus_half); |
| 3064 | // Load double_exponent with -0.5 by substracting 1. |
| 3065 | __ subsd(double_scratch, double_result); |
| 3066 | // Already ruled out NaNs for exponent. |
| 3067 | __ ucomisd(double_scratch, double_exponent); |
| 3068 | __ j(not_equal, &fast_power, Label::kNear); |
| 3069 | |
| 3070 | // Calculates reciprocal of square root of base. Check for the special |
| 3071 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3072 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3073 | // 9 bits set and the lowest 23 bits cleared. |
| 3074 | __ mov(scratch, 0xFF800000u); |
| 3075 | __ movd(double_scratch, scratch); |
| 3076 | __ cvtss2sd(double_scratch, double_scratch); |
| 3077 | __ ucomisd(double_base, double_scratch); |
| 3078 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3079 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3080 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3081 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3082 | |
| 3083 | // Set result to 0 in the special case. |
| 3084 | __ xorps(double_result, double_result); |
| 3085 | __ jmp(&done); |
| 3086 | |
| 3087 | __ bind(&continue_rsqrt); |
| 3088 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3089 | __ xorps(double_exponent, double_exponent); |
| 3090 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3091 | __ sqrtsd(double_exponent, double_exponent); |
| 3092 | __ divsd(double_result, double_exponent); |
| 3093 | __ jmp(&done); |
| 3094 | } |
| 3095 | |
| 3096 | // Using FPU instructions to calculate power. |
| 3097 | Label fast_power_failed; |
| 3098 | __ bind(&fast_power); |
| 3099 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3100 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3101 | __ sub(esp, Immediate(kDoubleSize)); |
| 3102 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3103 | __ fld_d(Operand(esp, 0)); // E |
| 3104 | __ movdbl(Operand(esp, 0), double_base); |
| 3105 | __ fld_d(Operand(esp, 0)); // B, E |
| 3106 | |
| 3107 | // Exponent is in st(1) and base is in st(0) |
| 3108 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3109 | // FYL2X calculates st(1) * log2(st(0)) |
| 3110 | __ fyl2x(); // X |
| 3111 | __ fld(0); // X, X |
| 3112 | __ frndint(); // rnd(X), X |
| 3113 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3114 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3115 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3116 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3117 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame^] | 3118 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3119 | // FSCALE calculates st(0) * 2^st(1) |
| 3120 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame^] | 3121 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3122 | // Bail out to runtime in case of exceptions in the status word. |
| 3123 | __ fnstsw_ax(); |
| 3124 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3125 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3126 | __ fstp_d(Operand(esp, 0)); |
| 3127 | __ movdbl(double_result, Operand(esp, 0)); |
| 3128 | __ add(esp, Immediate(kDoubleSize)); |
| 3129 | __ jmp(&done); |
| 3130 | |
| 3131 | __ bind(&fast_power_failed); |
| 3132 | __ fninit(); |
| 3133 | __ add(esp, Immediate(kDoubleSize)); |
| 3134 | __ jmp(&call_runtime); |
| 3135 | } |
| 3136 | |
| 3137 | // Calculate power with integer exponent. |
| 3138 | __ bind(&int_exponent); |
| 3139 | const XMMRegister double_scratch2 = double_exponent; |
| 3140 | __ mov(scratch, exponent); // Back up exponent. |
| 3141 | __ movsd(double_scratch, double_base); // Back up base. |
| 3142 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3143 | |
| 3144 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3145 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3146 | __ test(scratch, scratch); |
| 3147 | __ j(positive, &no_neg, Label::kNear); |
| 3148 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3149 | __ bind(&no_neg); |
| 3150 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3151 | __ j(zero, &while_false, Label::kNear); |
| 3152 | __ shr(scratch, 1); |
| 3153 | // Above condition means CF==0 && ZF==0. This means that the |
| 3154 | // bit that has been shifted out is 0 and the result is not 0. |
| 3155 | __ j(above, &while_true, Label::kNear); |
| 3156 | __ movsd(double_result, double_scratch); |
| 3157 | __ j(zero, &while_false, Label::kNear); |
| 3158 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3159 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3160 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3161 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3162 | __ j(above, &while_true, Label::kNear); |
| 3163 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3164 | __ j(not_zero, &while_true); |
| 3165 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3166 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3167 | // scratch has the original value of the exponent - if the exponent is |
| 3168 | // negative, return 1/result. |
| 3169 | __ test(exponent, exponent); |
| 3170 | __ j(positive, &done); |
| 3171 | __ divsd(double_scratch2, double_result); |
| 3172 | __ movsd(double_result, double_scratch2); |
| 3173 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3174 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3175 | __ xorps(double_scratch2, double_scratch2); |
| 3176 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3177 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3178 | // and may not have contained the exponent value in the first place when the |
| 3179 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3180 | __ j(not_equal, &done); |
| 3181 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3182 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3183 | // Returning or bailing out. |
| 3184 | Counters* counters = masm->isolate()->counters(); |
| 3185 | if (exponent_type_ == ON_STACK) { |
| 3186 | // The arguments are still on the stack. |
| 3187 | __ bind(&call_runtime); |
| 3188 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3189 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3190 | // The stub is called from non-optimized code, which expects the result |
| 3191 | // as heap number in exponent. |
| 3192 | __ bind(&done); |
| 3193 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3194 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3195 | __ IncrementCounter(counters->math_pow(), 1); |
| 3196 | __ ret(2 * kPointerSize); |
| 3197 | } else { |
| 3198 | __ bind(&call_runtime); |
| 3199 | { |
| 3200 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3201 | __ PrepareCallCFunction(4, scratch); |
| 3202 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3203 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3204 | __ CallCFunction( |
| 3205 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3206 | } |
| 3207 | // Return value is in st(0) on ia32. |
| 3208 | // Store it into the (fixed) result register. |
| 3209 | __ sub(esp, Immediate(kDoubleSize)); |
| 3210 | __ fstp_d(Operand(esp, 0)); |
| 3211 | __ movdbl(double_result, Operand(esp, 0)); |
| 3212 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3213 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3214 | __ bind(&done); |
| 3215 | __ IncrementCounter(counters->math_pow(), 1); |
| 3216 | __ ret(0); |
| 3217 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3221 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3222 | // The key is in edx and the parameter count is in eax. |
| 3223 | |
| 3224 | // The displacement is used for skipping the frame pointer on the |
| 3225 | // stack. It is the offset of the last parameter (if any) relative |
| 3226 | // to the frame pointer. |
| 3227 | static const int kDisplacement = 1 * kPointerSize; |
| 3228 | |
| 3229 | // Check that the key is a smi. |
| 3230 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3231 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3232 | |
| 3233 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3234 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3235 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3236 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3237 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3238 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3239 | |
| 3240 | // Check index against formal parameters count limit passed in |
| 3241 | // through register eax. Use unsigned comparison to get negative |
| 3242 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3243 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3244 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3245 | |
| 3246 | // Read the argument from the stack and return it. |
| 3247 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3248 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3249 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3250 | __ neg(edx); |
| 3251 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3252 | __ ret(0); |
| 3253 | |
| 3254 | // Arguments adaptor case: Check index against actual arguments |
| 3255 | // limit found in the arguments adaptor frame. Use unsigned |
| 3256 | // comparison to get negative check for free. |
| 3257 | __ bind(&adaptor); |
| 3258 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3259 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3260 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3261 | |
| 3262 | // Read the argument from the stack and return it. |
| 3263 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3264 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3265 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3266 | __ neg(edx); |
| 3267 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3268 | __ ret(0); |
| 3269 | |
| 3270 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3271 | // by calling the runtime system. |
| 3272 | __ bind(&slow); |
| 3273 | __ pop(ebx); // Return address. |
| 3274 | __ push(edx); |
| 3275 | __ push(ebx); |
| 3276 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3277 | } |
| 3278 | |
| 3279 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3280 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3281 | // esp[0] : return address |
| 3282 | // esp[4] : number of parameters |
| 3283 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3284 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3285 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3286 | // Check if the calling frame is an arguments adaptor frame. |
| 3287 | Label runtime; |
| 3288 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3289 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3290 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3291 | __ j(not_equal, &runtime, Label::kNear); |
| 3292 | |
| 3293 | // Patch the arguments.length and the parameters pointer. |
| 3294 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3295 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3296 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3297 | StandardFrameConstants::kCallerSPOffset)); |
| 3298 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3299 | |
| 3300 | __ bind(&runtime); |
| 3301 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3302 | } |
| 3303 | |
| 3304 | |
| 3305 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3306 | // esp[0] : return address |
| 3307 | // esp[4] : number of parameters (tagged) |
| 3308 | // esp[8] : receiver displacement |
| 3309 | // esp[12] : function |
| 3310 | |
| 3311 | // ebx = parameter count (tagged) |
| 3312 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3313 | |
| 3314 | // Check if the calling frame is an arguments adaptor frame. |
| 3315 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3316 | // Generate* functions. |
| 3317 | Label runtime; |
| 3318 | Label adaptor_frame, try_allocate; |
| 3319 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3320 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3321 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3322 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3323 | |
| 3324 | // No adaptor, parameter count = argument count. |
| 3325 | __ mov(ecx, ebx); |
| 3326 | __ jmp(&try_allocate, Label::kNear); |
| 3327 | |
| 3328 | // We have an adaptor frame. Patch the parameters pointer. |
| 3329 | __ bind(&adaptor_frame); |
| 3330 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3331 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3332 | StandardFrameConstants::kCallerSPOffset)); |
| 3333 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3334 | |
| 3335 | // ebx = parameter count (tagged) |
| 3336 | // ecx = argument count (tagged) |
| 3337 | // esp[4] = parameter count (tagged) |
| 3338 | // esp[8] = address of receiver argument |
| 3339 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3340 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3341 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3342 | __ mov(ebx, ecx); |
| 3343 | |
| 3344 | __ bind(&try_allocate); |
| 3345 | |
| 3346 | // Save mapped parameter count. |
| 3347 | __ push(ebx); |
| 3348 | |
| 3349 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3350 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3351 | const int kParameterMapHeaderSize = |
| 3352 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3353 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3354 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3355 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3356 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3357 | __ bind(&no_parameter_map); |
| 3358 | |
| 3359 | // 2. Backing store. |
| 3360 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3361 | |
| 3362 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3363 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3364 | |
| 3365 | // Do the allocation of all three objects in one go. |
| 3366 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3367 | |
| 3368 | // eax = address of new object(s) (tagged) |
| 3369 | // ecx = argument count (tagged) |
| 3370 | // esp[0] = mapped parameter count (tagged) |
| 3371 | // esp[8] = parameter count (tagged) |
| 3372 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3373 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3374 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3375 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3376 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3377 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3378 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3379 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3380 | __ mov(edi, Operand(edi, |
| 3381 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3382 | __ jmp(©, Label::kNear); |
| 3383 | |
| 3384 | __ bind(&has_mapped_parameters); |
| 3385 | __ mov(edi, Operand(edi, |
| 3386 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3387 | __ bind(©); |
| 3388 | |
| 3389 | // eax = address of new object (tagged) |
| 3390 | // ebx = mapped parameter count (tagged) |
| 3391 | // ecx = argument count (tagged) |
| 3392 | // edi = address of boilerplate object (tagged) |
| 3393 | // esp[0] = mapped parameter count (tagged) |
| 3394 | // esp[8] = parameter count (tagged) |
| 3395 | // esp[12] = address of receiver argument |
| 3396 | // Copy the JS object part. |
| 3397 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3398 | __ mov(edx, FieldOperand(edi, i)); |
| 3399 | __ mov(FieldOperand(eax, i), edx); |
| 3400 | } |
| 3401 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3402 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3403 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3404 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3405 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3406 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3407 | edx); |
| 3408 | |
| 3409 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3410 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3411 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3412 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3413 | ecx); |
| 3414 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3415 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3416 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3417 | // backing store. |
| 3418 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3419 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3420 | |
| 3421 | // eax = address of new object (tagged) |
| 3422 | // ebx = mapped parameter count (tagged) |
| 3423 | // ecx = argument count (tagged) |
| 3424 | // edi = address of parameter map or backing store (tagged) |
| 3425 | // esp[0] = mapped parameter count (tagged) |
| 3426 | // esp[8] = parameter count (tagged) |
| 3427 | // esp[12] = address of receiver argument |
| 3428 | // Free a register. |
| 3429 | __ push(eax); |
| 3430 | |
| 3431 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3432 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3433 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3434 | __ j(zero, &skip_parameter_map); |
| 3435 | |
| 3436 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3437 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3438 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3439 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3440 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3441 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3442 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3443 | |
| 3444 | // Copy the parameter slots and the holes in the arguments. |
| 3445 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3446 | // where parameters are stored in reverse order, at |
| 3447 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3448 | // The mapped parameter thus need to get indices |
| 3449 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3450 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3451 | // We loop from right to left. |
| 3452 | Label parameters_loop, parameters_test; |
| 3453 | __ push(ecx); |
| 3454 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3455 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3456 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3457 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3458 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3459 | __ mov(edx, edi); |
| 3460 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3461 | // eax = loop variable (tagged) |
| 3462 | // ebx = mapping index (tagged) |
| 3463 | // ecx = the hole value |
| 3464 | // edx = address of parameter map (tagged) |
| 3465 | // edi = address of backing store (tagged) |
| 3466 | // esp[0] = argument count (tagged) |
| 3467 | // esp[4] = address of new object (tagged) |
| 3468 | // esp[8] = mapped parameter count (tagged) |
| 3469 | // esp[16] = parameter count (tagged) |
| 3470 | // esp[20] = address of receiver argument |
| 3471 | __ jmp(¶meters_test, Label::kNear); |
| 3472 | |
| 3473 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3474 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3475 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3476 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3477 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3478 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3479 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3480 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3481 | __ pop(ecx); |
| 3482 | |
| 3483 | __ bind(&skip_parameter_map); |
| 3484 | |
| 3485 | // ecx = argument count (tagged) |
| 3486 | // edi = address of backing store (tagged) |
| 3487 | // esp[0] = address of new object (tagged) |
| 3488 | // esp[4] = mapped parameter count (tagged) |
| 3489 | // esp[12] = parameter count (tagged) |
| 3490 | // esp[16] = address of receiver argument |
| 3491 | // Copy arguments header and remaining slots (if there are any). |
| 3492 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3493 | Immediate(FACTORY->fixed_array_map())); |
| 3494 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3495 | |
| 3496 | Label arguments_loop, arguments_test; |
| 3497 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3498 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3499 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3500 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3501 | __ jmp(&arguments_test, Label::kNear); |
| 3502 | |
| 3503 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3504 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3505 | __ mov(eax, Operand(edx, 0)); |
| 3506 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3507 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3508 | |
| 3509 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3510 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3511 | __ j(less, &arguments_loop, Label::kNear); |
| 3512 | |
| 3513 | // Restore. |
| 3514 | __ pop(eax); // Address of arguments object. |
| 3515 | __ pop(ebx); // Parameter count. |
| 3516 | |
| 3517 | // Return and remove the on-stack parameters. |
| 3518 | __ ret(3 * kPointerSize); |
| 3519 | |
| 3520 | // Do the runtime call to allocate the arguments object. |
| 3521 | __ bind(&runtime); |
| 3522 | __ pop(eax); // Remove saved parameter count. |
| 3523 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3524 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | |
| 3528 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3529 | // esp[0] : return address |
| 3530 | // esp[4] : number of parameters |
| 3531 | // esp[8] : receiver displacement |
| 3532 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3533 | |
| 3534 | // Check if the calling frame is an arguments adaptor frame. |
| 3535 | Label adaptor_frame, try_allocate, runtime; |
| 3536 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3537 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3538 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3539 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3540 | |
| 3541 | // Get the length from the frame. |
| 3542 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3543 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3544 | |
| 3545 | // Patch the arguments.length and the parameters pointer. |
| 3546 | __ bind(&adaptor_frame); |
| 3547 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3548 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3549 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3550 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3551 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3552 | |
| 3553 | // Try the new space allocation. Start out with computing the size of |
| 3554 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3555 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3556 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3557 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3558 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3559 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3560 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3561 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3562 | |
| 3563 | // Do the allocation of both objects in one go. |
| 3564 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3565 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3566 | // Get the arguments boilerplate from the current native context. |
| 3567 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3568 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3569 | const int offset = |
| 3570 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3571 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3572 | |
| 3573 | // Copy the JS object part. |
| 3574 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3575 | __ mov(ebx, FieldOperand(edi, i)); |
| 3576 | __ mov(FieldOperand(eax, i), ebx); |
| 3577 | } |
| 3578 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3579 | // 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] | 3580 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3581 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3582 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3583 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3584 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3585 | |
| 3586 | // If there are no actual arguments, we're done. |
| 3587 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3588 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3589 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3590 | |
| 3591 | // Get the parameters pointer from the stack. |
| 3592 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3593 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3594 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3595 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3596 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3597 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3598 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3599 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3600 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3601 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3602 | // Untag the length for the loop below. |
| 3603 | __ SmiUntag(ecx); |
| 3604 | |
| 3605 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3606 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3607 | __ bind(&loop); |
| 3608 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3609 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3610 | __ add(edi, Immediate(kPointerSize)); |
| 3611 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3612 | __ dec(ecx); |
| 3613 | __ j(not_zero, &loop); |
| 3614 | |
| 3615 | // Return and remove the on-stack parameters. |
| 3616 | __ bind(&done); |
| 3617 | __ ret(3 * kPointerSize); |
| 3618 | |
| 3619 | // Do the runtime call to allocate the arguments object. |
| 3620 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3621 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | |
| 3625 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3626 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3627 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3628 | // at compilation. |
| 3629 | #ifdef V8_INTERPRETED_REGEXP |
| 3630 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3631 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3632 | |
| 3633 | // Stack frame on entry. |
| 3634 | // esp[0]: return address |
| 3635 | // esp[4]: last_match_info (expected JSArray) |
| 3636 | // esp[8]: previous index |
| 3637 | // esp[12]: subject string |
| 3638 | // esp[16]: JSRegExp object |
| 3639 | |
| 3640 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3641 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3642 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3643 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3644 | |
| 3645 | Label runtime, invoke_regexp; |
| 3646 | |
| 3647 | // Ensure that a RegExp stack is allocated. |
| 3648 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3649 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3650 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3651 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3652 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3653 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3654 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3655 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | |
| 3657 | // Check that the first argument is a JSRegExp object. |
| 3658 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3659 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3660 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3661 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3662 | __ j(not_equal, &runtime); |
| 3663 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3664 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3665 | if (FLAG_debug_code) { |
| 3666 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3667 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3668 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3669 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3670 | } |
| 3671 | |
| 3672 | // ecx: RegExp data (FixedArray) |
| 3673 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3674 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3675 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3676 | __ j(not_equal, &runtime); |
| 3677 | |
| 3678 | // ecx: RegExp data (FixedArray) |
| 3679 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3680 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3681 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3682 | // uses the asumption that smis are 2 * their untagged value. |
| 3683 | STATIC_ASSERT(kSmiTag == 0); |
| 3684 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3685 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3686 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3687 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3688 | __ j(above, &runtime); |
| 3689 | |
| 3690 | // ecx: RegExp data (FixedArray) |
| 3691 | // edx: Number of capture registers |
| 3692 | // Check that the second argument is a string. |
| 3693 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3694 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3695 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3696 | __ j(NegateCondition(is_string), &runtime); |
| 3697 | // Get the length of the string to ebx. |
| 3698 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3699 | |
| 3700 | // ebx: Length of subject string as a smi |
| 3701 | // ecx: RegExp data (FixedArray) |
| 3702 | // edx: Number of capture registers |
| 3703 | // Check that the third argument is a positive smi less than the subject |
| 3704 | // string length. A negative value will be greater (unsigned comparison). |
| 3705 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3706 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3707 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3708 | __ j(above_equal, &runtime); |
| 3709 | |
| 3710 | // ecx: RegExp data (FixedArray) |
| 3711 | // edx: Number of capture registers |
| 3712 | // Check that the fourth object is a JSArray object. |
| 3713 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3714 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3715 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3716 | __ j(not_equal, &runtime); |
| 3717 | // Check that the JSArray is in fast case. |
| 3718 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3719 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3720 | Factory* factory = masm->isolate()->factory(); |
| 3721 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3722 | __ j(not_equal, &runtime); |
| 3723 | // Check that the last match info has space for the capture registers and the |
| 3724 | // additional information. |
| 3725 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3726 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3727 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3728 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3729 | __ j(greater, &runtime); |
| 3730 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3731 | // Reset offset for possibly sliced string. |
| 3732 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3733 | // ecx: RegExp data (FixedArray) |
| 3734 | // Check the representation and encoding of the subject string. |
| 3735 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3736 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3737 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3738 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3739 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3740 | __ and_(ebx, kIsNotStringMask | |
| 3741 | kStringRepresentationMask | |
| 3742 | kStringEncodingMask | |
| 3743 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3744 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3745 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3746 | // 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] | 3747 | // string type tests will succeed if subject is not a string or a short |
| 3748 | // external string. |
| 3749 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3750 | kStringRepresentationMask | |
| 3751 | kShortExternalStringMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3752 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3753 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3754 | // 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] | 3755 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3756 | // A flat cons string is a cons string where the second part is the empty |
| 3757 | // string. In that case the subject string is just the first part of the cons |
| 3758 | // string. Also in this case the first part of the cons string is known to be |
| 3759 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3760 | // 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] | 3761 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3762 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3763 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3764 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3765 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3766 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3767 | __ j(less, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3768 | __ j(equal, &external_string); |
| 3769 | |
| 3770 | // Catch non-string subject or short external string. |
| 3771 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3772 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3773 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3774 | |
| 3775 | // String is sliced. |
| 3776 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3777 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3778 | // edi: offset of sliced string, smi-tagged. |
| 3779 | // eax: parent string. |
| 3780 | __ jmp(&check_encoding, Label::kNear); |
| 3781 | // String is a cons string, check whether it is flat. |
| 3782 | __ bind(&cons_string); |
| 3783 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3784 | __ j(not_equal, &runtime); |
| 3785 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3786 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3787 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3788 | // eax: first part of cons string or parent of sliced string. |
| 3789 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3790 | // 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] | 3791 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3792 | kStringRepresentationMask | kStringEncodingMask); |
| 3793 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3794 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3795 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3796 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3797 | kStringRepresentationMask); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3798 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3799 | |
| 3800 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3801 | // eax: subject string (flat ASCII) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3802 | // ecx: RegExp data (FixedArray) |
| 3803 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3804 | __ Set(ecx, Immediate(1)); // Type is ASCII. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3805 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3806 | |
| 3807 | __ bind(&seq_two_byte_string); |
| 3808 | // eax: subject string (flat two byte) |
| 3809 | // ecx: RegExp data (FixedArray) |
| 3810 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3811 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3812 | |
| 3813 | __ bind(&check_code); |
| 3814 | // Check that the irregexp code has been generated for the actual string |
| 3815 | // 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] | 3816 | // a smi (code flushing support). |
| 3817 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3818 | |
| 3819 | // eax: subject string |
| 3820 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3821 | // 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] | 3822 | // Load used arguments before starting to push arguments for call to native |
| 3823 | // RegExp code to avoid handling changing stack height. |
| 3824 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3825 | __ SmiUntag(ebx); // Previous index from smi. |
| 3826 | |
| 3827 | // eax: subject string |
| 3828 | // ebx: previous index |
| 3829 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3830 | // 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] | 3831 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3832 | Counters* counters = masm->isolate()->counters(); |
| 3833 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3834 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3835 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3836 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3837 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3838 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3839 | // Argument 9: Pass current isolate address. |
| 3840 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3841 | Immediate(ExternalReference::isolate_address())); |
| 3842 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3843 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3844 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3845 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3846 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3847 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3848 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3849 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3850 | |
| 3851 | // Argument 6: Set the number of capture registers to zero to force global |
| 3852 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3853 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3854 | |
| 3855 | // Argument 5: static offsets vector buffer. |
| 3856 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3857 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3858 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3859 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3860 | // Argument 2: Previous index. |
| 3861 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3862 | |
| 3863 | // Argument 1: Original subject string. |
| 3864 | // The original subject is in the previous stack frame. Therefore we have to |
| 3865 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3866 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3867 | // and thereby moves up esp by one kPointerSize.) |
| 3868 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3869 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3870 | |
| 3871 | // esi: original subject string |
| 3872 | // eax: underlying subject string |
| 3873 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3874 | // 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] | 3875 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3876 | // Argument 4: End of string data |
| 3877 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3878 | // Prepare start and end index of the input. |
| 3879 | // Load the length from the original sliced string if that is the case. |
| 3880 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3881 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3882 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3883 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3884 | |
| 3885 | // ebx: start index of the input string |
| 3886 | // esi: end index of the input string |
| 3887 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3888 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3889 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3890 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3891 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3893 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3894 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3895 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3896 | |
| 3897 | __ bind(&setup_two_byte); |
| 3898 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3899 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3900 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3901 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3902 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3903 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3904 | |
| 3905 | __ bind(&setup_rest); |
| 3906 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3908 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3909 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3910 | |
| 3911 | // Drop arguments and come back to JS mode. |
| 3912 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3913 | |
| 3914 | // Check the result. |
| 3915 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3916 | __ cmp(eax, 1); |
| 3917 | // We expect exactly one result since we force the called regexp to behave |
| 3918 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3919 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3920 | Label failure; |
| 3921 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3922 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3923 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3924 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3925 | __ j(not_equal, &runtime); |
| 3926 | // Result must now be exception. If there is no pending exception already a |
| 3927 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3928 | // haven't created the exception yet. Handle that in the runtime system. |
| 3929 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3930 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3931 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3932 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3933 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3934 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3935 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3936 | // For exception, throw the exception again. |
| 3937 | |
| 3938 | // Clear the pending exception variable. |
| 3939 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3940 | |
| 3941 | // Special handling of termination exceptions which are uncatchable |
| 3942 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3943 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3944 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3945 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3946 | |
| 3947 | // Handle normal exception by following handler chain. |
| 3948 | __ Throw(eax); |
| 3949 | |
| 3950 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3951 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3952 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3953 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3954 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3955 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3956 | __ ret(4 * kPointerSize); |
| 3957 | |
| 3958 | // Load RegExp data. |
| 3959 | __ bind(&success); |
| 3960 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3961 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3962 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3963 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3964 | STATIC_ASSERT(kSmiTag == 0); |
| 3965 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3966 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3967 | |
| 3968 | // edx: Number of capture registers |
| 3969 | // Load last_match_info which is still known to be a fast case JSArray. |
| 3970 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3971 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3972 | |
| 3973 | // ebx: last_match_info backing store (FixedArray) |
| 3974 | // edx: number of capture registers |
| 3975 | // Store the capture count. |
| 3976 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3977 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3978 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3979 | // Store last subject and last input. |
| 3980 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3981 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3982 | __ RecordWriteField(ebx, |
| 3983 | RegExpImpl::kLastSubjectOffset, |
| 3984 | eax, |
| 3985 | edi, |
| 3986 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3987 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3988 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3989 | __ RecordWriteField(ebx, |
| 3990 | RegExpImpl::kLastInputOffset, |
| 3991 | eax, |
| 3992 | edi, |
| 3993 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3994 | |
| 3995 | // Get the static offsets vector filled by the native regexp code. |
| 3996 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3997 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3998 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3999 | |
| 4000 | // ebx: last_match_info backing store (FixedArray) |
| 4001 | // ecx: offsets vector |
| 4002 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4003 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4004 | // Capture register counter starts from number of capture registers and |
| 4005 | // counts down until wraping after zero. |
| 4006 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4007 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4008 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4009 | // Read the value from the static offsets vector buffer. |
| 4010 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4011 | __ SmiTag(edi); |
| 4012 | // Store the smi value in the last match info. |
| 4013 | __ mov(FieldOperand(ebx, |
| 4014 | edx, |
| 4015 | times_pointer_size, |
| 4016 | RegExpImpl::kFirstCaptureOffset), |
| 4017 | edi); |
| 4018 | __ jmp(&next_capture); |
| 4019 | __ bind(&done); |
| 4020 | |
| 4021 | // Return last match info. |
| 4022 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4023 | __ ret(4 * kPointerSize); |
| 4024 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4025 | // External string. Short external strings have already been ruled out. |
| 4026 | // eax: subject string (expected to be external) |
| 4027 | // ebx: scratch |
| 4028 | __ bind(&external_string); |
| 4029 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4030 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4031 | if (FLAG_debug_code) { |
| 4032 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4033 | // Sequential strings have already been ruled out. |
| 4034 | __ test_b(ebx, kIsIndirectStringMask); |
| 4035 | __ Assert(zero, "external string expected, but not found"); |
| 4036 | } |
| 4037 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4038 | // 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] | 4039 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4040 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4041 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4042 | __ test_b(ebx, kStringEncodingMask); |
| 4043 | __ j(not_zero, &seq_ascii_string); |
| 4044 | __ jmp(&seq_two_byte_string); |
| 4045 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4046 | // Do the runtime call to execute the regexp. |
| 4047 | __ bind(&runtime); |
| 4048 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4049 | #endif // V8_INTERPRETED_REGEXP |
| 4050 | } |
| 4051 | |
| 4052 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4053 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4054 | const int kMaxInlineLength = 100; |
| 4055 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4056 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4057 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4058 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4059 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4060 | __ j(above, &slowcase); |
| 4061 | // Smi-tagging is equivalent to multiplying by 2. |
| 4062 | STATIC_ASSERT(kSmiTag == 0); |
| 4063 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4064 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4065 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4066 | // Elements: [Map][Length][..elements..] |
| 4067 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4068 | times_half_pointer_size, |
| 4069 | ebx, // In: Number of elements (times 2, being a smi) |
| 4070 | eax, // Out: Start of allocation (tagged). |
| 4071 | ecx, // Out: End of allocation. |
| 4072 | edx, // Scratch register |
| 4073 | &slowcase, |
| 4074 | TAG_OBJECT); |
| 4075 | // eax: Start of allocated area, object-tagged. |
| 4076 | |
| 4077 | // Set JSArray map to global.regexp_result_map(). |
| 4078 | // Set empty properties FixedArray. |
| 4079 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4080 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4081 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4082 | Factory* factory = masm->isolate()->factory(); |
| 4083 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4084 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4085 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4086 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4087 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4088 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4089 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4090 | |
| 4091 | // Set input, index and length fields from arguments. |
| 4092 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4093 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4094 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4095 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4096 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4097 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4098 | |
| 4099 | // Fill out the elements FixedArray. |
| 4100 | // eax: JSArray. |
| 4101 | // ebx: FixedArray. |
| 4102 | // ecx: Number of elements in array, as smi. |
| 4103 | |
| 4104 | // Set map. |
| 4105 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4106 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4107 | // Set length. |
| 4108 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4109 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4110 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4111 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4112 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4113 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4114 | // eax: JSArray. |
| 4115 | // ecx: Number of elements to fill. |
| 4116 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4117 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4118 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4119 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4120 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4121 | __ 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] | 4122 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4123 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4124 | __ jmp(&loop); |
| 4125 | |
| 4126 | __ bind(&done); |
| 4127 | __ ret(3 * kPointerSize); |
| 4128 | |
| 4129 | __ bind(&slowcase); |
| 4130 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4131 | } |
| 4132 | |
| 4133 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4134 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4135 | Register object, |
| 4136 | Register result, |
| 4137 | Register scratch1, |
| 4138 | Register scratch2, |
| 4139 | bool object_is_smi, |
| 4140 | Label* not_found) { |
| 4141 | // Use of registers. Register result is used as a temporary. |
| 4142 | Register number_string_cache = result; |
| 4143 | Register mask = scratch1; |
| 4144 | Register scratch = scratch2; |
| 4145 | |
| 4146 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4147 | ExternalReference roots_array_start = |
| 4148 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4149 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4150 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4151 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4152 | // Make the hash mask from the length of the number string cache. It |
| 4153 | // contains two elements (number and string) for each cache entry. |
| 4154 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4155 | __ 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] | 4156 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4157 | |
| 4158 | // Calculate the entry in the number string cache. The hash value in the |
| 4159 | // number string cache for smis is just the smi value, and the hash for |
| 4160 | // doubles is the xor of the upper and lower words. See |
| 4161 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4162 | Label smi_hash_calculated; |
| 4163 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4164 | if (object_is_smi) { |
| 4165 | __ mov(scratch, object); |
| 4166 | __ SmiUntag(scratch); |
| 4167 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4168 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4169 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4170 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | __ mov(scratch, object); |
| 4172 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4173 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4174 | __ bind(¬_smi); |
| 4175 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4176 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4177 | __ j(not_equal, not_found); |
| 4178 | STATIC_ASSERT(8 == kDoubleSize); |
| 4179 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4180 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4181 | // 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] | 4182 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4183 | Register index = scratch; |
| 4184 | Register probe = mask; |
| 4185 | __ mov(probe, |
| 4186 | FieldOperand(number_string_cache, |
| 4187 | index, |
| 4188 | times_twice_pointer_size, |
| 4189 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4190 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4191 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4192 | CpuFeatures::Scope fscope(SSE2); |
| 4193 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4194 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4195 | __ ucomisd(xmm0, xmm1); |
| 4196 | } else { |
| 4197 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4198 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4199 | __ FCmp(); |
| 4200 | } |
| 4201 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4202 | __ 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] | 4203 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | __ bind(&smi_hash_calculated); |
| 4207 | // 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] | 4208 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4209 | Register index = scratch; |
| 4210 | // Check if the entry is the smi we are looking for. |
| 4211 | __ cmp(object, |
| 4212 | FieldOperand(number_string_cache, |
| 4213 | index, |
| 4214 | times_twice_pointer_size, |
| 4215 | FixedArray::kHeaderSize)); |
| 4216 | __ j(not_equal, not_found); |
| 4217 | |
| 4218 | // Get the result from the cache. |
| 4219 | __ bind(&load_result_from_cache); |
| 4220 | __ mov(result, |
| 4221 | FieldOperand(number_string_cache, |
| 4222 | index, |
| 4223 | times_twice_pointer_size, |
| 4224 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4225 | Counters* counters = masm->isolate()->counters(); |
| 4226 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | |
| 4230 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4231 | Label runtime; |
| 4232 | |
| 4233 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4234 | |
| 4235 | // Generate code to lookup number in the number string cache. |
| 4236 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4237 | __ ret(1 * kPointerSize); |
| 4238 | |
| 4239 | __ bind(&runtime); |
| 4240 | // Handle number to string in the runtime system if not found in the cache. |
| 4241 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4242 | } |
| 4243 | |
| 4244 | |
| 4245 | static int NegativeComparisonResult(Condition cc) { |
| 4246 | ASSERT(cc != equal); |
| 4247 | ASSERT((cc == less) || (cc == less_equal) |
| 4248 | || (cc == greater) || (cc == greater_equal)); |
| 4249 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4250 | } |
| 4251 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4252 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4253 | static void CheckInputType(MacroAssembler* masm, |
| 4254 | Register input, |
| 4255 | CompareIC::State expected, |
| 4256 | Label* fail) { |
| 4257 | Label ok; |
| 4258 | if (expected == CompareIC::SMI) { |
| 4259 | __ JumpIfNotSmi(input, fail); |
| 4260 | } else if (expected == CompareIC::HEAP_NUMBER) { |
| 4261 | __ JumpIfSmi(input, &ok); |
| 4262 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4263 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4264 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4265 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4266 | // We could be strict about symbol/string here, but as long as |
| 4267 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4268 | __ bind(&ok); |
| 4269 | } |
| 4270 | |
| 4271 | |
| 4272 | static void BranchIfNonSymbol(MacroAssembler* masm, |
| 4273 | Label* label, |
| 4274 | Register object, |
| 4275 | Register scratch) { |
| 4276 | __ JumpIfSmi(object, label); |
| 4277 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4278 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4279 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4280 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4281 | __ j(not_equal, label); |
| 4282 | } |
| 4283 | |
| 4284 | |
| 4285 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4286 | Label check_unequal_objects; |
| 4287 | Condition cc = GetCondition(); |
| 4288 | |
| 4289 | Label miss; |
| 4290 | CheckInputType(masm, edx, left_, &miss); |
| 4291 | CheckInputType(masm, eax, right_, &miss); |
| 4292 | |
| 4293 | // Compare two smis. |
| 4294 | Label non_smi, smi_done; |
| 4295 | __ mov(ecx, edx); |
| 4296 | __ or_(ecx, eax); |
| 4297 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4298 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4299 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4300 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4301 | __ bind(&smi_done); |
| 4302 | __ mov(eax, edx); |
| 4303 | __ ret(0); |
| 4304 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4305 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4306 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4307 | // it is certain that at least one operand isn't a smi. |
| 4308 | |
| 4309 | // Identical objects can be compared fast, but there are some tricky cases |
| 4310 | // for NaN and undefined. |
| 4311 | { |
| 4312 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4313 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4314 | __ j(not_equal, ¬_identical); |
| 4315 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4316 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4317 | // Check for undefined. undefined OP undefined is false even though |
| 4318 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4319 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4320 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4321 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4322 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4323 | __ ret(0); |
| 4324 | __ bind(&check_for_nan); |
| 4325 | } |
| 4326 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4327 | // 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] | 4328 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4329 | Label heap_number; |
| 4330 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4331 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4332 | __ j(equal, &heap_number, Label::kNear); |
| 4333 | if (cc != equal) { |
| 4334 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4335 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4336 | __ j(above_equal, ¬_identical); |
| 4337 | } |
| 4338 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4339 | __ ret(0); |
| 4340 | |
| 4341 | __ bind(&heap_number); |
| 4342 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4343 | // it's not NaN. |
| 4344 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4345 | // and not all mantissa bits (0..51) clear. |
| 4346 | // We only accept QNaNs, which have bit 51 set. |
| 4347 | // Read top bits of double representation (second word of value). |
| 4348 | |
| 4349 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4350 | // all bits in the mask are set. We only need to check the word |
| 4351 | // that contains the exponent and high bit of the mantissa. |
| 4352 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4353 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 4354 | __ Set(eax, Immediate(0)); |
| 4355 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4356 | // bits. |
| 4357 | __ add(edx, edx); |
| 4358 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4359 | if (cc == equal) { |
| 4360 | STATIC_ASSERT(EQUAL != 1); |
| 4361 | __ setcc(above_equal, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4362 | __ ret(0); |
| 4363 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4364 | Label nan; |
| 4365 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4366 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4367 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4368 | __ bind(&nan); |
| 4369 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 4370 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | __ bind(¬_identical); |
| 4374 | } |
| 4375 | |
| 4376 | // Strict equality can quickly decide whether objects are equal. |
| 4377 | // 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] | 4378 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4379 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4380 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | // If we're doing a strict equality comparison, we don't have to do |
| 4382 | // type conversion, so we generate code to do fast comparison for objects |
| 4383 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4384 | // slow-case code. |
| 4385 | // If either is a Smi (we know that not both are), then they can only |
| 4386 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4387 | STATIC_ASSERT(kSmiTag == 0); |
| 4388 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4389 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4390 | __ and_(ecx, eax); |
| 4391 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4392 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4393 | // One operand is a smi. |
| 4394 | |
| 4395 | // Check whether the non-smi is a heap number. |
| 4396 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4397 | // 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] | 4398 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4399 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4400 | __ xor_(ebx, eax); |
| 4401 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4402 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4403 | // if eax was smi, ebx is now edx, else eax. |
| 4404 | |
| 4405 | // Check if the non-smi operand is a heap number. |
| 4406 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4407 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4408 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4409 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4410 | // Return non-equal (ebx is not zero) |
| 4411 | __ mov(eax, ebx); |
| 4412 | __ ret(0); |
| 4413 | |
| 4414 | __ bind(¬_smis); |
| 4415 | // If either operand is a JSObject or an oddball value, then they are not |
| 4416 | // equal since their pointers are different |
| 4417 | // There is no test for undetectability in strict equality. |
| 4418 | |
| 4419 | // Get the type of the first operand. |
| 4420 | // 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] | 4421 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4422 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4423 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4424 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4425 | |
| 4426 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4427 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4428 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4429 | __ bind(&return_not_equal); |
| 4430 | __ ret(0); |
| 4431 | |
| 4432 | __ bind(&first_non_object); |
| 4433 | // Check for oddballs: true, false, null, undefined. |
| 4434 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4435 | __ j(equal, &return_not_equal); |
| 4436 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4437 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4438 | __ j(above_equal, &return_not_equal); |
| 4439 | |
| 4440 | // Check for oddballs: true, false, null, undefined. |
| 4441 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4442 | __ j(equal, &return_not_equal); |
| 4443 | |
| 4444 | // Fall through to the general case. |
| 4445 | __ bind(&slow); |
| 4446 | } |
| 4447 | |
| 4448 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4449 | Label non_number_comparison; |
| 4450 | Label unordered; |
| 4451 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4452 | CpuFeatures::Scope use_sse2(SSE2); |
| 4453 | CpuFeatures::Scope use_cmov(CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4454 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4455 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4456 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4457 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4458 | // Don't base result on EFLAGS when a NaN is involved. |
| 4459 | __ j(parity_even, &unordered, Label::kNear); |
| 4460 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4461 | __ mov(eax, 0); // equal |
| 4462 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4463 | __ cmov(above, eax, ecx); |
| 4464 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4465 | __ cmov(below, eax, ecx); |
| 4466 | __ ret(0); |
| 4467 | } else { |
| 4468 | FloatingPointHelper::CheckFloatOperands( |
| 4469 | masm, &non_number_comparison, ebx); |
| 4470 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4471 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4472 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4473 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4474 | // Don't base result on EFLAGS when a NaN is involved. |
| 4475 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4476 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4477 | Label below_label, above_label; |
| 4478 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4479 | __ j(below, &below_label, Label::kNear); |
| 4480 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4481 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4482 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4483 | __ ret(0); |
| 4484 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4485 | __ bind(&below_label); |
| 4486 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4487 | __ ret(0); |
| 4488 | |
| 4489 | __ bind(&above_label); |
| 4490 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4491 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4494 | // If one of the numbers was NaN, then the result is always false. |
| 4495 | // The cc is never not-equal. |
| 4496 | __ bind(&unordered); |
| 4497 | ASSERT(cc != not_equal); |
| 4498 | if (cc == less || cc == less_equal) { |
| 4499 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4500 | } else { |
| 4501 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4502 | } |
| 4503 | __ ret(0); |
| 4504 | |
| 4505 | // The number comparison code did not provide a valid result. |
| 4506 | __ bind(&non_number_comparison); |
| 4507 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4508 | // Fast negative check for symbol-to-symbol equality. |
| 4509 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4510 | if (cc == equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4511 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4512 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4513 | |
| 4514 | // We've already checked for object identity, so if both operands |
| 4515 | // are symbols they aren't equal. Register eax already holds a |
| 4516 | // non-zero value, which indicates not equal, so just return. |
| 4517 | __ ret(0); |
| 4518 | } |
| 4519 | |
| 4520 | __ bind(&check_for_strings); |
| 4521 | |
| 4522 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4523 | &check_unequal_objects); |
| 4524 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4525 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4526 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4527 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4528 | edx, |
| 4529 | eax, |
| 4530 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4531 | ebx); |
| 4532 | } else { |
| 4533 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4534 | edx, |
| 4535 | eax, |
| 4536 | ecx, |
| 4537 | ebx, |
| 4538 | edi); |
| 4539 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4540 | #ifdef DEBUG |
| 4541 | __ Abort("Unexpected fall-through from string comparison"); |
| 4542 | #endif |
| 4543 | |
| 4544 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4545 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4546 | // Non-strict equality. Objects are unequal if |
| 4547 | // they are both JSObjects and not undetectable, |
| 4548 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4549 | Label not_both_objects; |
| 4550 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4551 | // At most one is a smi, so we can test for smi by adding the two. |
| 4552 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4553 | // a heap object has the low bit clear. |
| 4554 | STATIC_ASSERT(kSmiTag == 0); |
| 4555 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4556 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4557 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4558 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4559 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4560 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4561 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4562 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4563 | // We do not bail out after this point. Both are JSObjects, and |
| 4564 | // they are equal if and only if both are undetectable. |
| 4565 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4566 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4567 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4568 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4569 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4570 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4571 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4572 | // The objects are both undetectable, so they both compare as the value |
| 4573 | // undefined, and are equal. |
| 4574 | __ Set(eax, Immediate(EQUAL)); |
| 4575 | __ bind(&return_unequal); |
| 4576 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4577 | // or return equal if we fell through to here. |
| 4578 | __ ret(0); // rax, rdx were pushed |
| 4579 | __ bind(¬_both_objects); |
| 4580 | } |
| 4581 | |
| 4582 | // Push arguments below the return address. |
| 4583 | __ pop(ecx); |
| 4584 | __ push(edx); |
| 4585 | __ push(eax); |
| 4586 | |
| 4587 | // Figure out which native to call and setup the arguments. |
| 4588 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4589 | if (cc == equal) { |
| 4590 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4591 | } else { |
| 4592 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4593 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | // Restore return address on the stack. |
| 4597 | __ push(ecx); |
| 4598 | |
| 4599 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4600 | // tagged as a small integer. |
| 4601 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4602 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4603 | __ bind(&miss); |
| 4604 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | |
| 4608 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4609 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4613 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4614 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4615 | } |
| 4616 | |
| 4617 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4618 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4619 | // Cache the called function in a global property cell. Cache states |
| 4620 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4621 | // megamorphic. |
| 4622 | // ebx : cache cell for call target |
| 4623 | // edi : the function to call |
| 4624 | Isolate* isolate = masm->isolate(); |
| 4625 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4626 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4627 | // Load the cache state into ecx. |
| 4628 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4629 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4630 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4631 | // function without changing the state. |
| 4632 | __ cmp(ecx, edi); |
| 4633 | __ j(equal, &done, Label::kNear); |
| 4634 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4635 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4636 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4637 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4638 | // megamorphic. |
| 4639 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4640 | __ j(equal, &initialize, Label::kNear); |
| 4641 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4642 | // write-barrier is needed. |
| 4643 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4644 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4645 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4646 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4647 | // An uninitialized cache is patched with the function. |
| 4648 | __ bind(&initialize); |
| 4649 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4650 | // No need for a write barrier here - cells are rescanned. |
| 4651 | |
| 4652 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4656 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4657 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4658 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4659 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4660 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4661 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4662 | // The receiver might implicitly be the global object. This is |
| 4663 | // indicated by passing the hole as the receiver to the call |
| 4664 | // function stub. |
| 4665 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4666 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4667 | // Get the receiver from the stack. |
| 4668 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4669 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4670 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4671 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4672 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4673 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4674 | __ mov(ecx, GlobalObjectOperand()); |
| 4675 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4676 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4677 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4680 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4681 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4682 | // Goto slow case if we do not have a function. |
| 4683 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4684 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4685 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4686 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4687 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4688 | } |
| 4689 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4690 | // Fast-case: Just invoke the function. |
| 4691 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4692 | |
| 4693 | if (ReceiverMightBeImplicit()) { |
| 4694 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4695 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4696 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4697 | __ InvokeFunction(edi, |
| 4698 | actual, |
| 4699 | JUMP_FUNCTION, |
| 4700 | NullCallWrapper(), |
| 4701 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4702 | __ bind(&call_as_function); |
| 4703 | } |
| 4704 | __ InvokeFunction(edi, |
| 4705 | actual, |
| 4706 | JUMP_FUNCTION, |
| 4707 | NullCallWrapper(), |
| 4708 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4709 | |
| 4710 | // Slow-case: Non-function called. |
| 4711 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4712 | if (RecordCallTarget()) { |
| 4713 | // 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] | 4714 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4715 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4716 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4717 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4718 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4719 | // Check for function proxy. |
| 4720 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4721 | __ j(not_equal, &non_function); |
| 4722 | __ pop(ecx); |
| 4723 | __ push(edi); // put proxy as additional argument under return address |
| 4724 | __ push(ecx); |
| 4725 | __ Set(eax, Immediate(argc_ + 1)); |
| 4726 | __ Set(ebx, Immediate(0)); |
| 4727 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4728 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4729 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4730 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4731 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4732 | } |
| 4733 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4734 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4735 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4736 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4737 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4738 | __ Set(eax, Immediate(argc_)); |
| 4739 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4740 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4741 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4742 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4743 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4744 | } |
| 4745 | |
| 4746 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4747 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4748 | // eax : number of arguments |
| 4749 | // ebx : cache cell for call target |
| 4750 | // edi : constructor function |
| 4751 | Label slow, non_function_call; |
| 4752 | |
| 4753 | // Check that function is not a smi. |
| 4754 | __ JumpIfSmi(edi, &non_function_call); |
| 4755 | // Check that function is a JSFunction. |
| 4756 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4757 | __ j(not_equal, &slow); |
| 4758 | |
| 4759 | if (RecordCallTarget()) { |
| 4760 | GenerateRecordCallTarget(masm); |
| 4761 | } |
| 4762 | |
| 4763 | // Jump to the function-specific construct stub. |
| 4764 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4765 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4766 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4767 | __ jmp(ebx); |
| 4768 | |
| 4769 | // edi: called object |
| 4770 | // eax: number of arguments |
| 4771 | // ecx: object map |
| 4772 | Label do_call; |
| 4773 | __ bind(&slow); |
| 4774 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4775 | __ j(not_equal, &non_function_call); |
| 4776 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4777 | __ jmp(&do_call); |
| 4778 | |
| 4779 | __ bind(&non_function_call); |
| 4780 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4781 | __ bind(&do_call); |
| 4782 | // Set expected number of arguments to zero (not changing eax). |
| 4783 | __ Set(ebx, Immediate(0)); |
| 4784 | Handle<Code> arguments_adaptor = |
| 4785 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4786 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4787 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4788 | } |
| 4789 | |
| 4790 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4791 | bool CEntryStub::NeedsImmovableCode() { |
| 4792 | return false; |
| 4793 | } |
| 4794 | |
| 4795 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4796 | bool CEntryStub::IsPregenerated() { |
| 4797 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4798 | result_size_ == 1; |
| 4799 | } |
| 4800 | |
| 4801 | |
| 4802 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4803 | CEntryStub::GenerateAheadOfTime(); |
| 4804 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4805 | // It is important that the store buffer overflow stubs are generated first. |
| 4806 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4807 | } |
| 4808 | |
| 4809 | |
| 4810 | void CodeStub::GenerateFPStubs() { |
| 4811 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4812 | Handle<Code> code = save_doubles.GetCode(); |
| 4813 | code->set_is_pregenerated(true); |
| 4814 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 4815 | } |
| 4816 | |
| 4817 | |
| 4818 | void CEntryStub::GenerateAheadOfTime() { |
| 4819 | CEntryStub stub(1, kDontSaveFPRegs); |
| 4820 | Handle<Code> code = stub.GetCode(); |
| 4821 | code->set_is_pregenerated(true); |
| 4822 | } |
| 4823 | |
| 4824 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4825 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4826 | Label* throw_normal_exception, |
| 4827 | Label* throw_termination_exception, |
| 4828 | Label* throw_out_of_memory_exception, |
| 4829 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4830 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4831 | // eax: result parameter for PerformGC, if any |
| 4832 | // ebx: pointer to C function (C callee-saved) |
| 4833 | // ebp: frame pointer (restored after C call) |
| 4834 | // esp: stack pointer (restored after C call) |
| 4835 | // edi: number of arguments including receiver (C callee-saved) |
| 4836 | // esi: pointer to the first argument (C callee-saved) |
| 4837 | |
| 4838 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4839 | |
| 4840 | // Check stack alignment. |
| 4841 | if (FLAG_debug_code) { |
| 4842 | __ CheckStackAlignment(); |
| 4843 | } |
| 4844 | |
| 4845 | if (do_gc) { |
| 4846 | // Pass failure code returned from last attempt as first argument to |
| 4847 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4848 | // stack alignment is known to be correct. This function takes one argument |
| 4849 | // which is passed on the stack, and we know that the stack has been |
| 4850 | // prepared to pass at least one argument. |
| 4851 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4852 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4853 | } |
| 4854 | |
| 4855 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4856 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4857 | if (always_allocate_scope) { |
| 4858 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4859 | } |
| 4860 | |
| 4861 | // Call C function. |
| 4862 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4863 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4864 | __ mov(Operand(esp, 2 * kPointerSize), |
| 4865 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4866 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4867 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4868 | |
| 4869 | if (always_allocate_scope) { |
| 4870 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4871 | } |
| 4872 | |
| 4873 | // Make sure we're not trying to return 'the hole' from the runtime |
| 4874 | // call as this may lead to crashes in the IC code later. |
| 4875 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4876 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4877 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4878 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4879 | __ int3(); |
| 4880 | __ bind(&okay); |
| 4881 | } |
| 4882 | |
| 4883 | // Check for failure result. |
| 4884 | Label failure_returned; |
| 4885 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4886 | __ lea(ecx, Operand(eax, 1)); |
| 4887 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4888 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4889 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4890 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4891 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4892 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4893 | |
| 4894 | // Check that there is no pending exception, otherwise we |
| 4895 | // should have returned some failure value. |
| 4896 | if (FLAG_debug_code) { |
| 4897 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4898 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4899 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4900 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4901 | // 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] | 4902 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4903 | __ int3(); |
| 4904 | __ bind(&okay); |
| 4905 | __ pop(edx); |
| 4906 | } |
| 4907 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4908 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4909 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4910 | __ ret(0); |
| 4911 | |
| 4912 | // Handling of failure. |
| 4913 | __ bind(&failure_returned); |
| 4914 | |
| 4915 | Label retry; |
| 4916 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4917 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4918 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4919 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | |
| 4921 | // Special handling of out of memory exceptions. |
| 4922 | __ cmp(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 4923 | __ j(equal, throw_out_of_memory_exception); |
| 4924 | |
| 4925 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4926 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4927 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4928 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4929 | |
| 4930 | // Special handling of termination exceptions which are uncatchable |
| 4931 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4932 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4933 | __ j(equal, throw_termination_exception); |
| 4934 | |
| 4935 | // Handle normal exception. |
| 4936 | __ jmp(throw_normal_exception); |
| 4937 | |
| 4938 | // Retry. |
| 4939 | __ bind(&retry); |
| 4940 | } |
| 4941 | |
| 4942 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4943 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4944 | // eax: number of arguments including receiver |
| 4945 | // ebx: pointer to C function (C callee-saved) |
| 4946 | // ebp: frame pointer (restored after C call) |
| 4947 | // esp: stack pointer (restored after C call) |
| 4948 | // esi: current context (C callee-saved) |
| 4949 | // edi: JS function of the caller (C callee-saved) |
| 4950 | |
| 4951 | // NOTE: Invocations of builtins may return failure objects instead |
| 4952 | // of a proper result. The builtin entry handles this by performing |
| 4953 | // a garbage collection and retrying the builtin (twice). |
| 4954 | |
| 4955 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4956 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4957 | |
| 4958 | // eax: result parameter for PerformGC, if any (setup below) |
| 4959 | // ebx: pointer to builtin function (C callee-saved) |
| 4960 | // ebp: frame pointer (restored after C call) |
| 4961 | // esp: stack pointer (restored after C call) |
| 4962 | // edi: number of arguments including receiver (C callee-saved) |
| 4963 | // esi: argv pointer (C callee-saved) |
| 4964 | |
| 4965 | Label throw_normal_exception; |
| 4966 | Label throw_termination_exception; |
| 4967 | Label throw_out_of_memory_exception; |
| 4968 | |
| 4969 | // Call into the runtime system. |
| 4970 | GenerateCore(masm, |
| 4971 | &throw_normal_exception, |
| 4972 | &throw_termination_exception, |
| 4973 | &throw_out_of_memory_exception, |
| 4974 | false, |
| 4975 | false); |
| 4976 | |
| 4977 | // Do space-specific GC and retry runtime call. |
| 4978 | GenerateCore(masm, |
| 4979 | &throw_normal_exception, |
| 4980 | &throw_termination_exception, |
| 4981 | &throw_out_of_memory_exception, |
| 4982 | true, |
| 4983 | false); |
| 4984 | |
| 4985 | // Do full GC and retry runtime call one final time. |
| 4986 | Failure* failure = Failure::InternalError(); |
| 4987 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4988 | GenerateCore(masm, |
| 4989 | &throw_normal_exception, |
| 4990 | &throw_termination_exception, |
| 4991 | &throw_out_of_memory_exception, |
| 4992 | true, |
| 4993 | true); |
| 4994 | |
| 4995 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4996 | // Set external caught exception to false. |
| 4997 | Isolate* isolate = masm->isolate(); |
| 4998 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4999 | isolate); |
| 5000 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5001 | |
| 5002 | // Set pending exception and eax to out of memory exception. |
| 5003 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5004 | isolate); |
| 5005 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 5006 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5007 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5008 | |
| 5009 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5010 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5011 | |
| 5012 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5013 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | |
| 5017 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5018 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5019 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5020 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5021 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5022 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5023 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5024 | |
| 5025 | // Push marker in two places. |
| 5026 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5027 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5028 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5029 | // Save callee-saved registers (C calling conventions). |
| 5030 | __ push(edi); |
| 5031 | __ push(esi); |
| 5032 | __ push(ebx); |
| 5033 | |
| 5034 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5035 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5036 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5037 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5038 | // 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] | 5039 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5040 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5042 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5043 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5044 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5045 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5046 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5047 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5048 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5049 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5050 | // block that sets the pending exception. |
| 5051 | __ jmp(&invoke); |
| 5052 | __ bind(&handler_entry); |
| 5053 | handler_offset_ = handler_entry.pos(); |
| 5054 | // Caught exception: Store result (exception) in the pending exception |
| 5055 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5056 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5057 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5058 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5059 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5060 | __ jmp(&exit); |
| 5061 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5062 | // Invoke: Link this frame into the handler chain. There's only one |
| 5063 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5064 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5065 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5066 | |
| 5067 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5068 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5069 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5070 | |
| 5071 | // Fake a receiver (NULL). |
| 5072 | __ push(Immediate(0)); // receiver |
| 5073 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5074 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5075 | // pop the faked function when we return. Notice that we cannot store a |
| 5076 | // reference to the trampoline code directly in this stub, because the |
| 5077 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5078 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5079 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5080 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5081 | __ mov(edx, Immediate(construct_entry)); |
| 5082 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5083 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5084 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5085 | __ mov(edx, Immediate(entry)); |
| 5086 | } |
| 5087 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5088 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5089 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5090 | |
| 5091 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5092 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5093 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5094 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5095 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5096 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5097 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5098 | __ j(not_equal, ¬_outermost_js_2); |
| 5099 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5100 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5101 | |
| 5102 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5103 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5104 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5105 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5106 | |
| 5107 | // Restore callee-saved registers (C calling conventions). |
| 5108 | __ pop(ebx); |
| 5109 | __ pop(esi); |
| 5110 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5111 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5112 | |
| 5113 | // Restore frame pointer and return. |
| 5114 | __ pop(ebp); |
| 5115 | __ ret(0); |
| 5116 | } |
| 5117 | |
| 5118 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5119 | // Generate stub code for instanceof. |
| 5120 | // This code can patch a call site inlined cache of the instance of check, |
| 5121 | // which looks like this. |
| 5122 | // |
| 5123 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5124 | // 75 0a jne <some near label> |
| 5125 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5126 | // |
| 5127 | // If call site patching is requested the stack will have the delta from the |
| 5128 | // return address to the cmp instruction just below the return address. This |
| 5129 | // also means that call site patching can only take place with arguments in |
| 5130 | // registers. TOS looks like this when call site patching is requested |
| 5131 | // |
| 5132 | // esp[0] : return address |
| 5133 | // esp[4] : delta from return address to cmp instruction |
| 5134 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5135 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5136 | // Call site inlining and patching implies arguments in registers. |
| 5137 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5138 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5139 | // Fixed register usage throughout the stub. |
| 5140 | Register object = eax; // Object (lhs). |
| 5141 | Register map = ebx; // Map of the object. |
| 5142 | Register function = edx; // Function (rhs). |
| 5143 | Register prototype = edi; // Prototype of the function. |
| 5144 | Register scratch = ecx; |
| 5145 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5146 | // Constants describing the call site code to patch. |
| 5147 | static const int kDeltaToCmpImmediate = 2; |
| 5148 | static const int kDeltaToMov = 8; |
| 5149 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5150 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5151 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5152 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5153 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5154 | ExternalReference roots_array_start = |
| 5155 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5156 | |
| 5157 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5158 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5159 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5160 | // Get the object and function - they are always both needed. |
| 5161 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5162 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5163 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5164 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5165 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5166 | |
| 5167 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5168 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5169 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5170 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5171 | // If there is a call site cache don't look in the global cache, but do the |
| 5172 | // real lookup and update the call site cache. |
| 5173 | if (!HasCallSiteInlineCheck()) { |
| 5174 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5175 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5176 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5177 | __ cmp(function, Operand::StaticArray(scratch, |
| 5178 | times_pointer_size, |
| 5179 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5180 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5181 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5182 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5183 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5184 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5185 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5186 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5187 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5188 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5189 | __ bind(&miss); |
| 5190 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5191 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5192 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5193 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5194 | |
| 5195 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5196 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5197 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5198 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5199 | // Update the global instanceof or call site inlined cache with the current |
| 5200 | // map and function. The cached answer will be set when it is known below. |
| 5201 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5202 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5203 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5204 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5205 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5206 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5207 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5208 | } else { |
| 5209 | // The constants for the code patching are based on no push instructions |
| 5210 | // at the call site. |
| 5211 | ASSERT(HasArgsInRegisters()); |
| 5212 | // Get return address and delta to inlined map check. |
| 5213 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5214 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5215 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5216 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5217 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5218 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5219 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5220 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5221 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5222 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5223 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5224 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5225 | // Loop through the prototype chain of the object looking for the function |
| 5226 | // prototype. |
| 5227 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5228 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5230 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5231 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5232 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5233 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5234 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5235 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5236 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5237 | __ jmp(&loop); |
| 5238 | |
| 5239 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5240 | if (!HasCallSiteInlineCheck()) { |
| 5241 | __ Set(eax, Immediate(0)); |
| 5242 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5243 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5244 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5245 | } else { |
| 5246 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5247 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5248 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5249 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5250 | if (FLAG_debug_code) { |
| 5251 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5252 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5253 | } |
| 5254 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5255 | if (!ReturnTrueFalseObject()) { |
| 5256 | __ Set(eax, Immediate(0)); |
| 5257 | } |
| 5258 | } |
| 5259 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5260 | |
| 5261 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5262 | if (!HasCallSiteInlineCheck()) { |
| 5263 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5264 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5265 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5266 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5267 | } else { |
| 5268 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5269 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5270 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5271 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5272 | if (FLAG_debug_code) { |
| 5273 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5274 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5275 | } |
| 5276 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5277 | if (!ReturnTrueFalseObject()) { |
| 5278 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5279 | } |
| 5280 | } |
| 5281 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5282 | |
| 5283 | Label object_not_null, object_not_null_or_smi; |
| 5284 | __ bind(¬_js_object); |
| 5285 | // Before null, smi and string value checks, check that the rhs is a function |
| 5286 | // 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] | 5287 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5288 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5289 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5290 | |
| 5291 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5292 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5293 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5294 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5295 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5296 | |
| 5297 | __ bind(&object_not_null); |
| 5298 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5299 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5300 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5301 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5302 | |
| 5303 | __ bind(&object_not_null_or_smi); |
| 5304 | // String values is not instance of anything. |
| 5305 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5306 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5307 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5308 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5309 | |
| 5310 | // Slow-case: Go through the JavaScript implementation. |
| 5311 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5312 | if (!ReturnTrueFalseObject()) { |
| 5313 | // Tail call the builtin which returns 0 or 1. |
| 5314 | if (HasArgsInRegisters()) { |
| 5315 | // Push arguments below return address. |
| 5316 | __ pop(scratch); |
| 5317 | __ push(object); |
| 5318 | __ push(function); |
| 5319 | __ push(scratch); |
| 5320 | } |
| 5321 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5322 | } else { |
| 5323 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5324 | { |
| 5325 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5326 | __ push(object); |
| 5327 | __ push(function); |
| 5328 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5329 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5330 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5331 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5332 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5333 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5334 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5335 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5336 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5337 | __ bind(&done); |
| 5338 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5339 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5343 | Register InstanceofStub::left() { return eax; } |
| 5344 | |
| 5345 | |
| 5346 | Register InstanceofStub::right() { return edx; } |
| 5347 | |
| 5348 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5349 | // ------------------------------------------------------------------------- |
| 5350 | // StringCharCodeAtGenerator |
| 5351 | |
| 5352 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5353 | // If the receiver is a smi trigger the non-string case. |
| 5354 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5355 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5356 | |
| 5357 | // Fetch the instance type of the receiver into result register. |
| 5358 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5359 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5360 | // If the receiver is not a string trigger the non-string case. |
| 5361 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5362 | __ j(not_zero, receiver_not_string_); |
| 5363 | |
| 5364 | // If the index is non-smi trigger the non-smi case. |
| 5365 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5366 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5367 | __ bind(&got_smi_index_); |
| 5368 | |
| 5369 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5370 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5371 | __ j(above_equal, index_out_of_range_); |
| 5372 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5373 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5374 | |
| 5375 | Factory* factory = masm->isolate()->factory(); |
| 5376 | StringCharLoadGenerator::Generate( |
| 5377 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5378 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5379 | __ SmiTag(result_); |
| 5380 | __ bind(&exit_); |
| 5381 | } |
| 5382 | |
| 5383 | |
| 5384 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5385 | MacroAssembler* masm, |
| 5386 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5387 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5388 | |
| 5389 | // Index is not a smi. |
| 5390 | __ bind(&index_not_smi_); |
| 5391 | // 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] | 5392 | __ CheckMap(index_, |
| 5393 | masm->isolate()->factory()->heap_number_map(), |
| 5394 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5395 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5396 | call_helper.BeforeCall(masm); |
| 5397 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5398 | __ push(index_); // Consumed by runtime conversion function. |
| 5399 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5400 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5401 | } else { |
| 5402 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5403 | // NumberToSmi discards numbers that are not exact integers. |
| 5404 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5405 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5406 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5407 | // Save the conversion result before the pop instructions below |
| 5408 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5409 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5410 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5411 | __ pop(object_); |
| 5412 | // Reload the instance type. |
| 5413 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5414 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5415 | call_helper.AfterCall(masm); |
| 5416 | // If index is still not a smi, it must be out of range. |
| 5417 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5418 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5419 | // Otherwise, return to the fast path. |
| 5420 | __ jmp(&got_smi_index_); |
| 5421 | |
| 5422 | // Call runtime. We get here when the receiver is a string and the |
| 5423 | // index is a number, but the code of getting the actual character |
| 5424 | // is too complex (e.g., when the string needs to be flattened). |
| 5425 | __ bind(&call_runtime_); |
| 5426 | call_helper.BeforeCall(masm); |
| 5427 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5428 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5429 | __ push(index_); |
| 5430 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5431 | if (!result_.is(eax)) { |
| 5432 | __ mov(result_, eax); |
| 5433 | } |
| 5434 | call_helper.AfterCall(masm); |
| 5435 | __ jmp(&exit_); |
| 5436 | |
| 5437 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5438 | } |
| 5439 | |
| 5440 | |
| 5441 | // ------------------------------------------------------------------------- |
| 5442 | // StringCharFromCodeGenerator |
| 5443 | |
| 5444 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5445 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5446 | STATIC_ASSERT(kSmiTag == 0); |
| 5447 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5448 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5449 | __ test(code_, |
| 5450 | Immediate(kSmiTagMask | |
| 5451 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5452 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5453 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5454 | Factory* factory = masm->isolate()->factory(); |
| 5455 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5456 | STATIC_ASSERT(kSmiTag == 0); |
| 5457 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5458 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5459 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5460 | __ mov(result_, FieldOperand(result_, |
| 5461 | code_, times_half_pointer_size, |
| 5462 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5463 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5464 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5465 | __ bind(&exit_); |
| 5466 | } |
| 5467 | |
| 5468 | |
| 5469 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5470 | MacroAssembler* masm, |
| 5471 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5472 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5473 | |
| 5474 | __ bind(&slow_case_); |
| 5475 | call_helper.BeforeCall(masm); |
| 5476 | __ push(code_); |
| 5477 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5478 | if (!result_.is(eax)) { |
| 5479 | __ mov(result_, eax); |
| 5480 | } |
| 5481 | call_helper.AfterCall(masm); |
| 5482 | __ jmp(&exit_); |
| 5483 | |
| 5484 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5485 | } |
| 5486 | |
| 5487 | |
| 5488 | // ------------------------------------------------------------------------- |
| 5489 | // StringCharAtGenerator |
| 5490 | |
| 5491 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5492 | char_code_at_generator_.GenerateFast(masm); |
| 5493 | char_from_code_generator_.GenerateFast(masm); |
| 5494 | } |
| 5495 | |
| 5496 | |
| 5497 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5498 | MacroAssembler* masm, |
| 5499 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5500 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5501 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5502 | } |
| 5503 | |
| 5504 | |
| 5505 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5506 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5507 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5508 | |
| 5509 | // Load the two arguments. |
| 5510 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5511 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5512 | |
| 5513 | // 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] | 5514 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5515 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5516 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5517 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | |
| 5519 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5520 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5521 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5522 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5523 | } else { |
| 5524 | // Here at least one of the arguments is definitely a string. |
| 5525 | // We convert the one that is not known to be a string. |
| 5526 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5527 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5528 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5529 | &call_builtin); |
| 5530 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5531 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5532 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5533 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5534 | &call_builtin); |
| 5535 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5536 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | // Both arguments are strings. |
| 5540 | // eax: first string |
| 5541 | // edx: second string |
| 5542 | // 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] | 5543 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5544 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5545 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5546 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5547 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5548 | // 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] | 5549 | Counters* counters = masm->isolate()->counters(); |
| 5550 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5551 | __ ret(2 * kPointerSize); |
| 5552 | __ bind(&second_not_zero_length); |
| 5553 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5554 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5555 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5556 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5557 | // First string is empty, result is second string which is in edx. |
| 5558 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5559 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5560 | __ ret(2 * kPointerSize); |
| 5561 | |
| 5562 | // Both strings are non-empty. |
| 5563 | // eax: first string |
| 5564 | // ebx: length of first string as a smi |
| 5565 | // ecx: length of second string as a smi |
| 5566 | // edx: second string |
| 5567 | // Look at the length of the result of adding the two strings. |
| 5568 | Label string_add_flat_result, longer_than_two; |
| 5569 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5570 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5571 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5572 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5573 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5574 | // Use the symbol table when adding two one character strings, as it |
| 5575 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5576 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5577 | __ j(not_equal, &longer_than_two); |
| 5578 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5579 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5580 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5581 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5582 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5583 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5584 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5585 | |
| 5586 | // Try to lookup two character string in symbol table. If it is not found |
| 5587 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5588 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5589 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5590 | masm, ebx, ecx, eax, edx, edi, |
| 5591 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5592 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5593 | __ ret(2 * kPointerSize); |
| 5594 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5595 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5596 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5597 | // Reload the arguments. |
| 5598 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5599 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5600 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5601 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5602 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5603 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5604 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5605 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5606 | // Pack both characters in ebx. |
| 5607 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5608 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5609 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5610 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5611 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5612 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5613 | |
| 5614 | __ bind(&longer_than_two); |
| 5615 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5616 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5617 | __ j(below, &string_add_flat_result); |
| 5618 | |
| 5619 | // 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] | 5620 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5621 | Label non_ascii, allocated, ascii_data; |
| 5622 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5623 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5624 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5625 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5626 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5627 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5628 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5629 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5630 | __ j(zero, &non_ascii); |
| 5631 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5632 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5633 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5634 | __ bind(&allocated); |
| 5635 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5636 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5637 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5638 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5639 | Immediate(String::kEmptyHashField)); |
| 5640 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5641 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5642 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5643 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5644 | __ ret(2 * kPointerSize); |
| 5645 | __ bind(&non_ascii); |
| 5646 | // 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] | 5647 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5648 | // ecx: first instance type AND second instance type. |
| 5649 | // edi: second instance type. |
| 5650 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5651 | __ j(not_zero, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5652 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5653 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5654 | __ jmp(&allocated); |
| 5655 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5656 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5657 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5658 | // Handle creating a flat result from either external or sequential strings. |
| 5659 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | // eax: first string |
| 5661 | // ebx: length of resulting flat string as a smi |
| 5662 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5663 | Label first_prepared, second_prepared; |
| 5664 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5665 | __ bind(&string_add_flat_result); |
| 5666 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5667 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5668 | // ecx: instance type of first string |
| 5669 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5670 | __ test_b(ecx, kStringRepresentationMask); |
| 5671 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5672 | // Rule out short external string and load string resource. |
| 5673 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5674 | __ test_b(ecx, kShortExternalStringMask); |
| 5675 | __ j(not_zero, &call_runtime); |
| 5676 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5677 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5678 | __ jmp(&first_prepared, Label::kNear); |
| 5679 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5680 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5681 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5682 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5683 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5684 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5685 | // Check whether both strings have same encoding. |
| 5686 | // edi: instance type of second string |
| 5687 | __ xor_(ecx, edi); |
| 5688 | __ test_b(ecx, kStringEncodingMask); |
| 5689 | __ j(not_zero, &call_runtime); |
| 5690 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5691 | __ test_b(edi, kStringRepresentationMask); |
| 5692 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5693 | // Rule out short external string and load string resource. |
| 5694 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5695 | __ test_b(edi, kShortExternalStringMask); |
| 5696 | __ j(not_zero, &call_runtime); |
| 5697 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5698 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5699 | __ jmp(&second_prepared, Label::kNear); |
| 5700 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5701 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5702 | __ bind(&second_prepared); |
| 5703 | |
| 5704 | // Push the addresses of both strings' first characters onto the stack. |
| 5705 | __ push(edx); |
| 5706 | __ push(eax); |
| 5707 | |
| 5708 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5709 | // edi: instance type of second string |
| 5710 | // First string and second string have the same encoding. |
| 5711 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5712 | __ test_b(edi, kStringEncodingMask); |
| 5713 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5714 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5715 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5716 | // ebx: length of resulting flat string as a smi |
| 5717 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5718 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5719 | // eax: result string |
| 5720 | __ mov(ecx, eax); |
| 5721 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5722 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5723 | // Load first argument's length and first character location. Account for |
| 5724 | // values currently on the stack when fetching arguments from it. |
| 5725 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5726 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5727 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5728 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5729 | // eax: result string |
| 5730 | // ecx: first character of result |
| 5731 | // edx: first char of first argument |
| 5732 | // edi: length of first argument |
| 5733 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5734 | // Load second argument's length and first character location. Account for |
| 5735 | // values currently on the stack when fetching arguments from it. |
| 5736 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5737 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5738 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5739 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5740 | // eax: result string |
| 5741 | // ecx: next character of result |
| 5742 | // edx: first char of second argument |
| 5743 | // edi: length of second argument |
| 5744 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5745 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5746 | __ ret(2 * kPointerSize); |
| 5747 | |
| 5748 | // Handle creating a flat two byte result. |
| 5749 | // eax: first string - known to be two byte |
| 5750 | // ebx: length of resulting flat string as a smi |
| 5751 | // edx: second string |
| 5752 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5753 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5754 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5755 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5756 | // eax: result string |
| 5757 | __ mov(ecx, eax); |
| 5758 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5759 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5760 | // Load second argument's length and first character location. Account for |
| 5761 | // values currently on the stack when fetching arguments from it. |
| 5762 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5763 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5764 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5765 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5766 | // eax: result string |
| 5767 | // ecx: first character of result |
| 5768 | // edx: first char of first argument |
| 5769 | // edi: length of first argument |
| 5770 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5771 | // Load second argument's length and first character location. Account for |
| 5772 | // values currently on the stack when fetching arguments from it. |
| 5773 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5774 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5775 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5776 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5777 | // eax: result string |
| 5778 | // ecx: next character of result |
| 5779 | // edx: first char of second argument |
| 5780 | // edi: length of second argument |
| 5781 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5782 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5783 | __ ret(2 * kPointerSize); |
| 5784 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5785 | // Recover stack pointer before jumping to runtime. |
| 5786 | __ bind(&call_runtime_drop_two); |
| 5787 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5788 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5789 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5790 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5791 | |
| 5792 | if (call_builtin.is_linked()) { |
| 5793 | __ bind(&call_builtin); |
| 5794 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5795 | } |
| 5796 | } |
| 5797 | |
| 5798 | |
| 5799 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5800 | int stack_offset, |
| 5801 | Register arg, |
| 5802 | Register scratch1, |
| 5803 | Register scratch2, |
| 5804 | Register scratch3, |
| 5805 | Label* slow) { |
| 5806 | // First check if the argument is already a string. |
| 5807 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5808 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5809 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5810 | __ j(below, &done); |
| 5811 | |
| 5812 | // Check the number to string cache. |
| 5813 | Label not_cached; |
| 5814 | __ bind(¬_string); |
| 5815 | // Puts the cached result into scratch1. |
| 5816 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5817 | arg, |
| 5818 | scratch1, |
| 5819 | scratch2, |
| 5820 | scratch3, |
| 5821 | false, |
| 5822 | ¬_cached); |
| 5823 | __ mov(arg, scratch1); |
| 5824 | __ mov(Operand(esp, stack_offset), arg); |
| 5825 | __ jmp(&done); |
| 5826 | |
| 5827 | // Check if the argument is a safe string wrapper. |
| 5828 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5829 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5830 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5831 | __ j(not_equal, slow); |
| 5832 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5833 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5834 | __ j(zero, slow); |
| 5835 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5836 | __ mov(Operand(esp, stack_offset), arg); |
| 5837 | |
| 5838 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | |
| 5842 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5843 | Register dest, |
| 5844 | Register src, |
| 5845 | Register count, |
| 5846 | Register scratch, |
| 5847 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5848 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5849 | __ bind(&loop); |
| 5850 | // This loop just copies one character at a time, as it is only used for very |
| 5851 | // short strings. |
| 5852 | if (ascii) { |
| 5853 | __ mov_b(scratch, Operand(src, 0)); |
| 5854 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5855 | __ add(src, Immediate(1)); |
| 5856 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5857 | } else { |
| 5858 | __ mov_w(scratch, Operand(src, 0)); |
| 5859 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5860 | __ add(src, Immediate(2)); |
| 5861 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5862 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5863 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | __ j(not_zero, &loop); |
| 5865 | } |
| 5866 | |
| 5867 | |
| 5868 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5869 | Register dest, |
| 5870 | Register src, |
| 5871 | Register count, |
| 5872 | Register scratch, |
| 5873 | bool ascii) { |
| 5874 | // Copy characters using rep movs of doublewords. |
| 5875 | // The destination is aligned on a 4 byte boundary because we are |
| 5876 | // copying to the beginning of a newly allocated string. |
| 5877 | ASSERT(dest.is(edi)); // rep movs destination |
| 5878 | ASSERT(src.is(esi)); // rep movs source |
| 5879 | ASSERT(count.is(ecx)); // rep movs count |
| 5880 | ASSERT(!scratch.is(dest)); |
| 5881 | ASSERT(!scratch.is(src)); |
| 5882 | ASSERT(!scratch.is(count)); |
| 5883 | |
| 5884 | // Nothing to do for zero characters. |
| 5885 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5886 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5887 | __ j(zero, &done); |
| 5888 | |
| 5889 | // Make count the number of bytes to copy. |
| 5890 | if (!ascii) { |
| 5891 | __ shl(count, 1); |
| 5892 | } |
| 5893 | |
| 5894 | // 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] | 5895 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5896 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5897 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5898 | |
| 5899 | // Copy from edi to esi using rep movs instruction. |
| 5900 | __ mov(scratch, count); |
| 5901 | __ sar(count, 2); // Number of doublewords to copy. |
| 5902 | __ cld(); |
| 5903 | __ rep_movs(); |
| 5904 | |
| 5905 | // Find number of bytes left. |
| 5906 | __ mov(count, scratch); |
| 5907 | __ and_(count, 3); |
| 5908 | |
| 5909 | // Check if there are more bytes to copy. |
| 5910 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5911 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5912 | __ j(zero, &done); |
| 5913 | |
| 5914 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5915 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | __ bind(&loop); |
| 5917 | __ mov_b(scratch, Operand(src, 0)); |
| 5918 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5919 | __ add(src, Immediate(1)); |
| 5920 | __ add(dest, Immediate(1)); |
| 5921 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5922 | __ j(not_zero, &loop); |
| 5923 | |
| 5924 | __ bind(&done); |
| 5925 | } |
| 5926 | |
| 5927 | |
| 5928 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5929 | Register c1, |
| 5930 | Register c2, |
| 5931 | Register scratch1, |
| 5932 | Register scratch2, |
| 5933 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5934 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5935 | Label* not_found) { |
| 5936 | // Register scratch3 is the general scratch register in this function. |
| 5937 | Register scratch = scratch3; |
| 5938 | |
| 5939 | // Make sure that both characters are not digits as such strings has a |
| 5940 | // 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] | 5941 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5942 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5943 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5944 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5945 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5946 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5947 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5948 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5949 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5950 | |
| 5951 | __ bind(¬_array_index); |
| 5952 | // Calculate the two character string hash. |
| 5953 | Register hash = scratch1; |
| 5954 | GenerateHashInit(masm, hash, c1, scratch); |
| 5955 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5956 | GenerateHashGetHash(masm, hash, scratch); |
| 5957 | |
| 5958 | // Collect the two characters in a register. |
| 5959 | Register chars = c1; |
| 5960 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5961 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5962 | |
| 5963 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5964 | // hash: hash of two character string. |
| 5965 | |
| 5966 | // Load the symbol table. |
| 5967 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5968 | ExternalReference roots_array_start = |
| 5969 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5970 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 5971 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5972 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5973 | |
| 5974 | // Calculate capacity mask from the symbol table capacity. |
| 5975 | Register mask = scratch2; |
| 5976 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5977 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5978 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5979 | |
| 5980 | // Registers |
| 5981 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5982 | // hash: hash of two character string |
| 5983 | // symbol_table: symbol table |
| 5984 | // mask: capacity mask |
| 5985 | // scratch: - |
| 5986 | |
| 5987 | // Perform a number of probes in the symbol table. |
| 5988 | static const int kProbes = 4; |
| 5989 | Label found_in_symbol_table; |
| 5990 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5991 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5992 | for (int i = 0; i < kProbes; i++) { |
| 5993 | // Calculate entry in symbol table. |
| 5994 | __ mov(scratch, hash); |
| 5995 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5996 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5997 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5998 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5999 | |
| 6000 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6001 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6002 | __ mov(candidate, |
| 6003 | FieldOperand(symbol_table, |
| 6004 | scratch, |
| 6005 | times_pointer_size, |
| 6006 | SymbolTable::kElementsStartOffset)); |
| 6007 | |
| 6008 | // 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] | 6009 | Factory* factory = masm->isolate()->factory(); |
| 6010 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6011 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6012 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6013 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6014 | |
| 6015 | // If length is not 2 the string is not a candidate. |
| 6016 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6017 | Immediate(Smi::FromInt(2))); |
| 6018 | __ j(not_equal, &next_probe[i]); |
| 6019 | |
| 6020 | // As we are out of registers save the mask on the stack and use that |
| 6021 | // register as a temporary. |
| 6022 | __ push(mask); |
| 6023 | Register temp = mask; |
| 6024 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6025 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6026 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6027 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6028 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6029 | temp, temp, &next_probe_pop_mask[i]); |
| 6030 | |
| 6031 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6032 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6033 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6034 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6035 | __ j(equal, &found_in_symbol_table); |
| 6036 | __ bind(&next_probe_pop_mask[i]); |
| 6037 | __ pop(mask); |
| 6038 | __ bind(&next_probe[i]); |
| 6039 | } |
| 6040 | |
| 6041 | // No matching 2 character string found by probing. |
| 6042 | __ jmp(not_found); |
| 6043 | |
| 6044 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6045 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6046 | __ bind(&found_in_symbol_table); |
| 6047 | __ pop(mask); // Pop saved mask from the stack. |
| 6048 | if (!result.is(eax)) { |
| 6049 | __ mov(eax, result); |
| 6050 | } |
| 6051 | } |
| 6052 | |
| 6053 | |
| 6054 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6055 | Register hash, |
| 6056 | Register character, |
| 6057 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6058 | // hash = (seed + character) + ((seed + character) << 10); |
| 6059 | if (Serializer::enabled()) { |
| 6060 | ExternalReference roots_array_start = |
| 6061 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6062 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6063 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6064 | times_pointer_size, |
| 6065 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6066 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6067 | __ add(scratch, character); |
| 6068 | __ mov(hash, scratch); |
| 6069 | __ shl(scratch, 10); |
| 6070 | __ add(hash, scratch); |
| 6071 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6072 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6073 | __ lea(scratch, Operand(character, seed)); |
| 6074 | __ shl(scratch, 10); |
| 6075 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6076 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6077 | // hash ^= hash >> 6; |
| 6078 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6079 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6080 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6081 | } |
| 6082 | |
| 6083 | |
| 6084 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6085 | Register hash, |
| 6086 | Register character, |
| 6087 | Register scratch) { |
| 6088 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6089 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6090 | // hash += hash << 10; |
| 6091 | __ mov(scratch, hash); |
| 6092 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6093 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6094 | // hash ^= hash >> 6; |
| 6095 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6096 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6097 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | |
| 6101 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6102 | Register hash, |
| 6103 | Register scratch) { |
| 6104 | // hash += hash << 3; |
| 6105 | __ mov(scratch, hash); |
| 6106 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6107 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6108 | // hash ^= hash >> 11; |
| 6109 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6110 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6111 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6112 | // hash += hash << 15; |
| 6113 | __ mov(scratch, hash); |
| 6114 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6115 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6116 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6117 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6118 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6119 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6120 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6121 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6122 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6123 | __ bind(&hash_not_zero); |
| 6124 | } |
| 6125 | |
| 6126 | |
| 6127 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6128 | Label runtime; |
| 6129 | |
| 6130 | // Stack frame on entry. |
| 6131 | // esp[0]: return address |
| 6132 | // esp[4]: to |
| 6133 | // esp[8]: from |
| 6134 | // esp[12]: string |
| 6135 | |
| 6136 | // Make sure first argument is a string. |
| 6137 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6138 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6139 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6140 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6141 | __ j(NegateCondition(is_string), &runtime); |
| 6142 | |
| 6143 | // eax: string |
| 6144 | // ebx: instance type |
| 6145 | |
| 6146 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6147 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6148 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6149 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6150 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6151 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6152 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6153 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6154 | // Shorter than original string's length: an actual substring. |
| 6155 | __ j(below, ¬_original_string, Label::kNear); |
| 6156 | // Longer than original string's length or negative: unsafe arguments. |
| 6157 | __ j(above, &runtime); |
| 6158 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6159 | Counters* counters = masm->isolate()->counters(); |
| 6160 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6161 | __ ret(3 * kPointerSize); |
| 6162 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6163 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6164 | // eax: string |
| 6165 | // ebx: instance type |
| 6166 | // ecx: sub string length (smi) |
| 6167 | // edx: from index (smi) |
| 6168 | // Deal with different string types: update the index if necessary |
| 6169 | // and put the underlying string into edi. |
| 6170 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6171 | // If the string is not indirect, it can only be sequential or external. |
| 6172 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6173 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6174 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6175 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6176 | |
| 6177 | Factory* factory = masm->isolate()->factory(); |
| 6178 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6179 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6180 | // Cons string. Check whether it is flat, then fetch first part. |
| 6181 | // Flat cons strings have an empty second part. |
| 6182 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6183 | factory->empty_string()); |
| 6184 | __ j(not_equal, &runtime); |
| 6185 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6186 | // Update instance type. |
| 6187 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6188 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6189 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6190 | |
| 6191 | __ bind(&sliced_string); |
| 6192 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6193 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6194 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6195 | // Update instance type. |
| 6196 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6197 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6198 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6199 | |
| 6200 | __ bind(&seq_or_external_string); |
| 6201 | // Sequential or external string. Just move string to the expected register. |
| 6202 | __ mov(edi, eax); |
| 6203 | |
| 6204 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6205 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6206 | if (FLAG_string_slices) { |
| 6207 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6208 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6209 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6210 | // edx: adjusted start index (smi) |
| 6211 | // ecx: length (smi) |
| 6212 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6213 | // Short slice. Copy instead of slicing. |
| 6214 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6215 | // Allocate new sliced string. At this point we do not reload the instance |
| 6216 | // type including the string encoding because we simply rely on the info |
| 6217 | // provided by the original string. It does not matter if the original |
| 6218 | // string's encoding is wrong because we always have to recheck encoding of |
| 6219 | // the newly created string's parent anyways due to externalized strings. |
| 6220 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6221 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6222 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6223 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6224 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6225 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6226 | __ jmp(&set_slice_header, Label::kNear); |
| 6227 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6228 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6229 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6230 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6231 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6232 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6233 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6234 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6235 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6236 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6237 | |
| 6238 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6241 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6242 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6243 | // edx: adjusted start index (smi) |
| 6244 | // ecx: length (smi) |
| 6245 | // The subject string can only be external or sequential string of either |
| 6246 | // encoding at this point. |
| 6247 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6248 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6249 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6250 | __ test_b(ebx, kExternalStringTag); |
| 6251 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6252 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6253 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6254 | // Rule out short external strings. |
| 6255 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6256 | __ test_b(ebx, kShortExternalStringMask); |
| 6257 | __ j(not_zero, &runtime); |
| 6258 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6259 | // 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] | 6260 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6261 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6262 | |
| 6263 | __ bind(&sequential_string); |
| 6264 | // Stash away (adjusted) index and (underlying) string. |
| 6265 | __ push(edx); |
| 6266 | __ push(edi); |
| 6267 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6268 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6269 | __ test_b(ebx, kStringEncodingMask); |
| 6270 | __ j(zero, &two_byte_sequential); |
| 6271 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6272 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6273 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | |
| 6275 | // eax: result string |
| 6276 | // ecx: result string length |
| 6277 | __ mov(edx, esi); // esi used by following code. |
| 6278 | // Locate first character of result. |
| 6279 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6280 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6281 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6282 | __ pop(esi); |
| 6283 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6284 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6285 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6286 | |
| 6287 | // eax: result string |
| 6288 | // ecx: result length |
| 6289 | // edx: original value of esi |
| 6290 | // edi: first character of result |
| 6291 | // esi: character of sub string start |
| 6292 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6293 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6294 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6295 | __ ret(3 * kPointerSize); |
| 6296 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6297 | __ bind(&two_byte_sequential); |
| 6298 | // Sequential two-byte string. Allocate the result. |
| 6299 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | |
| 6301 | // eax: result string |
| 6302 | // ecx: result string length |
| 6303 | __ mov(edx, esi); // esi used by following code. |
| 6304 | // Locate first character of result. |
| 6305 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6306 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6307 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6308 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6309 | __ pop(esi); |
| 6310 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6311 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6312 | // byte character. |
| 6313 | STATIC_ASSERT(kSmiTag == 0); |
| 6314 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6315 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6316 | |
| 6317 | // eax: result string |
| 6318 | // ecx: result length |
| 6319 | // edx: original value of esi |
| 6320 | // edi: first character of result |
| 6321 | // esi: character of sub string start |
| 6322 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6323 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6324 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6325 | __ ret(3 * kPointerSize); |
| 6326 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6327 | // Drop pushed values on the stack before tail call. |
| 6328 | __ bind(&runtime_drop_two); |
| 6329 | __ Drop(2); |
| 6330 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6331 | // Just jump to runtime to create the sub string. |
| 6332 | __ bind(&runtime); |
| 6333 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6334 | } |
| 6335 | |
| 6336 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6337 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6338 | Register left, |
| 6339 | Register right, |
| 6340 | Register scratch1, |
| 6341 | Register scratch2) { |
| 6342 | Register length = scratch1; |
| 6343 | |
| 6344 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6345 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6346 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6347 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6348 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6349 | __ bind(&strings_not_equal); |
| 6350 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6351 | __ ret(0); |
| 6352 | |
| 6353 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6354 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6355 | __ bind(&check_zero_length); |
| 6356 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6357 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6358 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6359 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6360 | __ ret(0); |
| 6361 | |
| 6362 | // Compare characters. |
| 6363 | __ bind(&compare_chars); |
| 6364 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6365 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6366 | |
| 6367 | // Characters are equal. |
| 6368 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6369 | __ ret(0); |
| 6370 | } |
| 6371 | |
| 6372 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6373 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6374 | Register left, |
| 6375 | Register right, |
| 6376 | Register scratch1, |
| 6377 | Register scratch2, |
| 6378 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6379 | Counters* counters = masm->isolate()->counters(); |
| 6380 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6381 | |
| 6382 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6383 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6384 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6385 | __ mov(scratch3, scratch1); |
| 6386 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6387 | |
| 6388 | Register length_delta = scratch3; |
| 6389 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6390 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6391 | // 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] | 6392 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6393 | __ bind(&left_shorter); |
| 6394 | |
| 6395 | Register min_length = scratch1; |
| 6396 | |
| 6397 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6398 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6399 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6400 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6401 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6402 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6403 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6404 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6405 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6406 | |
| 6407 | // Compare lengths - strings up to min-length are equal. |
| 6408 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6409 | __ test(length_delta, length_delta); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6410 | __ j(not_zero, &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6411 | |
| 6412 | // Result is EQUAL. |
| 6413 | STATIC_ASSERT(EQUAL == 0); |
| 6414 | STATIC_ASSERT(kSmiTag == 0); |
| 6415 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6416 | __ ret(0); |
| 6417 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6418 | Label result_greater; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6419 | __ bind(&result_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6420 | __ j(greater, &result_greater, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6421 | |
| 6422 | // Result is LESS. |
| 6423 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6424 | __ ret(0); |
| 6425 | |
| 6426 | // Result is GREATER. |
| 6427 | __ bind(&result_greater); |
| 6428 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6429 | __ ret(0); |
| 6430 | } |
| 6431 | |
| 6432 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6433 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6434 | MacroAssembler* masm, |
| 6435 | Register left, |
| 6436 | Register right, |
| 6437 | Register length, |
| 6438 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6439 | Label* chars_not_equal, |
| 6440 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6441 | // Change index to run from -length to -1 by adding length to string |
| 6442 | // start. This means that loop ends when index reaches zero, which |
| 6443 | // doesn't need an additional compare. |
| 6444 | __ SmiUntag(length); |
| 6445 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6446 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6447 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6448 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6449 | __ neg(length); |
| 6450 | Register index = length; // index = -length; |
| 6451 | |
| 6452 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6453 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6454 | __ bind(&loop); |
| 6455 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6456 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6457 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6458 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6459 | __ j(not_zero, &loop); |
| 6460 | } |
| 6461 | |
| 6462 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6463 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6464 | Label runtime; |
| 6465 | |
| 6466 | // Stack frame on entry. |
| 6467 | // esp[0]: return address |
| 6468 | // esp[4]: right string |
| 6469 | // esp[8]: left string |
| 6470 | |
| 6471 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6472 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6473 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6474 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6475 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6476 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6477 | STATIC_ASSERT(EQUAL == 0); |
| 6478 | STATIC_ASSERT(kSmiTag == 0); |
| 6479 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6480 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6481 | __ ret(2 * kPointerSize); |
| 6482 | |
| 6483 | __ bind(¬_same); |
| 6484 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6485 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6486 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6487 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6488 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6489 | // Drop arguments from the stack. |
| 6490 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6491 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6492 | __ push(ecx); |
| 6493 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6494 | |
| 6495 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6496 | // tagged as a small integer. |
| 6497 | __ bind(&runtime); |
| 6498 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6499 | } |
| 6500 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6501 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6502 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6503 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6504 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6505 | __ mov(ecx, edx); |
| 6506 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6507 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6508 | |
| 6509 | if (GetCondition() == equal) { |
| 6510 | // 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] | 6511 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6512 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6513 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6514 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6515 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6516 | // Correct sign of result in case of overflow. |
| 6517 | __ not_(edx); |
| 6518 | __ bind(&done); |
| 6519 | __ mov(eax, edx); |
| 6520 | } |
| 6521 | __ ret(0); |
| 6522 | |
| 6523 | __ bind(&miss); |
| 6524 | GenerateMiss(masm); |
| 6525 | } |
| 6526 | |
| 6527 | |
| 6528 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6529 | ASSERT(state_ == CompareIC::HEAP_NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6530 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6531 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6532 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6533 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6534 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6535 | if (left_ == CompareIC::SMI) { |
| 6536 | __ JumpIfNotSmi(edx, &miss); |
| 6537 | } |
| 6538 | if (right_ == CompareIC::SMI) { |
| 6539 | __ JumpIfNotSmi(eax, &miss); |
| 6540 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6541 | |
| 6542 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6543 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6544 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6545 | CpuFeatures::Scope scope1(SSE2); |
| 6546 | CpuFeatures::Scope scope2(CMOV); |
| 6547 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6548 | // Load left and right operand. |
| 6549 | Label done, left, left_smi, right_smi; |
| 6550 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6551 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6552 | masm->isolate()->factory()->heap_number_map()); |
| 6553 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6554 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6555 | __ jmp(&left, Label::kNear); |
| 6556 | __ bind(&right_smi); |
| 6557 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6558 | __ SmiUntag(ecx); |
| 6559 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6560 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6561 | __ bind(&left); |
| 6562 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6563 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6564 | masm->isolate()->factory()->heap_number_map()); |
| 6565 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6566 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6567 | __ jmp(&done); |
| 6568 | __ bind(&left_smi); |
| 6569 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6570 | __ SmiUntag(ecx); |
| 6571 | __ cvtsi2sd(xmm0, ecx); |
| 6572 | |
| 6573 | __ bind(&done); |
| 6574 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6575 | __ ucomisd(xmm0, xmm1); |
| 6576 | |
| 6577 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6578 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6579 | |
| 6580 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6581 | // Performing mov, because xor would destroy the flag register. |
| 6582 | __ mov(eax, 0); // equal |
| 6583 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6584 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6585 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6586 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6587 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6588 | } else { |
| 6589 | __ mov(ecx, edx); |
| 6590 | __ and_(ecx, eax); |
| 6591 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6592 | |
| 6593 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6594 | masm->isolate()->factory()->heap_number_map()); |
| 6595 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6596 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6597 | masm->isolate()->factory()->heap_number_map()); |
| 6598 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6599 | } |
| 6600 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6601 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6602 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6603 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6604 | CompareIC::GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6605 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6606 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6607 | __ bind(&maybe_undefined1); |
| 6608 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6609 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6610 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6611 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6612 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6613 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6614 | __ jmp(&unordered); |
| 6615 | } |
| 6616 | |
| 6617 | __ bind(&maybe_undefined2); |
| 6618 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6619 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6620 | __ j(equal, &unordered); |
| 6621 | } |
| 6622 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6623 | __ bind(&miss); |
| 6624 | GenerateMiss(masm); |
| 6625 | } |
| 6626 | |
| 6627 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6628 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6629 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6630 | ASSERT(GetCondition() == equal); |
| 6631 | |
| 6632 | // Registers containing left and right operands respectively. |
| 6633 | Register left = edx; |
| 6634 | Register right = eax; |
| 6635 | Register tmp1 = ecx; |
| 6636 | Register tmp2 = ebx; |
| 6637 | |
| 6638 | // Check that both operands are heap objects. |
| 6639 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6640 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6641 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6642 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6643 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6644 | |
| 6645 | // Check that both operands are symbols. |
| 6646 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6647 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6648 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6649 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6650 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6651 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6652 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6653 | __ j(zero, &miss, Label::kNear); |
| 6654 | |
| 6655 | // Symbols are compared by identity. |
| 6656 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6657 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6658 | // Make sure eax is non-zero. At this point input operands are |
| 6659 | // guaranteed to be non-zero. |
| 6660 | ASSERT(right.is(eax)); |
| 6661 | __ j(not_equal, &done, Label::kNear); |
| 6662 | STATIC_ASSERT(EQUAL == 0); |
| 6663 | STATIC_ASSERT(kSmiTag == 0); |
| 6664 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6665 | __ bind(&done); |
| 6666 | __ ret(0); |
| 6667 | |
| 6668 | __ bind(&miss); |
| 6669 | GenerateMiss(masm); |
| 6670 | } |
| 6671 | |
| 6672 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6673 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6674 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6675 | Label miss; |
| 6676 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6677 | bool equality = Token::IsEqualityOp(op_); |
| 6678 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6679 | // Registers containing left and right operands respectively. |
| 6680 | Register left = edx; |
| 6681 | Register right = eax; |
| 6682 | Register tmp1 = ecx; |
| 6683 | Register tmp2 = ebx; |
| 6684 | Register tmp3 = edi; |
| 6685 | |
| 6686 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6687 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6688 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6689 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6690 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6691 | |
| 6692 | // Check that both operands are strings. This leaves the instance |
| 6693 | // types loaded in tmp1 and tmp2. |
| 6694 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6695 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6696 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6697 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6698 | __ mov(tmp3, tmp1); |
| 6699 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6700 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6701 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6702 | __ j(not_zero, &miss); |
| 6703 | |
| 6704 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6705 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6706 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6707 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6708 | STATIC_ASSERT(EQUAL == 0); |
| 6709 | STATIC_ASSERT(kSmiTag == 0); |
| 6710 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6711 | __ ret(0); |
| 6712 | |
| 6713 | // Handle not identical strings. |
| 6714 | __ bind(¬_same); |
| 6715 | |
| 6716 | // 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] | 6717 | // because we already know they are not identical. But in the case of |
| 6718 | // non-equality compare, we still need to determine the order. |
| 6719 | if (equality) { |
| 6720 | Label do_compare; |
| 6721 | STATIC_ASSERT(kSymbolTag != 0); |
| 6722 | __ and_(tmp1, tmp2); |
| 6723 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6724 | __ j(zero, &do_compare, Label::kNear); |
| 6725 | // Make sure eax is non-zero. At this point input operands are |
| 6726 | // guaranteed to be non-zero. |
| 6727 | ASSERT(right.is(eax)); |
| 6728 | __ ret(0); |
| 6729 | __ bind(&do_compare); |
| 6730 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6731 | |
| 6732 | // Check that both strings are sequential ASCII. |
| 6733 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6734 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6735 | |
| 6736 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6737 | if (equality) { |
| 6738 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6739 | masm, left, right, tmp1, tmp2); |
| 6740 | } else { |
| 6741 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6742 | masm, left, right, tmp1, tmp2, tmp3); |
| 6743 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6744 | |
| 6745 | // Handle more complex cases in runtime. |
| 6746 | __ bind(&runtime); |
| 6747 | __ pop(tmp1); // Return address. |
| 6748 | __ push(left); |
| 6749 | __ push(right); |
| 6750 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6751 | if (equality) { |
| 6752 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6753 | } else { |
| 6754 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6755 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6756 | |
| 6757 | __ bind(&miss); |
| 6758 | GenerateMiss(masm); |
| 6759 | } |
| 6760 | |
| 6761 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6762 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6763 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6764 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6765 | __ mov(ecx, edx); |
| 6766 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6767 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6768 | |
| 6769 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6770 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6771 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6772 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6773 | |
| 6774 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6775 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6776 | __ ret(0); |
| 6777 | |
| 6778 | __ bind(&miss); |
| 6779 | GenerateMiss(masm); |
| 6780 | } |
| 6781 | |
| 6782 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6783 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6784 | Label miss; |
| 6785 | __ mov(ecx, edx); |
| 6786 | __ and_(ecx, eax); |
| 6787 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6788 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6789 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6790 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6791 | __ cmp(ecx, known_map_); |
| 6792 | __ j(not_equal, &miss, Label::kNear); |
| 6793 | __ cmp(ebx, known_map_); |
| 6794 | __ j(not_equal, &miss, Label::kNear); |
| 6795 | |
| 6796 | __ sub(eax, edx); |
| 6797 | __ ret(0); |
| 6798 | |
| 6799 | __ bind(&miss); |
| 6800 | GenerateMiss(masm); |
| 6801 | } |
| 6802 | |
| 6803 | |
| 6804 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6805 | { |
| 6806 | // Call the runtime system in a fresh internal frame. |
| 6807 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6808 | masm->isolate()); |
| 6809 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6810 | __ push(edx); // Preserve edx and eax. |
| 6811 | __ push(eax); |
| 6812 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6813 | __ push(eax); |
| 6814 | __ push(Immediate(Smi::FromInt(op_))); |
| 6815 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6816 | // Compute the entry point of the rewritten stub. |
| 6817 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6818 | __ pop(eax); |
| 6819 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6820 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6821 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6822 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6823 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6827 | // Helper function used to check that the dictionary doesn't contain |
| 6828 | // the property. This function may return false negatives, so miss_label |
| 6829 | // must always call a backup property check that is complete. |
| 6830 | // This function is safe to call if the receiver has fast properties. |
| 6831 | // 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] | 6832 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6833 | Label* miss, |
| 6834 | Label* done, |
| 6835 | Register properties, |
| 6836 | Handle<String> name, |
| 6837 | Register r0) { |
| 6838 | ASSERT(name->IsSymbol()); |
| 6839 | |
| 6840 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6841 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6842 | // undefined value), it guarantees the hash table doesn't contain the |
| 6843 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6844 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6845 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6846 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6847 | Register index = r0; |
| 6848 | // Capacity is smi 2^n. |
| 6849 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6850 | __ dec(index); |
| 6851 | __ and_(index, |
| 6852 | Immediate(Smi::FromInt(name->Hash() + |
| 6853 | StringDictionary::GetProbeOffset(i)))); |
| 6854 | |
| 6855 | // Scale the index by multiplying by the entry size. |
| 6856 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6857 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6858 | Register entity_name = r0; |
| 6859 | // Having undefined at this place means the name is not contained. |
| 6860 | ASSERT_EQ(kSmiTagSize, 1); |
| 6861 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6862 | kElementsStartOffset - kHeapObjectTag)); |
| 6863 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6864 | __ j(equal, done); |
| 6865 | |
| 6866 | // Stop if found the property. |
| 6867 | __ cmp(entity_name, Handle<String>(name)); |
| 6868 | __ j(equal, miss); |
| 6869 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6870 | Label the_hole; |
| 6871 | // Check for the hole and skip. |
| 6872 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 6873 | __ j(equal, &the_hole, Label::kNear); |
| 6874 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6875 | // Check if the entry name is not a symbol. |
| 6876 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6877 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6878 | kIsSymbolMask); |
| 6879 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6880 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | StringDictionaryLookupStub stub(properties, |
| 6884 | r0, |
| 6885 | r0, |
| 6886 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6887 | __ push(Immediate(Handle<Object>(name))); |
| 6888 | __ push(Immediate(name->Hash())); |
| 6889 | __ CallStub(&stub); |
| 6890 | __ test(r0, r0); |
| 6891 | __ j(not_zero, miss); |
| 6892 | __ jmp(done); |
| 6893 | } |
| 6894 | |
| 6895 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6896 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6897 | // |done| label if a property with the given name is found leaving the |
| 6898 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6899 | // otherwise. |
| 6900 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6901 | Label* miss, |
| 6902 | Label* done, |
| 6903 | Register elements, |
| 6904 | Register name, |
| 6905 | Register r0, |
| 6906 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6907 | ASSERT(!elements.is(r0)); |
| 6908 | ASSERT(!elements.is(r1)); |
| 6909 | ASSERT(!name.is(r0)); |
| 6910 | ASSERT(!name.is(r1)); |
| 6911 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6912 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6913 | |
| 6914 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6915 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6916 | __ dec(r1); |
| 6917 | |
| 6918 | // Generate an unrolled loop that performs a few probes before |
| 6919 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6920 | // cover ~93% of loads from dictionaries. |
| 6921 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6922 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6923 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6924 | __ shr(r0, String::kHashShift); |
| 6925 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6926 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6927 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6928 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6929 | |
| 6930 | // Scale the index by multiplying by the entry size. |
| 6931 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6932 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6933 | |
| 6934 | // Check if the key is identical to the name. |
| 6935 | __ cmp(name, Operand(elements, |
| 6936 | r0, |
| 6937 | times_4, |
| 6938 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6939 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | StringDictionaryLookupStub stub(elements, |
| 6943 | r1, |
| 6944 | r0, |
| 6945 | POSITIVE_LOOKUP); |
| 6946 | __ push(name); |
| 6947 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6948 | __ shr(r0, String::kHashShift); |
| 6949 | __ push(r0); |
| 6950 | __ CallStub(&stub); |
| 6951 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6952 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6953 | __ j(zero, miss); |
| 6954 | __ jmp(done); |
| 6955 | } |
| 6956 | |
| 6957 | |
| 6958 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6959 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6960 | // 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] | 6961 | // Stack frame on entry: |
| 6962 | // esp[0 * kPointerSize]: return address. |
| 6963 | // esp[1 * kPointerSize]: key's hash. |
| 6964 | // esp[2 * kPointerSize]: key. |
| 6965 | // Registers: |
| 6966 | // dictionary_: StringDictionary to probe. |
| 6967 | // result_: used as scratch. |
| 6968 | // index_: will hold an index of entry if lookup is successful. |
| 6969 | // might alias with result_. |
| 6970 | // Returns: |
| 6971 | // result_ is zero if lookup failed, non zero otherwise. |
| 6972 | |
| 6973 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6974 | |
| 6975 | Register scratch = result_; |
| 6976 | |
| 6977 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6978 | __ dec(scratch); |
| 6979 | __ SmiUntag(scratch); |
| 6980 | __ push(scratch); |
| 6981 | |
| 6982 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6983 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6984 | // undefined value), it guarantees the hash table doesn't contain the |
| 6985 | // property. It's true even if some slots represent deleted properties |
| 6986 | // (their names are the null value). |
| 6987 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6988 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6989 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6990 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6991 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6992 | } |
| 6993 | __ and_(scratch, Operand(esp, 0)); |
| 6994 | |
| 6995 | // Scale the index by multiplying by the entry size. |
| 6996 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6997 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6998 | |
| 6999 | // Having undefined at this place means the name is not contained. |
| 7000 | ASSERT_EQ(kSmiTagSize, 1); |
| 7001 | __ mov(scratch, Operand(dictionary_, |
| 7002 | index_, |
| 7003 | times_pointer_size, |
| 7004 | kElementsStartOffset - kHeapObjectTag)); |
| 7005 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7006 | __ j(equal, ¬_in_dictionary); |
| 7007 | |
| 7008 | // Stop if found the property. |
| 7009 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7010 | __ j(equal, &in_dictionary); |
| 7011 | |
| 7012 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7013 | // If we hit a non symbol key during negative lookup |
| 7014 | // we have to bailout as this key might be equal to the |
| 7015 | // key we are looking for. |
| 7016 | |
| 7017 | // Check if the entry name is not a symbol. |
| 7018 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7019 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7020 | kIsSymbolMask); |
| 7021 | __ j(zero, &maybe_in_dictionary); |
| 7022 | } |
| 7023 | } |
| 7024 | |
| 7025 | __ bind(&maybe_in_dictionary); |
| 7026 | // If we are doing negative lookup then probing failure should be |
| 7027 | // treated as a lookup success. For positive lookup probing failure |
| 7028 | // should be treated as lookup failure. |
| 7029 | if (mode_ == POSITIVE_LOOKUP) { |
| 7030 | __ mov(result_, Immediate(0)); |
| 7031 | __ Drop(1); |
| 7032 | __ ret(2 * kPointerSize); |
| 7033 | } |
| 7034 | |
| 7035 | __ bind(&in_dictionary); |
| 7036 | __ mov(result_, Immediate(1)); |
| 7037 | __ Drop(1); |
| 7038 | __ ret(2 * kPointerSize); |
| 7039 | |
| 7040 | __ bind(¬_in_dictionary); |
| 7041 | __ mov(result_, Immediate(0)); |
| 7042 | __ Drop(1); |
| 7043 | __ ret(2 * kPointerSize); |
| 7044 | } |
| 7045 | |
| 7046 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7047 | struct AheadOfTimeWriteBarrierStubList { |
| 7048 | Register object, value, address; |
| 7049 | RememberedSetAction action; |
| 7050 | }; |
| 7051 | |
| 7052 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7053 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7054 | |
| 7055 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7056 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7057 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7058 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7059 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7060 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7061 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7062 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7063 | // Used in StoreStubCompiler::CompileStoreField and |
| 7064 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7065 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7066 | // GenerateStoreField calls the stub with two different permutations of |
| 7067 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7068 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7069 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7070 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7071 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7072 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7073 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7074 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7075 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7076 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7077 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7078 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7079 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7080 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7081 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7082 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7083 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7084 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7085 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7086 | // FastNewClosureStub |
| 7087 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7088 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7089 | { 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] | 7090 | }; |
| 7091 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7092 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7093 | |
| 7094 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7095 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7096 | !entry->object.is(no_reg); |
| 7097 | entry++) { |
| 7098 | if (object_.is(entry->object) && |
| 7099 | value_.is(entry->value) && |
| 7100 | address_.is(entry->address) && |
| 7101 | remembered_set_action_ == entry->action && |
| 7102 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7103 | return true; |
| 7104 | } |
| 7105 | } |
| 7106 | return false; |
| 7107 | } |
| 7108 | |
| 7109 | |
| 7110 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7111 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7112 | stub1.GetCode()->set_is_pregenerated(true); |
| 7113 | |
| 7114 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7115 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7116 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7117 | stub2.GetCode()->set_is_pregenerated(true); |
| 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | |
| 7122 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7123 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7124 | !entry->object.is(no_reg); |
| 7125 | entry++) { |
| 7126 | RecordWriteStub stub(entry->object, |
| 7127 | entry->value, |
| 7128 | entry->address, |
| 7129 | entry->action, |
| 7130 | kDontSaveFPRegs); |
| 7131 | stub.GetCode()->set_is_pregenerated(true); |
| 7132 | } |
| 7133 | } |
| 7134 | |
| 7135 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7136 | bool CodeStub::CanUseFPRegisters() { |
| 7137 | return CpuFeatures::IsSupported(SSE2); |
| 7138 | } |
| 7139 | |
| 7140 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7141 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7142 | // the value has just been written into the object, now this stub makes sure |
| 7143 | // we keep the GC informed. The word in the object where the value has been |
| 7144 | // written is in the address register. |
| 7145 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7146 | Label skip_to_incremental_noncompacting; |
| 7147 | Label skip_to_incremental_compacting; |
| 7148 | |
| 7149 | // The first two instructions are generated with labels so as to get the |
| 7150 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7151 | // forth between a compare instructions (a nop in this position) and the |
| 7152 | // real branch when we start and stop incremental heap marking. |
| 7153 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7154 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7155 | |
| 7156 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7157 | __ RememberedSetHelper(object_, |
| 7158 | address_, |
| 7159 | value_, |
| 7160 | save_fp_regs_mode_, |
| 7161 | MacroAssembler::kReturnAtEnd); |
| 7162 | } else { |
| 7163 | __ ret(0); |
| 7164 | } |
| 7165 | |
| 7166 | __ bind(&skip_to_incremental_noncompacting); |
| 7167 | GenerateIncremental(masm, INCREMENTAL); |
| 7168 | |
| 7169 | __ bind(&skip_to_incremental_compacting); |
| 7170 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7171 | |
| 7172 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7173 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7174 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7175 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7176 | } |
| 7177 | |
| 7178 | |
| 7179 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7180 | regs_.Save(masm); |
| 7181 | |
| 7182 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7183 | Label dont_need_remembered_set; |
| 7184 | |
| 7185 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7186 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7187 | regs_.scratch0(), |
| 7188 | &dont_need_remembered_set); |
| 7189 | |
| 7190 | __ CheckPageFlag(regs_.object(), |
| 7191 | regs_.scratch0(), |
| 7192 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7193 | not_zero, |
| 7194 | &dont_need_remembered_set); |
| 7195 | |
| 7196 | // First notify the incremental marker if necessary, then update the |
| 7197 | // remembered set. |
| 7198 | CheckNeedsToInformIncrementalMarker( |
| 7199 | masm, |
| 7200 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7201 | mode); |
| 7202 | InformIncrementalMarker(masm, mode); |
| 7203 | regs_.Restore(masm); |
| 7204 | __ RememberedSetHelper(object_, |
| 7205 | address_, |
| 7206 | value_, |
| 7207 | save_fp_regs_mode_, |
| 7208 | MacroAssembler::kReturnAtEnd); |
| 7209 | |
| 7210 | __ bind(&dont_need_remembered_set); |
| 7211 | } |
| 7212 | |
| 7213 | CheckNeedsToInformIncrementalMarker( |
| 7214 | masm, |
| 7215 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7216 | mode); |
| 7217 | InformIncrementalMarker(masm, mode); |
| 7218 | regs_.Restore(masm); |
| 7219 | __ ret(0); |
| 7220 | } |
| 7221 | |
| 7222 | |
| 7223 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7224 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7225 | int argument_count = 3; |
| 7226 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7227 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7228 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7229 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7230 | Immediate(ExternalReference::isolate_address())); |
| 7231 | |
| 7232 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7233 | if (mode == INCREMENTAL_COMPACTION) { |
| 7234 | __ CallCFunction( |
| 7235 | ExternalReference::incremental_evacuation_record_write_function( |
| 7236 | masm->isolate()), |
| 7237 | argument_count); |
| 7238 | } else { |
| 7239 | ASSERT(mode == INCREMENTAL); |
| 7240 | __ CallCFunction( |
| 7241 | ExternalReference::incremental_marking_record_write_function( |
| 7242 | masm->isolate()), |
| 7243 | argument_count); |
| 7244 | } |
| 7245 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7246 | } |
| 7247 | |
| 7248 | |
| 7249 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7250 | MacroAssembler* masm, |
| 7251 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7252 | Mode mode) { |
| 7253 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7254 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7255 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7256 | __ and_(regs_.scratch0(), regs_.object()); |
| 7257 | __ mov(regs_.scratch1(), |
| 7258 | Operand(regs_.scratch0(), |
| 7259 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7260 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7261 | __ mov(Operand(regs_.scratch0(), |
| 7262 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7263 | regs_.scratch1()); |
| 7264 | __ j(negative, &need_incremental); |
| 7265 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7266 | // Let's look at the color of the object: If it is not black we don't have |
| 7267 | // to inform the incremental marker. |
| 7268 | __ JumpIfBlack(regs_.object(), |
| 7269 | regs_.scratch0(), |
| 7270 | regs_.scratch1(), |
| 7271 | &object_is_black, |
| 7272 | Label::kNear); |
| 7273 | |
| 7274 | regs_.Restore(masm); |
| 7275 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7276 | __ RememberedSetHelper(object_, |
| 7277 | address_, |
| 7278 | value_, |
| 7279 | save_fp_regs_mode_, |
| 7280 | MacroAssembler::kReturnAtEnd); |
| 7281 | } else { |
| 7282 | __ ret(0); |
| 7283 | } |
| 7284 | |
| 7285 | __ bind(&object_is_black); |
| 7286 | |
| 7287 | // Get the value from the slot. |
| 7288 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7289 | |
| 7290 | if (mode == INCREMENTAL_COMPACTION) { |
| 7291 | Label ensure_not_white; |
| 7292 | |
| 7293 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7294 | regs_.scratch1(), // Scratch. |
| 7295 | MemoryChunk::kEvacuationCandidateMask, |
| 7296 | zero, |
| 7297 | &ensure_not_white, |
| 7298 | Label::kNear); |
| 7299 | |
| 7300 | __ CheckPageFlag(regs_.object(), |
| 7301 | regs_.scratch1(), // Scratch. |
| 7302 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7303 | not_zero, |
| 7304 | &ensure_not_white, |
| 7305 | Label::kNear); |
| 7306 | |
| 7307 | __ jmp(&need_incremental); |
| 7308 | |
| 7309 | __ bind(&ensure_not_white); |
| 7310 | } |
| 7311 | |
| 7312 | // We need an extra register for this, so we push the object register |
| 7313 | // temporarily. |
| 7314 | __ push(regs_.object()); |
| 7315 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7316 | regs_.scratch1(), // Scratch. |
| 7317 | regs_.object(), // Scratch. |
| 7318 | &need_incremental_pop_object, |
| 7319 | Label::kNear); |
| 7320 | __ pop(regs_.object()); |
| 7321 | |
| 7322 | regs_.Restore(masm); |
| 7323 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7324 | __ RememberedSetHelper(object_, |
| 7325 | address_, |
| 7326 | value_, |
| 7327 | save_fp_regs_mode_, |
| 7328 | MacroAssembler::kReturnAtEnd); |
| 7329 | } else { |
| 7330 | __ ret(0); |
| 7331 | } |
| 7332 | |
| 7333 | __ bind(&need_incremental_pop_object); |
| 7334 | __ pop(regs_.object()); |
| 7335 | |
| 7336 | __ bind(&need_incremental); |
| 7337 | |
| 7338 | // Fall through when we need to inform the incremental marker. |
| 7339 | } |
| 7340 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7341 | |
| 7342 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7343 | // ----------- S t a t e ------------- |
| 7344 | // -- eax : element value to store |
| 7345 | // -- ebx : array literal |
| 7346 | // -- edi : map of array literal |
| 7347 | // -- ecx : element index as smi |
| 7348 | // -- edx : array literal index in function |
| 7349 | // -- esp[0] : return address |
| 7350 | // ----------------------------------- |
| 7351 | |
| 7352 | Label element_done; |
| 7353 | Label double_elements; |
| 7354 | Label smi_element; |
| 7355 | Label slow_elements; |
| 7356 | Label slow_elements_from_double; |
| 7357 | Label fast_elements; |
| 7358 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7359 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7360 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7361 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7362 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7363 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7364 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7365 | // Store into the array literal requires a elements transition. Call into |
| 7366 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7367 | |
| 7368 | __ bind(&slow_elements); |
| 7369 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7370 | // call. |
| 7371 | __ push(ebx); |
| 7372 | __ push(ecx); |
| 7373 | __ push(eax); |
| 7374 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7375 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7376 | __ push(edx); |
| 7377 | __ push(edi); // Return return address so that tail call returns to right |
| 7378 | // place. |
| 7379 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7380 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7381 | __ bind(&slow_elements_from_double); |
| 7382 | __ pop(edx); |
| 7383 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7384 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7385 | // 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] | 7386 | __ bind(&fast_elements); |
| 7387 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7388 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7389 | FixedArrayBase::kHeaderSize)); |
| 7390 | __ mov(Operand(ecx, 0), eax); |
| 7391 | // Update the write barrier for the array store. |
| 7392 | __ RecordWrite(ebx, ecx, eax, |
| 7393 | kDontSaveFPRegs, |
| 7394 | EMIT_REMEMBERED_SET, |
| 7395 | OMIT_SMI_CHECK); |
| 7396 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7397 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7398 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7399 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7400 | __ bind(&smi_element); |
| 7401 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7402 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7403 | FixedArrayBase::kHeaderSize), eax); |
| 7404 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7405 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7406 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7407 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7408 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7409 | __ push(edx); |
| 7410 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7411 | __ StoreNumberToDoubleElements(eax, |
| 7412 | edx, |
| 7413 | ecx, |
| 7414 | edi, |
| 7415 | xmm0, |
| 7416 | &slow_elements_from_double, |
| 7417 | false); |
| 7418 | __ pop(edx); |
| 7419 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7422 | |
| 7423 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7424 | if (entry_hook_ != NULL) { |
| 7425 | ProfileEntryHookStub stub; |
| 7426 | masm->CallStub(&stub); |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | |
| 7431 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7432 | // Ecx is the only volatile register we must save. |
| 7433 | __ push(ecx); |
| 7434 | |
| 7435 | // Calculate and push the original stack pointer. |
| 7436 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7437 | __ push(eax); |
| 7438 | |
| 7439 | // Calculate and push the function address. |
| 7440 | __ mov(eax, Operand(eax, 0)); |
| 7441 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7442 | __ push(eax); |
| 7443 | |
| 7444 | // Call the entry hook. |
| 7445 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
| 7446 | __ call(Operand(hook_location, RelocInfo::NONE)); |
| 7447 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7448 | |
| 7449 | // Restore ecx. |
| 7450 | __ pop(ecx); |
| 7451 | __ ret(0); |
| 7452 | } |
| 7453 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7454 | #undef __ |
| 7455 | |
| 7456 | } } // namespace v8::internal |
| 7457 | |
| 7458 | #endif // V8_TARGET_ARCH_IA32 |